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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 11:00:59 PDT 2025


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

```suggestion
const APInt *C1;

if (!match(V1, m_APInt(C1))) {
  return nullptr;
}
```

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


More information about the llvm-commits mailing list