Skip to content

Commit dac2d40

Browse files
committed
[Attributor] Make liveness "edge-based"
Summary: If control is transferred to a successor is the key question when it comes to liveness. The new implementation puts that question in the focus and thereby providing a clean way to assume certain CFG edges are dead or instructions will not transfer control. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69605
1 parent 9bbf2a1 commit dac2d40

File tree

10 files changed

+280
-145
lines changed

10 files changed

+280
-145
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 186 additions & 126 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/FunctionAttrs/align.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
2+
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=7 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
33

44
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
55

llvm/test/Transforms/FunctionAttrs/arg_nocapture.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -functionattrs -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=10 -S < %s | FileCheck %s
1+
; RUN: opt -functionattrs -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 -S < %s | FileCheck %s
22
;
33
; Test cases specifically designed for the "no-capture" argument attribute.
44
; We use FIXME's to indicate problems and missing attributes.

llvm/test/Transforms/FunctionAttrs/fn_noreturn.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 -S < %s | FileCheck %s
1+
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 -S < %s | FileCheck %s
22
;
33
; Test cases specifically designed for the "no-return" function attribute.
44
; We use FIXME's to indicate problems and missing attributes.

llvm/test/Transforms/FunctionAttrs/internal-noalias.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
1+
; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
22

33
define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
44
entry:

llvm/test/Transforms/FunctionAttrs/liveness.ll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=5 -S < %s | FileCheck %s
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 -S < %s | FileCheck %s
23

34
declare void @no_return_call() nofree noreturn nounwind readnone
45

@@ -687,19 +688,19 @@ define void @live_with_dead_entry_lp() personality i8* bitcast (i32 (...)* @__gx
687688
; CHECK: define void @live_with_dead_entry_lp(
688689
; CHECK-NEXT: entry:
689690
; CHECK-NEXT: invoke void @blowup()
690-
; CHECK-NEXT: to label %live_with_dead_entry.dead unwind label %lp1
691+
; CHECK-NEXT: to label %live_with_dead_entry.dead1 unwind label %lp1
691692
; CHECK: lp1: ; preds = %entry
692693
; CHECK-NEXT: %lp = landingpad { i8*, i32 }
693694
; CHECK-NEXT: catch i8* null
694695
; CHECK-NEXT: invoke void @blowup()
695-
; CHECK-NEXT: to label %live_with_dead_entry.dead1 unwind label %lp2
696+
; CHECK-NEXT: to label %live_with_dead_entry.dead unwind label %lp2
696697
; CHECK: lp2: ; preds = %lp1
697698
; CHECK-NEXT: %0 = landingpad { i8*, i32 }
698699
; CHECK-NEXT: catch i8* null
699700
; CHECK-NEXT: br label %live_with_dead_entry
700-
; CHECK: live_with_dead_entry.dead: ; preds = %entry
701+
; CHECK: live_with_dead_entry.dead:
701702
; CHECK-NEXT: unreachable
702-
; CHECK: live_with_dead_entry.dead1: ; preds = %lp1
703+
; CHECK: live_with_dead_entry.dead1:
703704
; CHECK-NEXT: unreachable
704705
; CHECK: live_with_dead_entry: ; preds = %lp2
705706
; CHECK-NEXT: ret void

llvm/test/Transforms/FunctionAttrs/nonnull.ll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -S -functionattrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR
3-
; RUN: opt -S -passes=function-attrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR
4-
; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=8 -S < %s | FileCheck %s --check-prefixes=BOTH,ATTRIBUTOR
2+
; RUN: opt -S -functionattrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR,OLD
3+
; RUN: opt -S -passes=function-attrs -enable-nonnull-arg-prop %s | FileCheck %s --check-prefixes=BOTH,FNATTR,OLD
4+
; RUN: opt -attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=7 -S < %s | FileCheck %s --check-prefixes=BOTH,OLD,ATTRIBUTOR,ATTRIBUTOR_OPM
5+
; RUN: opt -passes=attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=7 -S < %s | FileCheck %s --check-prefixes=BOTH,ATTRIBUTOR,ATTRIBUTOR_NPM
56

67
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
78

@@ -195,16 +196,17 @@ bb4: ; preds = %bb1
195196
%tmp5 = getelementptr inbounds i32, i32* %arg, i64 1
196197
; ATTRIBUTOR: %tmp5b = tail call i32* @f3(i32* nonnull %tmp5)
197198
%tmp5b = tail call i32* @f3(i32* %tmp5)
199+
%tmp5c = getelementptr inbounds i32, i32* %tmp5b, i64 -1
198200
br label %bb9
199201

200202
bb6: ; preds = %bb1
201203
; FIXME: missing nonnull. It should be @f2(i32* nonnull %arg)
202-
; ATTRIBUTOR: %tmp7 = tail call nonnull i32* @f2(i32* readonly %arg)
204+
; ATTRIBUTOR: %tmp7 = tail call nonnull i32* @f2(i32* %arg)
203205
%tmp7 = tail call i32* @f2(i32* %arg)
204206
ret i32* %tmp7
205207

206208
bb9: ; preds = %bb4, %bb
207-
%tmp10 = phi i32* [ %tmp5, %bb4 ], [ inttoptr (i64 4 to i32*), %bb ]
209+
%tmp10 = phi i32* [ %tmp5c, %bb4 ], [ inttoptr (i64 4 to i32*), %bb ]
208210
ret i32* %tmp10
209211
}
210212

@@ -214,7 +216,7 @@ define internal i32* @f2(i32* %arg) {
214216
bb:
215217

216218
; FIXME: missing nonnull. It should be @f1(i32* nonnull readonly %arg)
217-
; ATTRIBUTOR: %tmp = tail call nonnull i32* @f1(i32* readonly %arg)
219+
; ATTRIBUTOR: %tmp = tail call nonnull i32* @f1(i32* %arg)
218220
%tmp = tail call i32* @f1(i32* %arg)
219221
ret i32* %tmp
220222
}
@@ -224,7 +226,7 @@ define dso_local noalias i32* @f3(i32* %arg) {
224226
; ATTRIBUTOR: define dso_local noalias nonnull i32* @f3(i32* readonly %arg)
225227
bb:
226228
; FIXME: missing nonnull. It should be @f1(i32* nonnull readonly %arg)
227-
; ATTRIBUTOR: %tmp = call nonnull i32* @f1(i32* readonly %arg)
229+
; ATTRIBUTOR: %tmp = call nonnull i32* @f1(i32* %arg)
228230
%tmp = call i32* @f1(i32* %arg)
229231
ret i32* %tmp
230232
}
@@ -578,7 +580,6 @@ define void @make_live(i32* nonnull dereferenceable(8) %a) {
578580
ret void
579581
}
580582

581-
582583
;int f(int *u, int n){
583584
; for(int i = 0;i<n;i++){
584585
; h(u);

llvm/test/Transforms/FunctionAttrs/noreturn_async.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 -S < %s | FileCheck %s
1+
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 -S < %s | FileCheck %s
22
;
33
; This file is the same as noreturn_sync.ll but with a personality which
44
; indicates that the exception handler *can* catch asynchronous exceptions. As

llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 -S < %s | FileCheck %s
1+
; RUN: opt -functionattrs -attributor -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 -S < %s | FileCheck %s
22
;
33
; This file is the same as noreturn_async.ll but with a personality which
44
; indicates that the exception handler *cannot* catch asynchronous exceptions.

llvm/test/Transforms/FunctionAttrs/value-simplify.ll

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
12
; RUN: opt -attributor --attributor-disable=false -S < %s | FileCheck %s
23
; TODO: Add max-iteration check
34
; ModuleID = 'value-simplify.ll'
@@ -119,3 +120,75 @@ end:
119120
ret void
120121

121122
}
123+
124+
define i32 @ipccp1(i32 %a) {
125+
; CHECK-LABEL: define {{[^@]+}}@ipccp1
126+
; CHECK-SAME: (i32 returned [[A:%.*]]) #0
127+
; CHECK-NEXT: br i1 true, label [[T:%.*]], label [[F:%.*]]
128+
; CHECK: t:
129+
; CHECK-NEXT: ret i32 [[A:%.*]]
130+
; CHECK: f:
131+
; CHECK-NEXT: unreachable
132+
;
133+
br i1 true, label %t, label %f
134+
t:
135+
ret i32 %a
136+
f:
137+
%r = call i32 @ipccp1(i32 5)
138+
ret i32 %r
139+
}
140+
141+
define internal i1 @ipccp2i(i1 %a) {
142+
; CHECK-LABEL: define {{[^@]+}}@ipccp2i
143+
; CHECK-SAME: (i1 returned [[A:%.*]]) #0
144+
; CHECK-NEXT: br i1 true, label [[T:%.*]], label [[F:%.*]]
145+
; CHECK: t:
146+
; CHECK-NEXT: ret i1 true
147+
; CHECK: f:
148+
; CHECK-NEXT: unreachable
149+
;
150+
br i1 %a, label %t, label %f
151+
t:
152+
ret i1 %a
153+
f:
154+
%r = call i1 @ipccp2i(i1 false)
155+
ret i1 %r
156+
}
157+
158+
define i1 @ipccp2() {
159+
; CHECK-LABEL: define {{[^@]+}}@ipccp2() #1
160+
; CHECK-NEXT: [[R:%.*]] = call i1 @ipccp2i(i1 true) #0
161+
; CHECK-NEXT: ret i1 [[R]]
162+
;
163+
%r = call i1 @ipccp2i(i1 true)
164+
ret i1 %r
165+
}
166+
167+
define internal i32 @ipccp3i(i32 %a) {
168+
; CHECK-LABEL: define {{[^@]+}}@ipccp3i
169+
; CHECK-SAME: (i32 [[A:%.*]]) #1
170+
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A:%.*]], 7
171+
; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
172+
; CHECK: t:
173+
; CHECK-NEXT: ret i32 [[A]]
174+
; CHECK: f:
175+
; CHECK-NEXT: [[R:%.*]] = call i32 @ipccp3i(i32 5) #1
176+
; CHECK-NEXT: ret i32 [[R]]
177+
;
178+
%c = icmp eq i32 %a, 7
179+
br i1 %c, label %t, label %f
180+
t:
181+
ret i32 %a
182+
f:
183+
%r = call i32 @ipccp3i(i32 5)
184+
ret i32 %r
185+
}
186+
187+
define i32 @ipccp3() {
188+
; CHECK-LABEL: define {{[^@]+}}@ipccp3() #1
189+
; CHECK-NEXT: [[R:%.*]] = call i32 @ipccp3i(i32 7) #1
190+
; CHECK-NEXT: ret i32 [[R]]
191+
;
192+
%r = call i32 @ipccp3i(i32 7)
193+
ret i32 %r
194+
}

0 commit comments

Comments
 (0)