[Attributor] Teach AANoCapture to use information in-flight more aggressively

AAReturnedValues, AAMemoryBehavior, and AANoUnwind, can provide
information that helps during the tracking or even justifies no-capture.
We now use this information and enable no-capture in some test cases
designed a long while a ago for these cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375382 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Johannes Doerfert
2019-10-21 00:48:42 +00:00
parent f5c1edb2b9
commit 463d8212b2
6 changed files with 103 additions and 21 deletions
+8 -10
View File
@@ -405,35 +405,33 @@ entry:
;
; Make sure the returned flag on %r is strong enough to justify nocapture on %b but **not** on %r.
;
; FIXME: The "returned" information is not propagated to the fullest extend causing us to miss "nocapture" on %b in the following:
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either1(i32* readonly %b, i32* readonly returned %r)
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either1(i32* nocapture readonly %b, i32* readonly returned %r)
;
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either2(i32* readonly %b, i32* readonly returned %r)
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either3(i32* readonly %b, i32* readonly returned %r)
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either2(i32* nocapture readonly %b, i32* readonly returned %r)
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either3(i32* nocapture readonly %b, i32* readonly returned %r)
;
; FIXME: The "nounwind" information is not derived to the fullest extend causing us to miss "nocapture" on %b in the following:
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either4(i32* readonly %b, i32* readonly returned %r)
define i32* @not_captured_by_readonly_call_not_returned_either1(i32* %b, i32* returned %r) #0 {
; CHECK: define i32* @not_captured_by_readonly_call_not_returned_either4(i32* nocapture readonly %b, i32* readonly returned %r)
define i32* @not_captured_by_readonly_call_not_returned_either1(i32* %b, i32* returned %r) {
entry:
%call = call i32* @readonly_unknown(i32* %b, i32* %r) nounwind
ret i32* %call
}
declare i32* @readonly_unknown_r1a(i32*, i32* returned) readonly
define i32* @not_captured_by_readonly_call_not_returned_either2(i32* %b, i32* %r) #0 {
define i32* @not_captured_by_readonly_call_not_returned_either2(i32* %b, i32* %r) {
entry:
%call = call i32* @readonly_unknown_r1a(i32* %b, i32* %r) nounwind
ret i32* %call
}
declare i32* @readonly_unknown_r1b(i32*, i32* returned) readonly nounwind
define i32* @not_captured_by_readonly_call_not_returned_either3(i32* %b, i32* %r) #0 {
define i32* @not_captured_by_readonly_call_not_returned_either3(i32* %b, i32* %r) {
entry:
%call = call i32* @readonly_unknown_r1b(i32* %b, i32* %r)
ret i32* %call
}
define i32* @not_captured_by_readonly_call_not_returned_either4(i32* %b, i32* %r) #0 {
define i32* @not_captured_by_readonly_call_not_returned_either4(i32* %b, i32* %r) nounwind {
entry:
%call = call i32* @readonly_unknown_r1a(i32* %b, i32* %r)
ret i32* %call
@@ -1,5 +1,5 @@
; RUN: opt -functionattrs -S < %s | FileCheck %s --check-prefix=FNATTR
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=7 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -functionattrs -S < %s | FileCheck %s --check-prefix=BOTH
;
; Test cases specifically designed for the "returned" argument attribute.
@@ -39,6 +39,20 @@ l1:
ret i1 1 ; escaping value not caught by def-use chaining.
}
; c4b is c4 but without the escaping part
; FNATTR: define i1 @c4b(i32* %q, i32 %bitno)
; ATTRIBUTOR: define i1 @c4b(i32* nocapture readnone %q, i32 %bitno)
define i1 @c4b(i32* %q, i32 %bitno) {
%tmp = ptrtoint i32* %q to i32
%tmp2 = lshr i32 %tmp, %bitno
%bit = trunc i32 %tmp2 to i1
br i1 %bit, label %l1, label %l0
l0:
ret i1 0 ; not escaping!
l1:
ret i1 0 ; not escaping!
}
@lookup_table = global [2 x i1] [ i1 0, i1 1 ]
; FNATTR: define i1 @c5(i32* %q, i32 %bitno)
@@ -331,5 +345,20 @@ entry:
ret void
}
declare i8* @unknownpi8pi8(i8*,i8* returned)
define i8* @test_returned1(i8* %A, i8* returned %B) nounwind readonly {
; ATTRIBUTOR: define i8* @test_returned1(i8* nocapture readonly %A, i8* readonly returned %B)
entry:
%p = call i8* @unknownpi8pi8(i8* %A, i8* %B)
ret i8* %p
}
define i8* @test_returned2(i8* %A, i8* %B) {
; ATTRIBUTOR: define i8* @test_returned2(i8* nocapture readonly %A, i8* readonly returned %B)
entry:
%p = call i8* @unknownpi8pi8(i8* %A, i8* %B) nounwind readonly
ret i8* %p
}
declare i8* @llvm.launder.invariant.group.p0i8(i8*)
declare i8* @llvm.strip.invariant.group.p0i8(i8*)
+1 -1
View File
@@ -220,7 +220,7 @@ bb:
define dso_local noalias i32* @f3(i32* %arg) {
; FIXME: missing nonnull. It should be nonnull @f3(i32* nonnull readonly %arg)
; ATTRIBUTOR: define dso_local noalias i32* @f3(i32* readonly %arg)
; ATTRIBUTOR: define dso_local noalias i32* @f3(i32* nocapture readonly %arg)
bb:
; FIXME: missing nonnull. It should be @f1(i32* nonnull readonly %arg)
; ATTRIBUTOR: %tmp = call i32* @f1(i32* readonly %arg)
@@ -1,4 +1,4 @@
; RUN: opt -functionattrs -enable-nonnull-arg-prop -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=7 -S < %s | FileCheck %s
; RUN: opt -functionattrs -enable-nonnull-arg-prop -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=8 -S < %s | FileCheck %s
;
; This is an evolved example to stress test SCC parameter attribute propagation.
; The SCC in this test is made up of the following six function, three of which