Skip to content

Commit a9f083d

Browse files
tejas-amdtru
authored andcommitted
[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 #63856 Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D159160 (cherry picked from commit 0609b65)
1 parent 7a0ee8a commit a9f083d

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
@@ -6833,7 +6833,7 @@ const ConstantRange &ScalarEvolution::getRangeRef(
68336833
if (llvm::isKnownNonZero(V, DL))
68346834
MinVal = Align;
68356835
ConservativeResult = ConservativeResult.intersectWith(
6836-
{MinVal, MaxVal + 1}, RangeType);
6836+
ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType);
68376837
}
68386838
}
68396839

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)