[llvm] [DAG] isSplatValue - only accept binop splats if they share all the same demanded undef elements (PR #135597)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 14 06:20:37 PDT 2025


================
@@ -3002,8 +3002,12 @@ bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts,
     APInt UndefLHS, UndefRHS;
     SDValue LHS = V.getOperand(0);
     SDValue RHS = V.getOperand(1);
+    // Ensure the same demanded undef elts for both operands, otherwise we might
+    // fail to handle binop-specific undef handling.
+    // e.g. (and undef, 0) -> 0 etc.
     if (isSplatValue(LHS, DemandedElts, UndefLHS, Depth + 1) &&
-        isSplatValue(RHS, DemandedElts, UndefRHS, Depth + 1)) {
+        isSplatValue(RHS, DemandedElts, UndefRHS, Depth + 1) &&
+        (DemandedElts & UndefLHS) == (DemandedElts & UndefRHS)) {
----------------
RKSimon wrote:

Yes, I was just being over-cautious - I'll update it.

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


More information about the llvm-commits mailing list