2021-04-04 00:44:28 +08:00
|
|
|
; RUN: opt -enable-new-pm=1 -function-attrs --disable-nofree-inference=false -S < %s | FileCheck %s --check-prefix=FNATTR
|
2019-07-13 01:38:51 +08:00
|
|
|
|
2019-07-13 00:29:14 +08:00
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
|
|
|
|
; Test cases specifically designed for the "nofree" function attribute.
|
|
|
|
; We use FIXME's to indicate problems and missing attributes.
|
|
|
|
|
|
|
|
; Free functions
|
|
|
|
declare void @free(i8* nocapture) local_unnamed_addr #1
|
|
|
|
declare noalias i8* @realloc(i8* nocapture, i64) local_unnamed_addr #0
|
|
|
|
declare void @_ZdaPv(i8*) local_unnamed_addr #2
|
|
|
|
|
|
|
|
|
|
|
|
; TEST 1 (positive case)
|
[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
|
|
|
; FNATTR: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR-NEXT: define void @only_return()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @only_return() #0 {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; TEST 2 (negative case)
|
2019-07-13 00:29:14 +08:00
|
|
|
; Only free
|
|
|
|
; void only_free(char* p) {
|
|
|
|
; free(p);
|
|
|
|
; }
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTR-NEXT: define void @only_free(i8* nocapture %0) local_unnamed_addr
|
|
|
|
define void @only_free(i8* nocapture %0) local_unnamed_addr #0 {
|
2019-07-13 00:29:14 +08:00
|
|
|
tail call void @free(i8* %0) #1
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; TEST 3 (negative case)
|
2019-07-13 00:29:14 +08:00
|
|
|
; Free occurs in same scc.
|
|
|
|
; void free_in_scc1(char*p){
|
|
|
|
; free_in_scc2(p);
|
|
|
|
; }
|
|
|
|
; void free_in_scc2(char*p){
|
|
|
|
; free_in_scc1(p);
|
|
|
|
; free(p);
|
|
|
|
; }
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTR-NEXT: define void @free_in_scc1(i8* nocapture %0) local_unnamed_addr
|
|
|
|
define void @free_in_scc1(i8* nocapture %0) local_unnamed_addr #0 {
|
2019-07-13 00:29:14 +08:00
|
|
|
tail call void @free_in_scc2(i8* %0) #1
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTR-NEXT: define void @free_in_scc2(i8* nocapture %0) local_unnamed_addr
|
|
|
|
define void @free_in_scc2(i8* nocapture %0) local_unnamed_addr #0 {
|
2019-08-06 07:22:05 +08:00
|
|
|
%cmp = icmp eq i8* %0, null
|
|
|
|
br i1 %cmp, label %rec, label %call
|
|
|
|
call:
|
2019-07-13 00:29:14 +08:00
|
|
|
tail call void @free(i8* %0) #1
|
2019-08-06 07:22:05 +08:00
|
|
|
br label %end
|
|
|
|
rec:
|
|
|
|
tail call void @free_in_scc1(i8* %0)
|
|
|
|
br label %end
|
|
|
|
end:
|
2019-07-13 00:29:14 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; TEST 4 (positive case)
|
|
|
|
; Free doesn't occur.
|
|
|
|
; void mutual_recursion1(){
|
|
|
|
; mutual_recursion2();
|
|
|
|
; }
|
|
|
|
; void mutual_recursion2(){
|
|
|
|
; mutual_recursion1();
|
|
|
|
; }
|
|
|
|
|
|
|
|
|
[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
|
|
|
; FNATTR: Function Attrs: nofree noinline nosync nounwind readnone uwtable
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR-NEXT: define void @mutual_recursion1()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @mutual_recursion1() #0 {
|
|
|
|
call void @mutual_recursion2()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
; FNATTR: Function Attrs: nofree noinline nosync nounwind readnone uwtable
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR-NEXT: define void @mutual_recursion2()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @mutual_recursion2() #0 {
|
|
|
|
call void @mutual_recursion1()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; TEST 5
|
2019-07-13 01:38:51 +08:00
|
|
|
; C++ delete operation (negative case)
|
2019-07-13 00:29:14 +08:00
|
|
|
; void delete_op (char p[]){
|
|
|
|
; delete [] p;
|
|
|
|
; }
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTR-NEXT: define void @_Z9delete_opPc(i8* %0) local_unnamed_addr
|
|
|
|
define void @_Z9delete_opPc(i8* %0) local_unnamed_addr #0 {
|
2019-07-13 00:29:14 +08:00
|
|
|
%2 = icmp eq i8* %0, null
|
|
|
|
br i1 %2, label %4, label %3
|
|
|
|
|
|
|
|
; <label>:3: ; preds = %1
|
|
|
|
tail call void @_ZdaPv(i8* nonnull %0) #2
|
|
|
|
br label %4
|
|
|
|
|
|
|
|
; <label>:4: ; preds = %3, %1
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; TEST 6 (negative case)
|
|
|
|
; Call realloc
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTR-NEXT: define noalias i8* @call_realloc(i8* nocapture %0, i64 %1) local_unnamed_addr
|
|
|
|
define noalias i8* @call_realloc(i8* nocapture %0, i64 %1) local_unnamed_addr #0 {
|
2019-07-13 00:29:14 +08:00
|
|
|
%ret = tail call i8* @realloc(i8* %0, i64 %1) #2
|
|
|
|
ret i8* %ret
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; TEST 7 (positive case)
|
|
|
|
; Call function declaration with "nofree"
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
|
|
|
|
; FNATTR: Function Attrs: nofree noinline nounwind readnone uwtable
|
|
|
|
; FNATTR-NEXT: declare void @nofree_function()
|
2019-07-13 00:29:14 +08:00
|
|
|
declare void @nofree_function() nofree readnone #0
|
|
|
|
|
[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
|
|
|
; FNATTR: Function Attrs: nofree noinline nosync nounwind readnone uwtable
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR-NEXT: define void @call_nofree_function()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @call_nofree_function() #0 {
|
|
|
|
tail call void @nofree_function()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; TEST 8 (negative case)
|
2019-07-13 00:29:14 +08:00
|
|
|
; Call function declaration without "nofree"
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
|
2019-07-13 00:29:14 +08:00
|
|
|
declare void @maybe_free() #0
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
|
|
|
; FNATTR: define void @call_maybe_free()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @call_maybe_free() #0 {
|
|
|
|
tail call void @maybe_free()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; TEST 9 (negative case)
|
2019-07-13 00:29:14 +08:00
|
|
|
; Call both of above functions
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; FNATTR: Function Attrs: noinline nounwind uwtable
|
|
|
|
; FNATTR-NEXT: define void @call_both()
|
2019-07-13 00:29:14 +08:00
|
|
|
define void @call_both() #0 {
|
|
|
|
tail call void @maybe_free()
|
|
|
|
tail call void @nofree_function()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-13 01:38:51 +08:00
|
|
|
; TEST 10 (positive case)
|
|
|
|
; Call intrinsic function
|
[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
|
|
|
; FNATTRS: Function Attrs: nofree noinline nosync readnone speculatable
|
2019-08-03 22:28:34 +08:00
|
|
|
; FNATTRS-NEXT: declare float @llvm.floor.f32(float %0)
|
2019-07-13 01:38:51 +08:00
|
|
|
declare float @llvm.floor.f32(float)
|
|
|
|
|
|
|
|
; FNATTRS: Function Attrs: noinline nounwind uwtable
|
|
|
|
; FNATTRS-NEXT: define void @call_floor(float %a)
|
|
|
|
; FIXME: missing nofree
|
|
|
|
|
|
|
|
define void @call_floor(float %a) #0 {
|
|
|
|
tail call float @llvm.floor.f32(float %a)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; TEST 11 (positive case)
|
|
|
|
; Check propagation.
|
|
|
|
|
|
|
|
; FNATTRS: Function Attrs: noinline nounwind uwtable
|
|
|
|
; FNATTRS-NEXT: define void @f1()
|
|
|
|
define void @f1() #0 {
|
|
|
|
tail call void @nofree_function()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FNATTRS: Function Attrs: noinline nounwind uwtable
|
|
|
|
; FNATTRS-NEXT: define void @f2()
|
|
|
|
define void @f2() #0 {
|
|
|
|
tail call void @f1()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2019-11-02 23:35:38 +08:00
|
|
|
|
|
|
|
declare noalias i8* @malloc(i64)
|
2019-07-13 01:38:51 +08:00
|
|
|
|
2019-07-13 00:29:14 +08:00
|
|
|
attributes #0 = { nounwind uwtable noinline }
|
|
|
|
attributes #1 = { nounwind }
|
|
|
|
attributes #2 = { nobuiltin nounwind }
|