Skip to content

Commit f549176

Browse files
committed
[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
1 parent 7c02dc2 commit f549176

19 files changed

Lines changed: 64 additions & 68 deletions

File tree

‎clang/test/CodeGenOpenCL/convergent.cl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ kernel void assume_convergent_asm()
134134
__asm__ volatile("s_barrier");
135135
}
136136

137-
// CHECK: attributes #0 = { nofree noinline norecurse nounwind willreturn "
137+
// CHECK: attributes #0 = { nofree noinline norecurse nounwind willreturn mustprogress "
138138
// CHECK: attributes #1 = { {{[^}]*}}convergent{{[^}]*}} }
139139
// CHECK: attributes #2 = { {{[^}]*}}convergent{{[^}]*}} }
140140
// CHECK: attributes #3 = { {{[^}]*}}convergent noduplicate{{[^}]*}} }

‎llvm/lib/Transforms/IPO/FunctionAttrs.cpp‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "llvm/Support/ErrorHandling.h"
5858
#include "llvm/Support/raw_ostream.h"
5959
#include "llvm/Transforms/IPO.h"
60+
#include "llvm/Transforms/Utils/Local.h"
6061
#include <cassert>
6162
#include <iterator>
6263
#include <map>
@@ -1556,21 +1557,7 @@ static bool addNoSyncAttr(const SCCNodeSet &SCCNodes) {
15561557
++NumNoSync;
15571558
},
15581559
/* RequiresExactDefinition= */ true});
1559-
bool Changed = AI.run(SCCNodes);
1560-
1561-
// readnone + not convergent implies nosync
1562-
// (This is here so that we don't have to duplicate the function local
1563-
// memory reasoning of the readnone analysis.)
1564-
for (Function *F : SCCNodes) {
1565-
if (!F || F->hasNoSync())
1566-
continue;
1567-
if (!F->doesNotAccessMemory() || F->isConvergent())
1568-
continue;
1569-
F->setNoSync();
1570-
NumNoSync++;
1571-
Changed = true;
1572-
}
1573-
return Changed;
1560+
return AI.run(SCCNodes);
15741561
}
15751562

15761563
static SCCNodesResult createSCCNodeSet(ArrayRef<Function *> Functions) {
@@ -1630,6 +1617,14 @@ static bool deriveAttrsInPostOrder(ArrayRef<Function *> Functions,
16301617

16311618
Changed |= addNoSyncAttr(Nodes.SCCNodes);
16321619

1620+
// Finally, infer the maximal set of attributes from the ones we've inferred
1621+
// above. This is handling the cases where one attribute on a signature
1622+
// implies another, but for implementation reasons the inference rule for
1623+
// the later is missing (or simply less sophisticated).
1624+
for (Function *F : Nodes.SCCNodes)
1625+
if (F)
1626+
Changed |= inferAttributesFromOthers(*F);
1627+
16331628
return Changed;
16341629
}
16351630

‎llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ define i32 @test3_no(i8* %p) nounwind {
7272
declare void @callee(i32* %p) nounwind
7373
declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1) nounwind
7474

75-
; CHECK: attributes #0 = { norecurse nosync nounwind readnone willreturn }
76-
; CHECK: attributes #1 = { nofree norecurse nosync nounwind willreturn writeonly }
77-
; CHECK: attributes #2 = { nounwind readonly }
75+
; CHECK: attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress }
76+
; CHECK: attributes #1 = { nofree norecurse nosync nounwind willreturn writeonly mustprogress }
77+
; CHECK: attributes #2 = { nofree nounwind readonly }
7878
; CHECK: attributes #3 = { nounwind }
79-
; CHECK: attributes #4 = { nosync nounwind readnone willreturn }
80-
; CHECK: attributes #5 = { nofree nosync nounwind willreturn }
81-
; CHECK: attributes #6 = { nofree norecurse nosync nounwind willreturn }
79+
; CHECK: attributes #4 = { nofree nosync nounwind readnone willreturn mustprogress }
80+
; CHECK: attributes #5 = { nofree nosync nounwind willreturn mustprogress }
81+
; CHECK: attributes #6 = { nofree norecurse nosync nounwind willreturn mustprogress }
8282
; CHECK: attributes #7 = { argmemonly nofree nosync nounwind willreturn }
8383

8484
; Root note.

‎llvm/test/CodeGen/AMDGPU/inline-attr.ll‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
; GCN: define amdgpu_kernel void @caller(float addrspace(1)* nocapture %p) local_unnamed_addr #1 {
77
; GCN: %mul.i = fmul float %load, 1.500000e+01
88

9-
; UNSAFE: attributes #0 = { norecurse nosync nounwind readnone willreturn "unsafe-fp-math"="true" }
10-
; UNSAFE: attributes #1 = { nofree norecurse nosync nounwind willreturn "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="true" }
9+
; UNSAFE: attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress "unsafe-fp-math"="true" }
10+
; UNSAFE: attributes #1 = { nofree norecurse nosync nounwind willreturn mustprogress "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="true" }
1111

12-
; NOINFS: attributes #0 = { norecurse nosync nounwind readnone willreturn "no-infs-fp-math"="true" }
13-
; NOINFS: attributes #1 = { nofree norecurse nosync nounwind willreturn "less-precise-fpmad"="false" "no-infs-fp-math"="true" "no-nans-fp-math"="false" "unsafe-fp-math"="false" }
12+
; NOINFS: attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress "no-infs-fp-math"="true" }
13+
; NOINFS: attributes #1 = { nofree norecurse nosync nounwind willreturn mustprogress "less-precise-fpmad"="false" "no-infs-fp-math"="true" "no-nans-fp-math"="false" "unsafe-fp-math"="false" }
1414

15-
; NONANS: attributes #0 = { norecurse nosync nounwind readnone willreturn "no-nans-fp-math"="true" }
16-
; NONANS: attributes #1 = { nofree norecurse nosync nounwind willreturn "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="true" "unsafe-fp-math"="false" }
15+
; NONANS: attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress "no-nans-fp-math"="true" }
16+
; NONANS: attributes #1 = { nofree norecurse nosync nounwind willreturn mustprogress "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="true" "unsafe-fp-math"="false" }
1717

1818
define float @foo(float %x) #0 {
1919
entry:

‎llvm/test/Other/cgscc-devirt-iteration.ll‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare void @unknown()
2828

2929
define void @test1() {
3030
; BEFORE-NOT: Function Attrs
31-
; AFTER: Function Attrs: nosync readnone
31+
; AFTER: Function Attrs: nofree nosync readnone
3232
; CHECK-LABEL: define void @test1()
3333
entry:
3434
%fptr = alloca void ()*
@@ -56,8 +56,8 @@ declare void @readnone_with_arg(void ()**) readnone
5656

5757
define void @test2_a(void ()** %ignore) {
5858
; BEFORE-NOT: Function Attrs
59-
; AFTER1: Function Attrs: readonly
60-
; AFTER2: Function Attrs: nosync readnone
59+
; AFTER1: Function Attrs: nofree readonly
60+
; AFTER2: Function Attrs: nofree nosync readnone
6161
; BEFORE: define void @test2_a(void ()** %ignore)
6262
; AFTER: define void @test2_a(void ()** readnone %ignore)
6363
entry:
@@ -77,8 +77,8 @@ entry:
7777

7878
define void @test2_b() {
7979
; BEFORE-NOT: Function Attrs
80-
; AFTER1: Function Attrs: readonly
81-
; AFTER2: Function Attrs: nosync readnone
80+
; AFTER1: Function Attrs: nofree readonly
81+
; AFTER2: Function Attrs: nofree nosync readnone
8282
; CHECK-LABEL: define void @test2_b()
8383
entry:
8484
%f2ptr = alloca void ()*

‎llvm/test/Other/cgscc-iterate-function-mutation.ll‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; RUN: opt -aa-pipeline=basic-aa -passes='cgscc(function-attrs,function(simplify-cfg))' -S < %s | FileCheck %s
22

3-
declare void @readnone() nosync readnone
3+
declare void @readnone() nofree nosync readnone
44
declare void @unknown()
5-
declare void @reference_function_pointer(void()*) nosync readnone
5+
declare void @reference_function_pointer(void()*) nofree nosync readnone
66

77
; The @test1_* set of functions checks that when we mutate functions with
88
; simplify-cfg to delete call edges and this ends up splitting both the SCCs
@@ -338,4 +338,4 @@ exit:
338338
ret void
339339
}
340340

341-
; CHECK: attributes #0 = { nosync readnone }
341+
; CHECK: attributes #0 = { nofree nosync readnone }

‎llvm/test/Other/cgscc-observe-devirt.ll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; without requiring the outer manager to iterate doesn't break any invariant.
1111
; RUN: opt -aa-pipeline=basic-aa -passes='cgscc(function-attrs,function(gvn),function-attrs)' -S < %s | FileCheck %s --check-prefix=AFTER
1212

13-
declare void @readnone() nosync readnone
13+
declare void @readnone() nofree nosync readnone
1414
declare void @unknown()
1515

1616
; The @test1_* checks that if we refine an indirect call to a direct call and
@@ -103,4 +103,4 @@ define void @test2_b3() {
103103
ret void
104104
}
105105

106-
; CHECK: attributes #0 = { nosync readnone }
106+
; CHECK: attributes #0 = { nofree nosync readnone }

‎llvm/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ entry:
88
ret i32 %tmp
99
}
1010

11-
; CHECK: declare i32 @e() #0
11+
; CHECK: declare i32 @e() #1
1212
declare i32 @e() readonly
1313

14-
; CHECK: attributes #0 = { readonly }
14+
; CHECK: attributes #0 = { nofree readonly }
15+
; CHECK: attributes #1 = { readonly }

‎llvm/test/Transforms/FunctionAttrs/atomic.ll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ entry:
2020
ret i32 %r
2121
}
2222

23-
; CHECK: attributes #0 = { norecurse nosync nounwind readnone ssp uwtable willreturn }
24-
; CHECK: attributes #1 = { nofree norecurse nounwind ssp uwtable willreturn }
23+
; CHECK: attributes #0 = { nofree norecurse nosync nounwind readnone ssp uwtable willreturn mustprogress }
24+
; CHECK: attributes #1 = { nofree norecurse nounwind ssp uwtable willreturn mustprogress }

‎llvm/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ entry:
2828
attributes #0 = { argmemonly }
2929
attributes #1 = { inaccessiblememonly }
3030
attributes #2 = { inaccessiblemem_or_argmemonly }
31-
; CHECK: attributes #0 = { norecurse nosync nounwind readnone willreturn }
31+
; CHECK: attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress }
3232
; CHECK-NOT: attributes

0 commit comments

Comments
 (0)