[llvm] [InstCombine] Fold reconstruction across select (PR #145102)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 22 22:55:02 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()))))
+ return nullptr;
+
+ Value *V2, *Trunc;
+ if (!match(ZExtSel, m_ZExt(m_OneUse(m_Select(m_Specific(Cond), m_Value(V2),
+ m_Value(Trunc))))))
+ return nullptr;
+
+ if (!match(Trunc, m_Trunc(m_Specific(X))))
+ return nullptr;
+
+ Value *ZExtTrue = Builder.CreateZExt(V2, V1->getType());
+ Value *True;
+ if (!(True = simplifyBinOp(Opcode, V1, ZExtTrue, FMF, Q)))
+ True = Builder.CreateOr(V1, ZExtTrue);
----------------
dtcxzyw wrote:
```suggestion
Value *True = simplifyBinOp(Opcode, V1, ZExtTrue, FMF, Q))
if (!True) return nullptr;
```
See my previous comment https://github.com/llvm/llvm-project/pull/145102/files#r2160769651
https://github.com/llvm/llvm-project/pull/145102
More information about the llvm-commits
mailing list