@@ -11410,13 +11410,18 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(
11410
11410
// select_cc lhs, rhs, sub(rhs, lhs), sub(lhs, rhs), cc ->
11411
11411
// select_cc lhs, rhs, neg(sub(lhs, rhs)), sub(lhs, rhs), cc
11412
11412
// The second forms can be matched into subs+cneg.
11413
+ // NOTE: Drop poison generating flags from the negated operand to avoid
11414
+ // inadvertently propagating poison after the canonicalisation.
11413
11415
if (TVal.getOpcode() == ISD::SUB && FVal.getOpcode() == ISD::SUB) {
11414
11416
if (TVal.getOperand(0) == LHS && TVal.getOperand(1) == RHS &&
11415
- FVal.getOperand(0) == RHS && FVal.getOperand(1) == LHS)
11417
+ FVal.getOperand(0) == RHS && FVal.getOperand(1) == LHS) {
11418
+ TVal->dropFlags(SDNodeFlags::PoisonGeneratingFlags);
11416
11419
FVal = DAG.getNegative(TVal, DL, TVal.getValueType());
11417
- else if (TVal.getOperand(0) == RHS && TVal.getOperand(1) == LHS &&
11418
- FVal.getOperand(0) == LHS && FVal.getOperand(1) == RHS)
11420
+ } else if (TVal.getOperand(0) == RHS && TVal.getOperand(1) == LHS &&
11421
+ FVal.getOperand(0) == LHS && FVal.getOperand(1) == RHS) {
11422
+ FVal->dropFlags(SDNodeFlags::PoisonGeneratingFlags);
11419
11423
TVal = DAG.getNegative(FVal, DL, FVal.getValueType());
11424
+ }
11420
11425
}
11421
11426
11422
11427
unsigned Opcode = AArch64ISD::CSEL;
0 commit comments