Repository navigation
Fix three xarch lowering correctness/invariant issues - #130843
tannergooding merged 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
CC. @dotnet/jit-contrib, @EgorBo. 3x small bug fixes in lowering |
There was a problem hiding this comment.
Pull request overview
This PR makes three targeted correctness/invariant fixes in xarch lowering and adds three new JitBlue regression tests to cover the affected scenarios.
Changes:
- Fixes mask inversion in
LowerHWIntrinsicCmpOpby passing the mask’s base type toTryInvertMask. - Fixes
TryLowerAndOpToExtractLowestSetBitto checkGTF_SET_FLAGSon theGT_ANDroot that would be replaced. - Fixes an invariant violation in containment for
NI_X86Base_Insertby not markingop2reg-optional when it is already contained. - Adds three new JitBlue regression tests with per-test csproj configuration.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/lowerxarch.cpp | Correctness/invariant fixes in xarch lowering for mask inversion, flags-guarding, and INSERTPS containment. |
| src/tests/JIT/Regression/JitBlue/Runtime_MaskCompareAllBitsSet/Runtime_MaskCompareAllBitsSet.csproj | New JitBlue test project for mask inversion scenario. |
| src/tests/JIT/Regression/JitBlue/Runtime_MaskCompareAllBitsSet/Runtime_MaskCompareAllBitsSet.cs | New regression test covering mask comparisons vs AllBitsSet with differing element interpretations. |
| src/tests/JIT/Regression/JitBlue/Runtime_InsertpsZeroContainment/Runtime_InsertpsZeroContainment.csproj | New JitBlue test project for INSERTPS containment invariant. |
| src/tests/JIT/Regression/JitBlue/Runtime_InsertpsZeroContainment/Runtime_InsertpsZeroContainment.cs | New regression test validating INSERTPS behavior when op2 is a contained zero vector. |
| src/tests/JIT/Regression/JitBlue/Runtime_ExtractLowestSetBitFlags/Runtime_ExtractLowestSetBitFlags.csproj | New JitBlue test project for AND/NEG lowering flags-guard scenario. |
| src/tests/JIT/Regression/JitBlue/Runtime_ExtractLowestSetBitFlags/Runtime_ExtractLowestSetBitFlags.cs | New regression test exercising x & (-x) patterns feeding branches/value uses. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 2
The const-mask inversion path in TryInvertMask computes the number of valid mask bits from the base type, but LowerHWIntrinsicCmpOp was passing the node's simdBaseType instead of maskBaseType. These can legitimately differ (e.g. an op_Equality declared TYP_INT over a TYP_DOUBLE mask), which would yield the wrong bit count and spurious high bits in the inverted mask. Use maskBaseType, consistent with every other consumer in the block. Co-authored-by: Copilot App <[email protected]>
…tLowestSetBit The flags guard tested opNode (the surviving leaf operand) rather than andNode (the GT_AND root that is removed and replaced by the BLSI). AND and BLSI set the CPU flags differently, so if a downstream consumer reads the flags produced by the AND the transform is unsound. Check andNode, matching the sibling TryLowerAndOpToResetLowestSetBit, and drop the dead opNode sub-check. Co-authored-by: Copilot App <[email protected]>
c6e8e3b to
ae818a3
Compare
For NI_X86Base_Insert (FLOAT), when op2 is a zero vector it is already MakeSrcContained, but TryMakeSrcContainedOrRegOptional then ran unconditionally and additionally marked it reg-optional, violating the invariant that a node is not both contained and reg-optional. Guard the call on !op2->isContained(). Co-authored-by: Copilot App <[email protected]>
ae818a3 to
a972ceb
Compare
|
Workflow state for the Holistic Review Orchestrator. {
"version": 5,
"last_dispatched_commit": "a972cebe72e8e8547c012ec73923400a41d9d279",
"last_dispatched_base_ref": "main",
"last_dispatched_base_sha": "f2281d59e62aa6a75e53055b8f842bac108b9887",
"last_reviewed_commit": "a972cebe72e8e8547c012ec73923400a41d9d279",
"last_reviewed_base_ref": "main",
"last_reviewed_base_sha": "f2281d59e62aa6a75e53055b8f842bac108b9887",
"last_recorded_worker_run_id": "29688132271",
"review_attempt_commit": "",
"review_attempt_base_ref": "",
"review_attempt_count": 0,
"max_review_attempts": 5,
"review_history_format": "holistic-review-disclosure-v1",
"review_history": [
{
"commit": "a972cebe72e8e8547c012ec73923400a41d9d279",
"review_id": 4730810105
}
]
} |
There was a problem hiding this comment.
Holistic Review
Motivation: The PR bundles three independent x64 lowering fixes in the JIT, each addressing a distinct correctness or invariant issue in lowerxarch.cpp: (1) a wrong base type passed to TryInvertMask, (2) a dead/incorrect GTF_SET_FLAGS guard node in TryLowerAndOpToExtractLowestSetBit, and (3) an INSERTPS operand marked both contained and reg-optional. Each is a real invariant/correctness concern even if latent on current codegen paths.
Approach: Each change is a minimal, surgical edit that aligns the affected code with the established convention in its own vicinity. (1) simdBaseType -> maskBaseType matches every other consumer in the block (count at line 2892, NotMask/ShiftLeftMask/ShiftRightMask), correctly deriving the valid mask-bit count when the mask element type differs from the declared comparison base type. (2) Checking andNode->gtFlags instead of opNode->gtFlags matches the sibling TryLowerAndOpToResetLowestSetBit; the old guard tested a surviving leaf rather than the removed GT_AND whose flags semantics differ from BLSI. (3) Guarding TryMakeSrcContainedOrRegOptional on !op2->isContained() makes the op2-zero path symmetric with the op1-zero branch above and preserves the invariant that a node is not simultaneously contained and reg-optional. Each fix ships a standalone JitBlue regression test with a scalar reference oracle.
Summary: LGTM. The three fixes are correct, independently reviewable (one commit each), and consistent with surrounding conventions. The regression tests are reasonable: Runtime_130846 uses ConditionalFact(typeof(Sse41)) with a proper scalar oracle covering varied control bytes; Runtime_130845 exercises both value and flags-consumer uses; Runtime_130844 exercises mask/base-type mismatch cases and acts as a coverage guard on non-AVX512 hardware while exercising the buggy EVEX path on AVX512 CI. As the author notes, #130845 and #130846 are latent hardening changes today and #130844 is only observable on AVX512, so real behavioral coverage depends on AVX512 CI legs; this is acknowledged and acceptable. No actionable findings.
Detailed Findings
None.
Note
This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.
Generated by Holistic Review · 50.1 AIC · ⌖ 10.2 AIC · ⊞ 10K
Three independent xarch lowering fixes, each as its own commit so they can be reviewed (or split) individually. Each has a standalone JitBlue regression test named after its tracking issue.
Fix incorrect base type passed to TryInvertMask for mask inversion(test:Runtime_130844)Fixes #130844.
LowerHWIntrinsicCmpOppassed the node'ssimdBaseTypetoTryInvertMask, but the const-mask inversion path computes the number of valid mask bits from that base type (GetBitMask(simdSize / genTypeSize(base))). The mask's own base type (maskBaseType) can legitimately differ from the comparison's declared base type (e.g. anop_EqualitydeclaredTYP_INTover aTYP_DOUBLEmask), which would produce the wrong bit count and spurious high bits in the inverted mask. PassmaskBaseType, consistent with every other consumer in the block (elementcount,NotMask/ShiftLeftMask/ShiftRightMask). The other caller (BlendVariableMask) is unaffected since its base type already matches the mask.Only observable on AVX512 (EVEX mask +
KORTEST) and only in theIsCnsMsk()const-mask branch; correctness/consistency fix.Ensure the correct node is checked for flags in TryLowerAndOpToExtractLowestSetBit(test:Runtime_130845)Fixes #130845.
The
GTF_SET_FLAGSguard testedopNode(the surviving leaf operand -- a dead check) rather thanandNode, theGT_ANDroot that is removed and replaced by the BLSI.ANDandBLSIset the CPU flags differently, so if a downstream consumer reads the flags produced by the AND the transform is unsound. CheckandNode, matching the siblingTryLowerAndOpToResetLowestSetBit, and drop the deadopNodesub-check.Latent by lowering order today (the AND's
GTF_SET_FLAGSis only set later, when the consuming compare-to-zero is lowered), so this is a consistency/hardening change.Don't mark INSERTPS op2 both contained and reg-optional(test:Runtime_130846)Fixes #130846.
For
NI_X86Base_Insert(FLOAT), whenop2is a zero vector it is alreadyMakeSrcContained(the zero is fully elided via the INSERTPSzmask), butTryMakeSrcContainedOrRegOptionalthen ran unconditionally and additionally marked it reg-optional -- violating the invariant that a node is not both contained and reg-optional. Guard the call on!op2->isContained(), making the op2 path symmetric with theop1->IsVectorZero()branch just above (which contains and never retries).The reg-optional flag is inert at runtime (a contained zero
CNS_VECproduces no operand uses), so no default-build assert fires; hardening fix confirmed via temporary instrumentation.All three come with JitBlue regression tests (proper ISA guards, scalar reference oracles). On non-AVX512 hardware all three are latent, so the tests are execution/coverage guards; #130844 specifically exercises the buggy EVEX path only on AVX512 CI.
Note
This PR description and the accompanying changes were generated with the assistance of GitHub Copilot.