[PATCH] D154001: [ScalarEvolution] Analyze ranges for heap allocations
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 29 09:36:09 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22ca38da25e1: [ScalarEvolution] Analyze ranges for heap allocations (authored by aeubanks).
Changed prior to commit:
https://reviews.llvm.org/D154001?vs=535521&id=535852#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154001/new/
https://reviews.llvm.org/D154001
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/malloc.ll
llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
Index: llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
===================================================================
--- llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
+++ llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll
@@ -60,20 +60,14 @@
; CHECK-NEXT: store i32 2, ptr [[GETELEMENTPTR]], align 4
; CHECK-NEXT: [[GETELEMENTPTR1:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 2
; CHECK-NEXT: store i32 3, ptr [[GETELEMENTPTR1]], align 4
-; CHECK-NEXT: [[GETELEMENTPTR2:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 3
-; CHECK-NEXT: br label [[BB11_I:%.*]]
-; CHECK: bb11.i:
-; CHECK-NEXT: [[PHI37_I:%.*]] = phi i32 [ [[ADD_I:%.*]], [[BB11_I]] ], [ 0, [[BB:%.*]] ]
-; CHECK-NEXT: [[PHI6_I:%.*]] = phi ptr [ [[SPEC_SELECT_I:%.*]], [[BB11_I]] ], [ [[ALLOC]], [[BB]] ]
-; CHECK-NEXT: [[SPEC_SELECT_I]] = getelementptr i32, ptr [[PHI6_I]], i64 1
-; CHECK-NEXT: [[LOAD_I:%.*]] = load i32, ptr [[PHI6_I]], align 4
-; CHECK-NEXT: [[ADD_I]] = add i32 [[LOAD_I]], [[PHI37_I]]
-; CHECK-NEXT: [[ICMP4_I:%.*]] = icmp ne ptr [[SPEC_SELECT_I]], [[GETELEMENTPTR2]]
-; CHECK-NEXT: [[ICMP102_I:%.*]] = icmp ne ptr [[SPEC_SELECT_I]], null
-; CHECK-NEXT: [[ICMP10_NOT_I:%.*]] = and i1 [[ICMP102_I]], [[ICMP4_I]]
-; CHECK-NEXT: br i1 [[ICMP10_NOT_I]], label [[BB11_I]], label [[LOOP_EXIT:%.*]]
-; CHECK: loop.exit:
-; CHECK-NEXT: ret i32 [[ADD_I]]
+; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 1
+; CHECK-NEXT: [[LOAD_I:%.*]] = load i32, ptr [[ALLOC]], align 4
+; CHECK-NEXT: [[SPEC_SELECT_I_1:%.*]] = getelementptr i32, ptr [[ALLOC]], i64 2
+; CHECK-NEXT: [[LOAD_I_1:%.*]] = load i32, ptr [[SPEC_SELECT_I]], align 4
+; CHECK-NEXT: [[ADD_I_1:%.*]] = add i32 [[LOAD_I_1]], [[LOAD_I]]
+; CHECK-NEXT: [[LOAD_I_2:%.*]] = load i32, ptr [[SPEC_SELECT_I_1]], align 4
+; CHECK-NEXT: [[ADD_I_2:%.*]] = add i32 [[LOAD_I_2]], [[ADD_I_1]]
+; CHECK-NEXT: ret i32 [[ADD_I_2]]
;
bb:
%alloc = call dereferenceable_or_null(64) ptr @malloc(i64 64)
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.535852.patch
Type: text/x-patch
Size: 3803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/0d242468/attachment.bin>
More information about the llvm-commits
mailing list