[llvm] [InstCombine] lshr (mul (X, 2^N + 1)), N -> add (X, lshr(X, N)) (PR #90295)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 20 08:32:44 PDT 2024
================
@@ -1483,6 +1494,16 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
}
}
+ // lshr (mul nsw (X, 2^N + 1)), N -> add nsw (X, lshr(X, N))
+ if (match(Op0, m_OneUse(m_NSWMul(m_Value(X), m_APInt(MulC))))) {
+ if (BitWidth > 2 && (*MulC - 1).isPowerOf2() &&
+ MulC->logBase2() == ShAmtC) {
+ return BinaryOperator::CreateNSWAdd(
+ X, Builder.CreateLShr(X, ConstantInt::get(Ty, ShAmtC), "",
+ I.isExact()));
+ }
+ }
+
----------------
goldsteinn wrote:
That wasn't exact code, just the idea of putting all the `m_Mul` and `(*MulC - 1).isPowerOf2() && MulC->logBase2() == ShAmtC` together to simplify the code.
https://github.com/llvm/llvm-project/pull/90295
More information about the llvm-commits
mailing list