[llvm] [InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X, (C1 >> C2)` (PR #72625)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 01:14:22 PST 2023
================
@@ -1435,12 +1435,11 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
if (Op0->hasOneUse()) {
APInt NewMulC = MulC->lshr(ShAmtC);
// if c is divisible by (1 << ShAmtC):
- // lshr (mul nuw x, MulC), ShAmtC -> mul nuw x, (MulC >> ShAmtC)
+ // lshr (mul nuw x, MulC), ShAmtC -> mul nuw nsw x, (MulC >> ShAmtC)
if (MulC->eq(NewMulC.shl(ShAmtC))) {
auto *NewMul =
BinaryOperator::CreateNUWMul(X, ConstantInt::get(Ty, NewMulC));
- BinaryOperator *OrigMul = cast<BinaryOperator>(Op0);
- NewMul->setHasNoSignedWrap(OrigMul->hasNoSignedWrap());
+ NewMul->setHasNoSignedWrap(true);
----------------
dtcxzyw wrote:
I believe this trivial case has been handled by `simplifyLShrInst`. I'll do it later.
https://github.com/llvm/llvm-project/pull/72625
More information about the llvm-commits
mailing list