Skip to content

Commit 26ffed0

Browse files
committed
[SCEV] Use ashr to adjust constant multipliers
1 parent 295b5f3 commit 26ffed0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7841,7 +7841,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
78417841
unsigned GCD = std::min(MulZeros, TZ);
78427842
APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD);
78437843
SmallVector<const SCEV*, 4> MulOps;
7844-
MulOps.push_back(getConstant(OpC->getAPInt().lshr(GCD)));
7844+
MulOps.push_back(getConstant(OpC->getAPInt().ashr(GCD)));
78457845
append_range(MulOps, LHSMul->operands().drop_front());
78467846
auto *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags());
78477847
ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt));

llvm/test/Analysis/ScalarEvolution/pr135531.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define i32 @pr135511(i32 %x) {
99
; CHECK-NEXT: %neg = sub nsw i32 0, %and
1010
; CHECK-NEXT: --> (-2 * (zext i13 (trunc i32 (%x /u 2) to i13) to i32))<nsw> U: [0,-1) S: [-16382,1)
1111
; CHECK-NEXT: %res = and i32 %neg, 268431360
12-
; CHECK-NEXT: --> (4096 * (zext i16 (trunc i32 ((2147483647 * (zext i13 (trunc i32 (%x /u 2) to i13) to i32))<nuw><nsw> /u 2048) to i16) to i32))<nuw><nsw> U: [0,268431361) S: [0,268431361)
12+
; CHECK-NEXT: --> (4096 * (zext i16 (trunc i32 ((-1 * (zext i13 (trunc i32 (%x /u 2) to i13) to i32))<nsw> /u 2048) to i16) to i32))<nuw><nsw> U: [0,268431361) S: [0,268431361)
1313
; CHECK-NEXT: Determining loop execution counts for: @pr135511
1414
;
1515
%and = and i32 %x, 16382

0 commit comments

Comments
 (0)