[llvm] [InstCombine] Combine or-disjoint (and->mul), (and->mul) to and->mul (PR #136013)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 13:24:33 PDT 2025
================
@@ -3560,6 +3560,72 @@ static Value *foldOrOfInversions(BinaryOperator &I,
return nullptr;
}
+struct DecomposedBitMaskMul {
+ Value *X;
+ APInt Factor;
+ APInt Mask;
+};
+
+static std::optional<DecomposedBitMaskMul> matchBitmaskMul(Value *V) {
+ Instruction *Op = dyn_cast<Instruction>(V);
+ if (!Op)
+ return std::nullopt;
+
+ Value *MulOp = nullptr;
+ const APInt *MulConst = nullptr;
+ if (match(Op, m_Mul(m_Value(MulOp), m_APInt(MulConst)))) {
+ Value *Original = nullptr;
+ const APInt *Mask = nullptr;
+ if (!MulConst->isStrictlyPositive())
+ return std::nullopt;
+
+ if (match(MulOp, m_And(m_Value(Original), m_APInt(Mask)))) {
+ if (!Mask->isStrictlyPositive())
+ return std::nullopt;
+ DecomposedBitMaskMul Ret;
+ Ret.X = Original;
+ Ret.Mask = *Mask;
+ Ret.Factor = *MulConst;
+ return Ret;
----------------
arsenm wrote:
```suggestion
return { Original, *Mask, *MulConst};
```
https://github.com/llvm/llvm-project/pull/136013
More information about the llvm-commits
mailing list