@@ -11410,13 +11410,18 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(
1141011410 // select_cc lhs, rhs, sub(rhs, lhs), sub(lhs, rhs), cc ->
1141111411 // select_cc lhs, rhs, neg(sub(lhs, rhs)), sub(lhs, rhs), cc
1141211412 // 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.
1141311415 if (TVal.getOpcode() == ISD::SUB && FVal.getOpcode() == ISD::SUB) {
1141411416 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);
1141611419 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);
1141911423 TVal = DAG.getNegative(FVal, DL, FVal.getValueType());
11424+ }
1142011425 }
1142111426
1142211427 unsigned Opcode = AArch64ISD::CSEL;
0 commit comments