Skip to content

Commit df34eac

Browse files
authored
[AArch64] Drop poison flags when lowering absolute difference patterns. (llvm#152130)
As a follow-up to llvm#151177, when lowering SELECT_CC nodes of absolute difference patterns, drop poison-generating flags from the negated operand to avoid inadvertently propagating poison. As discussed in the PR above, I didn't find practical issues with the current code, but it seems safer to do this preemptively.
1 parent 0461cd3 commit df34eac

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11390,13 +11390,18 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(
1139011390
// select_cc lhs, rhs, sub(rhs, lhs), sub(lhs, rhs), cc ->
1139111391
// select_cc lhs, rhs, neg(sub(lhs, rhs)), sub(lhs, rhs), cc
1139211392
// The second forms can be matched into subs+cneg.
11393+
// NOTE: Drop poison generating flags from the negated operand to avoid
11394+
// inadvertently propagating poison after the canonicalisation.
1139311395
if (TVal.getOpcode() == ISD::SUB && FVal.getOpcode() == ISD::SUB) {
1139411396
if (TVal.getOperand(0) == LHS && TVal.getOperand(1) == RHS &&
11395-
FVal.getOperand(0) == RHS && FVal.getOperand(1) == LHS)
11397+
FVal.getOperand(0) == RHS && FVal.getOperand(1) == LHS) {
11398+
TVal->dropFlags(SDNodeFlags::PoisonGeneratingFlags);
1139611399
FVal = DAG.getNegative(TVal, DL, TVal.getValueType());
11397-
else if (TVal.getOperand(0) == RHS && TVal.getOperand(1) == LHS &&
11398-
FVal.getOperand(0) == LHS && FVal.getOperand(1) == RHS)
11400+
} else if (TVal.getOperand(0) == RHS && TVal.getOperand(1) == LHS &&
11401+
FVal.getOperand(0) == LHS && FVal.getOperand(1) == RHS) {
11402+
FVal->dropFlags(SDNodeFlags::PoisonGeneratingFlags);
1139911403
TVal = DAG.getNegative(FVal, DL, FVal.getValueType());
11404+
}
1140011405
}
1140111406

1140211407
unsigned Opcode = AArch64ISD::CSEL;

0 commit comments

Comments
 (0)