diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2025-04-13 20:22:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 20:22:48 +0800 |
commit | bb9580a02b393683ff0b6c360df684f33c715a1f (patch) | |
tree | 7ad9a286366ba3c4f25dc7265353d51932e663ca /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 77fcdb9f26d2d9da04767894b23b71e52e5ac7ce (diff) | |
download | llvm-bb9580a02b393683ff0b6c360df684f33c715a1f.zip llvm-bb9580a02b393683ff0b6c360df684f33c715a1f.tar.gz llvm-bb9580a02b393683ff0b6c360df684f33c715a1f.tar.bz2 |
[SCEV] Use ashr to adjust constant multipliers (#135534)
SCEV converts "-2 *nsw (i32 V)" into "2148473647 *nsw (i32 V)". But we
cannot preserve the nsw flag when the constant multiplier is negative.
This patch changes lshr to ashr so that we can preserve both nsw and nuw
flags.
Alive2 proof: https://alive2.llvm.org/ce/z/LZVSEa
Closes https://github.com/llvm/llvm-project/issues/135531.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index c62ea15..d193c9e 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -7841,7 +7841,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { unsigned GCD = std::min(MulZeros, TZ); APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD); SmallVector<const SCEV*, 4> MulOps; - MulOps.push_back(getConstant(OpC->getAPInt().lshr(GCD))); + MulOps.push_back(getConstant(OpC->getAPInt().ashr(GCD))); append_range(MulOps, LHSMul->operands().drop_front()); auto *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags()); ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt)); |