[PATCH] D154001: [ScalarEvolution] Analyze ranges for heap allocations
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 14:10:36 PDT 2023
aeubanks created this revision.
aeubanks added a reviewer: nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Followup to D153624 <https://reviews.llvm.org/D153624>. Allows for better exit count calculations for loops checking heap allocations against null.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154001
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
@@ -5,7 +5,7 @@
; CHECK-LABEL: 'f'
; CHECK-NEXT: Classifying expressions for: @f
; CHECK-NEXT: %alloc = tail call dereferenceable(64) ptr @malloc(i64 64)
-; CHECK-NEXT: --> %alloc U: full-set S: full-set
+; CHECK-NEXT: --> %alloc U: [1,-64) S: full-set
; CHECK-NEXT: Determining loop execution counts for: @f
;
%alloc = tail call dereferenceable(64) ptr @malloc(i64 64)
@@ -16,7 +16,7 @@
; CHECK-LABEL: 'f2'
; CHECK-NEXT: Classifying expressions for: @f2
; CHECK-NEXT: %alloc = tail call dereferenceable_or_null(64) ptr @malloc(i64 64)
-; CHECK-NEXT: --> %alloc U: full-set S: full-set
+; CHECK-NEXT: --> %alloc U: [0,-64) S: full-set
; CHECK-NEXT: Determining loop execution counts for: @f2
;
%alloc = tail call dereferenceable_or_null(64) ptr @malloc(i64 64)
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6816,7 +6816,8 @@
Opts.RoundToAlign = false;
Opts.NullIsUnknownSize = true;
uint64_t ObjSize;
- if ((isa<GlobalVariable>(V) || isa<AllocaInst>(V)) &&
+ if ((isa<GlobalVariable>(V) || isa<AllocaInst>(V) ||
+ isAllocationFn(V, &TLI)) &&
getObjectSize(V, ObjSize, DL, &TLI, Opts) && ObjSize > 1) {
// The highest address the object can start is ObjSize bytes before the
// end (unsigned max value). If this value is not a multiple of the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154001.535521.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230628/7cfe379d/attachment.bin>
More information about the llvm-commits
mailing list