[PATCH] D159160: [SCEV] Fix potentially empty set for unsigned ranges
Tejas Joshi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 21:26:10 PDT 2023
tejas created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
tejas requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The following commit enabled the analysis of ranges for heap allocations:
22ca38da25e19a7c5fcfeb3f22159aba92ec381e <https://reviews.llvm.org/rG22ca38da25e19a7c5fcfeb3f22159aba92ec381e>
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159160
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/malloc.ll
Index: llvm/test/Analysis/ScalarEvolution/malloc.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/malloc.ll
+++ llvm/test/Analysis/ScalarEvolution/malloc.ll
@@ -23,4 +23,15 @@
ret ptr %alloc
}
+define ptr @undefined_max() {
+; CHECK-LABEL: 'undefined_max'
+; CHECK-NEXT: Classifying expressions for: @undefined_max
+; CHECK-NEXT: %alloc = call nonnull ptr @malloc(i64 -1)
+; CHECK-NEXT: --> %alloc U: full-set S: full-set
+; CHECK-NEXT: Determining loop execution counts for: @undefined_max
+;
+ %alloc = call nonnull ptr @malloc(i64 -1)
+ ret ptr %alloc
+}
+
declare noalias noundef ptr @malloc(i64 noundef) allockind("alloc,uninitialized") allocsize(0)
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6843,7 +6843,7 @@
if (llvm::isKnownNonZero(V, DL))
MinVal = Align;
ConservativeResult = ConservativeResult.intersectWith(
- {MinVal, MaxVal + 1}, RangeType);
+ ConstantRange::getNonEmpty(MinVal, MaxVal + 1), RangeType);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159160.554562.patch
Type: text/x-patch
Size: 1226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230830/e90f9c9d/attachment.bin>
More information about the llvm-commits
mailing list