[llvm] [SelectionDAG] Handle more opcodes in isGuaranteedNotToBeUndefOrPoison (PR #147019)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 5 08:16:32 PDT 2025


================
@@ -5480,6 +5557,52 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
     return true;
   }
 
+  case ISD::SHL:
+  case ISD::SRL:
+  case ISD::SRA:
+    // Shift amount operand is checked by canCreateUndefOrPoison. So it is
+    // enough to check operand 0 if Op can't create undef/poison.
+    return !canCreateUndefOrPoison(Op, DemandedElts, PoisonOnly,
+                                   /*ConsiderFlags*/ true, Depth) &&
+           isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedElts,
+                                            PoisonOnly, Depth + 1);
+
+  case ISD::BSWAP:
----------------
bjope wrote:

(I've been out of office some days so memory is a bit vague...)

I think I added most of these just by trying to find fairly common opcodes (at least pretty common from my perspective) that have "elementwise operands".

Unfortunately this patch does not include any lit tests that is impacted by this extra DemandedElts propagation. The motivating case was something I think I saw when working on the other patches with "DoNotPoisionEltMask" for SimplifyDemanded functions.

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


More information about the llvm-commits mailing list