[llvm] [SelectionDAG] Preserver poison for abs INT_MIN lowering (PR #183851)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 13 17:49:08 PDT 2026


================
@@ -6924,7 +6924,12 @@ static SDValue foldAndOrOfSETCC(SDNode *LogicOp, SelectionDAG &DAG) {
       //    -> (icmp eq Abs(A), C)
       // (icmp ne A, C) & (icmp ne A, -C)
       //    -> (icmp ne Abs(A), C)
-      SDValue AbsOp = DAG.getNode(ISD::ABS, DL, OpVT, LHS0);
+      // Use ABS_MIN_POISON if that node already exists, otherwise ABS.
+      unsigned AbsOpc =
+          DAG.doesNodeExist(ISD::ABS_MIN_POISON, DAG.getVTList(OpVT), {LHS0})
----------------
topperc wrote:

> then the program has already asserted that x is never INT_MIN.

It's not an assertion. x an be INT_MIN so long as the poison the ABS_MIN_POISON doesn't propagate to something that make poison into undefined behavior. The poison could be blocked by a select for example.

If we introduce a new use of the ABS_MIN_POISON, we don't know that the poison won't propagate on the new path that is created.

https://github.com/llvm/llvm-project/pull/183851


More information about the llvm-commits mailing list