[llvm] [InstCombine] Simplify fractions when there is no overflow (PR #92949)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 16:28:58 PDT 2024
================
@@ -1273,13 +1314,30 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {
}
// (X << Z) / (X * Y) -> (1 << Z) / Y
- // TODO: Handle sdiv.
if (!IsSigned && Op1->hasOneUse() &&
match(Op0, m_NUWShl(m_Value(X), m_Value(Z))) &&
match(Op1, m_c_Mul(m_Specific(X), m_Value(Y))))
if (cast<OverflowingBinaryOperator>(Op1)->hasNoUnsignedWrap()) {
Instruction *NewDiv = BinaryOperator::CreateUDiv(
- Builder.CreateShl(ConstantInt::get(Ty, 1), Z, "", /*NUW*/ true), Y);
+ Builder.CreateShl(
+ ConstantInt::get(Ty, 1), Z, "", /*NUW*/ true,
+ cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap()),
----------------
topperc wrote:
Changing the flags on an existing transform should be its own patch.
https://github.com/llvm/llvm-project/pull/92949
More information about the llvm-commits
mailing list