2019-04-17 12:52:47 +08:00
|
|
|
; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs,inline)' -S | FileCheck %s
|
|
|
|
; This test runs the inliner and the function attribute deduction. It ensures
|
|
|
|
; that when the inliner mutates the call graph it correctly updates the CGSCC
|
|
|
|
; iteration so that we can compute refined function attributes. In this way it
|
|
|
|
; is leveraging function attribute computation to observe correct call graph
|
|
|
|
; updates.
|
|
|
|
|
|
|
|
; Boring unknown external function call.
|
|
|
|
; CHECK: declare void @unknown()
|
|
|
|
declare void @unknown()
|
|
|
|
|
|
|
|
; Sanity check: this should get annotated as readnone.
|
|
|
|
; CHECK: Function Attrs: nounwind readnone
|
|
|
|
; CHECK-NEXT: declare void @readnone()
|
|
|
|
declare void @readnone() readnone nounwind
|
|
|
|
|
|
|
|
; The 'test1_' prefixed functions are designed to trigger forming a new direct
|
|
|
|
; call in the inlined body of the function. After that, we form a new SCC and
|
|
|
|
; using that can deduce precise function attrs.
|
|
|
|
|
|
|
|
; This function should no longer exist.
|
|
|
|
; CHECK-NOT: @test1_f()
|
|
|
|
define internal void @test1_f(void()* %p) {
|
|
|
|
entry:
|
|
|
|
call void %p()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test1_g()
|
|
|
|
define void @test1_g() noinline {
|
|
|
|
entry:
|
|
|
|
call void @test1_f(void()* @test1_h)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test1_h()
|
|
|
|
define void @test1_h() noinline {
|
|
|
|
entry:
|
|
|
|
call void @test1_g()
|
|
|
|
call void @readnone()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; The 'test2_' prefixed functions are designed to trigger forming a new direct
|
|
|
|
; call due to RAUW-ing the returned value of a called function into the caller.
|
|
|
|
; This too should form a new SCC which can then be reasoned about to compute
|
|
|
|
; precise function attrs.
|
|
|
|
|
|
|
|
; This function should no longer exist.
|
|
|
|
; CHECK-NOT: @test2_f()
|
|
|
|
define internal void()* @test2_f() {
|
|
|
|
entry:
|
|
|
|
ret void()* @test2_h
|
|
|
|
}
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test2_g()
|
|
|
|
define void @test2_g() noinline {
|
|
|
|
entry:
|
|
|
|
%p = call void()* @test2_f()
|
|
|
|
call void %p()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test2_h()
|
|
|
|
define void @test2_h() noinline {
|
|
|
|
entry:
|
|
|
|
call void @test2_g()
|
|
|
|
call void @readnone()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; The 'test3_' prefixed functions are designed to inline in a way that causes
|
|
|
|
; call sites to become trivially dead during the middle of inlining callsites of
|
|
|
|
; a single function to make sure that the inliner does not get confused by this
|
|
|
|
; pattern.
|
|
|
|
|
|
|
|
; CHECK-NOT: @test3_maybe_unknown(
|
|
|
|
define internal void @test3_maybe_unknown(i1 %b) {
|
|
|
|
entry:
|
|
|
|
br i1 %b, label %then, label %exit
|
|
|
|
|
|
|
|
then:
|
|
|
|
call void @unknown()
|
|
|
|
br label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-NOT: @test3_f(
|
|
|
|
define internal i1 @test3_f() {
|
|
|
|
entry:
|
|
|
|
ret i1 false
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-NOT: @test3_g(
|
|
|
|
define internal i1 @test3_g(i1 %b) {
|
|
|
|
entry:
|
|
|
|
br i1 %b, label %then1, label %if2
|
|
|
|
|
|
|
|
then1:
|
|
|
|
call void @test3_maybe_unknown(i1 true)
|
|
|
|
br label %if2
|
|
|
|
|
|
|
|
if2:
|
|
|
|
%f = call i1 @test3_f()
|
|
|
|
br i1 %f, label %then2, label %exit
|
|
|
|
|
|
|
|
then2:
|
|
|
|
call void @test3_maybe_unknown(i1 true)
|
|
|
|
br label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret i1 false
|
|
|
|
}
|
|
|
|
|
|
|
|
; FIXME: Currently the inliner doesn't successfully mark this as readnone
|
|
|
|
; because while it simplifies trivially dead CFGs when inlining callees it
|
|
|
|
; doesn't simplify the caller's trivially dead CFG and so we end with a dead
|
|
|
|
; block calling @unknown.
|
|
|
|
; CHECK-NOT: Function Attrs: readnone
|
|
|
|
; CHECK: define void @test3_h()
|
|
|
|
define void @test3_h() {
|
|
|
|
entry:
|
|
|
|
%g = call i1 @test3_g(i1 false)
|
|
|
|
br i1 %g, label %then, label %exit
|
|
|
|
|
|
|
|
then:
|
|
|
|
call void @test3_maybe_unknown(i1 true)
|
|
|
|
br label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
call void @test3_maybe_unknown(i1 false)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; The 'test4_' prefixed functions are designed to trigger forming a new direct
|
|
|
|
; call in the inlined body of the function similar to 'test1_'. However, after
|
|
|
|
; that we continue to inline another edge of the graph forcing us to do a more
|
|
|
|
; interesting call graph update for the new call edge. Eventually, we still
|
|
|
|
; form a new SCC and should use that can deduce precise function attrs.
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test4_f1()
|
|
|
|
define void @test4_f1() noinline {
|
|
|
|
entry:
|
|
|
|
call void @test4_h()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-NOT: @test4_f2
|
|
|
|
define internal void @test4_f2() {
|
|
|
|
entry:
|
|
|
|
call void @test4_f1()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-NOT: @test4_g
|
|
|
|
define internal void @test4_g(void()* %p) {
|
|
|
|
entry:
|
|
|
|
call void %p()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; This function should have had 'readnone' deduced for its SCC.
|
[funcattrs] Add the maximal set of implied attributes to definitions
Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.
Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.
The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.
I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.
Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.
Differential Revision: https://reviews.llvm.org/D100226
2021-04-17 05:03:36 +08:00
|
|
|
; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: define void @test4_h()
|
|
|
|
define void @test4_h() noinline {
|
|
|
|
entry:
|
|
|
|
call void @test4_g(void()* @test4_f2)
|
|
|
|
ret void
|
|
|
|
}
|