[llvm] [InstCombine] Fold reconstruction across select (PR #145102)

Macsen Casaus via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 05:11:52 PDT 2025


================
@@ -1349,6 +1349,40 @@ Value *InstCombinerImpl::SimplifySelectsFeedingBinaryOp(BinaryOperator &I,
     return nullptr;
   };
 
+  // Special case for reconstructing across a select:
+  // (Cond ? V1 : (X & Mask)) op
+  // zext (Cond ? V2 : trunc X)
+  // -> (Cond ? (V1 op zext V2) : ((X & Mask) op zext trunc X))
+  auto foldReconstruction = [&](Value *V1, Value *Masked,
+                                Value *ZExtSel) -> Value * {
+    if (Opcode != Instruction::Or)
+      return nullptr;
+
+    Value *X;
+    if (!match(Masked, m_OneUse(m_And(m_Value(X), m_Constant()))))
----------------
macsencasaus wrote:

I thought of this, but it would fail to simplify a case like
https://github.com/llvm/llvm-project/blob/6f0a946cec035c7613e69fc79e2b6dcd98d0470d/llvm/test/Transforms/InstCombine/select-reconstruction.ll#L40-L57
I can do it anyway if you believe this case is not relevant.

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


More information about the llvm-commits mailing list