Skip to content

Commit 2a6d415

Browse files
committed
[SelectionDAG] Fix AArch64 machine verifier bug when expanding LOOP_DEPENDENCE_MASK
We did not ensure new opcodes like mi/pl were filtered out when swapping, and TargetConstant nodes don't match TableGen ImmLeaf patterns during instruction selection. When this zero constant flows into the AArch64 CCMP formation code, the machine verifier hit an assertion in expensive checks.
1 parent a4e7d15 commit 2a6d415

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ SDValue VectorLegalizer::ExpandLOOP_DEPENDENCE_MASK(SDNode *N) {
18291829
// If the difference is positive then some elements may alias
18301830
EVT CmpVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
18311831
Diff.getValueType());
1832-
SDValue Zero = DAG.getTargetConstant(0, DL, PtrVT);
1832+
SDValue Zero = DAG.getConstant(0, DL, PtrVT);
18331833
SDValue Cmp = DAG.getSetCC(DL, CmpVT, Diff, Zero,
18341834
IsReadAfterWrite ? ISD::SETEQ : ISD::SETLE);
18351835

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_LOOP_DEPENDENCE_MASK(SDNode *N) {
413413
SDValue Diff = DAG.getNode(ISD::SUB, DL, PtrVT, SinkValue, SourceValue);
414414
EVT CmpVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
415415
Diff.getValueType());
416-
SDValue Zero = DAG.getTargetConstant(0, DL, PtrVT);
416+
SDValue Zero = DAG.getConstant(0, DL, PtrVT);
417417
return DAG.getNode(ISD::OR, DL, CmpVT,
418418
DAG.getSetCC(DL, CmpVT, Diff, EltSize, ISD::SETGE),
419419
DAG.getSetCC(DL, CmpVT, Diff, Zero, ISD::SETEQ));

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26013,9 +26013,12 @@ static SDValue reassociateCSELOperandsForCSE(SDNode *N, SelectionDAG &DAG) {
2601326013
// Try again with the operands of the SUBS instruction and the condition
2601426014
// swapped. Due to canonicalization, this only helps for non-constant
2601526015
// operands of the SUBS instruction.
26016-
std::swap(CmpOpToMatch, CmpOpOther);
26017-
if (SDValue R = Fold(getSwappedCondition(CC), CmpOpToMatch, CmpOpToMatch))
26018-
return R;
26016+
auto NewCC = getSwappedCondition(CC);
26017+
if (NewCC != AArch64CC::AL) {
26018+
std::swap(CmpOpToMatch, CmpOpOther);
26019+
if (SDValue R = Fold(NewCC, CmpOpToMatch, CmpOpToMatch))
26020+
return R;
26021+
}
2601926022
return SDValue();
2602026023
}
2602126024

0 commit comments

Comments
 (0)