Skip to content

Commit 0ddf479

Browse files
tejas-amdAndrés Villegas
authored and
Andrés Villegas
committed
[SCEV] Fix potentially empty set for unsigned ranges
The following commit enabled the analysis of ranges for heap allocations: 22ca38d The range turns out to be empty in cases such as the one in test (which is [1,1)), leading to an assertion failure. This patch fixes for the same case. Fixes llvm#63856 Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D159160
1 parent 2b5d277 commit 0ddf479

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6843,7 +6843,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
68436843
if (llvm::isKnownNonZero(V, DL))
68446844
MinVal = Align;
68456845
ConservativeResult = ConservativeResult.intersectWith(
6846-
{MinVal, MaxVal + 1}, RangeType);
6846+
ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType);
68476847
}
68486848
}
68496849

llvm/test/Analysis/ScalarEvolution/malloc.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ define ptr @f2() {
2323
ret ptr %alloc
2424
}
2525

26+
define ptr @undefined_max() {
27+
; CHECK-LABEL: 'undefined_max'
28+
; CHECK-NEXT: Classifying expressions for: @undefined_max
29+
; CHECK-NEXT: %alloc = call nonnull ptr @malloc(i64 -1)
30+
; CHECK-NEXT: --> %alloc U: full-set S: full-set
31+
; CHECK-NEXT: Determining loop execution counts for: @undefined_max
32+
;
33+
%alloc = call nonnull ptr @malloc(i64 -1)
34+
ret ptr %alloc
35+
}
36+
2637
declare noalias noundef ptr @malloc(i64 noundef) allockind("alloc,uninitialized") allocsize(0)

0 commit comments

Comments
 (0)