Skip to content

Commit 3736e1d

Browse files
committed
[SCEV] Ensure shift amount is in range before calling getZExtValue()
Fixes #76234
1 parent efeb546 commit 3736e1d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7914,9 +7914,10 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
79147914
// expression. We already checked that ShlAmt < BitWidth, so
79157915
// the multiplier, 1 << (ShlAmt - AShrAmt), fits into TruncTy as
79167916
// ShlAmt - AShrAmt < Amt.
7917-
uint64_t ShlAmt = ShlAmtCI->getZExtValue();
7918-
if (ShlAmtCI->getValue().ult(BitWidth) && ShlAmt >= AShrAmt) {
7919-
APInt Mul = APInt::getOneBitSet(BitWidth - AShrAmt, ShlAmt - AShrAmt);
7917+
const APInt &ShlAmt = ShlAmtCI->getValue();
7918+
if (ShlAmt.ult(BitWidth) && ShlAmt.uge(AShrAmt)) {
7919+
APInt Mul = APInt::getOneBitSet(BitWidth - AShrAmt,
7920+
ShlAmtCI->getZExtValue() - AShrAmt);
79207921
const SCEV *CompositeExpr =
79217922
getMulExpr(AddTruncateExpr, getConstant(Mul));
79227923
if (L->getOpcode() != Instruction::Shl)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3+
4+
; Reduced from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65278
5+
define i32 @PR76234() {
6+
; CHECK-LABEL: 'PR76234'
7+
; CHECK-NEXT: Classifying expressions for: @PR76234
8+
; CHECK-NEXT: %B9 = shl i896 0, -264147265567832623176169892458258303259423663018060761063980354513336951278362429737208627943828593947337197496628564339441173779751342768625269489231469788454193341999502542084365758838213220526512116454105594202074014146375780869419198449383518238244769290448868999168
9+
; CHECK-NEXT: --> %B9 U: [0,1) S: [0,1)
10+
; CHECK-NEXT: %B39 = ashr i896 %B9, 1
11+
; CHECK-NEXT: --> %B39 U: [0,1) S: [0,1) Exits: <<Unknown>> LoopDispositions: { %1: Variant }
12+
; CHECK-NEXT: Determining loop execution counts for: @PR76234
13+
; CHECK-NEXT: Loop %1: <multiple exits> Unpredictable backedge-taken count.
14+
; CHECK-NEXT: Loop %1: Unpredictable constant max backedge-taken count.
15+
; CHECK-NEXT: Loop %1: Unpredictable symbolic max backedge-taken count.
16+
; CHECK-NEXT: Loop %1: Unpredictable predicated backedge-taken count.
17+
;
18+
%B9 = shl i896 0, -264147265567832623176169892458258303259423663018060761063980354513336951278362429737208627943828593947337197496628564339441173779751342768625269489231469788454193341999502542084365758838213220526512116454105594202074014146375780869419198449383518238244769290448868999168
19+
br label %1
20+
1:
21+
%B39 = ashr i896 %B9, 1
22+
br label %1
23+
}

0 commit comments

Comments
 (0)