llvm.org GIT mirror llvm / d8caf85
Change the default attributes for llvm.prefetch to inaccessiblemem_or_argmemonly so that we can perform some optimizations across it. Fixes PR32365 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298781 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 3 years ago
8 changed file(s) with 65 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
330330 def int_thread_pointer : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>,
331331 GCCBuiltin<"__builtin_thread_pointer">;
332332
333 // IntrArgMemOnly is more pessimistic than strictly necessary for prefetch,
334 // however it does conveniently prevent the prefetch from being reordered
335 // with respect to nearby accesses to the same memory.
336 def int_prefetch : Intrinsic<[],
337 [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty,
338 llvm_i32_ty],
339 [IntrArgMemOnly, NoCapture<0>]>;
333 // IntrInaccessibleMemOrArgMemOnly is a little more pessimistic than strictly
334 // necessary for prefetch, however it does conveniently prevent the prefetch
335 // from being reordered overly much with respect to nearby access to the same
336 // memory while not impeding optimization.
337 def int_prefetch
338 : Intrinsic<[], [ llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ],
339 [ IntrInaccessibleMemOrArgMemOnly, ReadOnly<0>, NoCapture<0> ]>;
340340 def int_pcmarker : Intrinsic<[], [llvm_i32_ty]>;
341341
342342 def int_readcyclecounter : Intrinsic<[llvm_i64_ty]>;
980980 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
981981
982982 call void @f.nobuiltin() builtin
983 ; CHECK: call void @f.nobuiltin() #33
983 ; CHECK: call void @f.nobuiltin() #34
984984
985985 call fastcc noalias i32* @f.noalias() noinline
986986 ; CHECK: call fastcc noalias i32* @f.noalias() #11
11821182 ; CHECK: attributes #30 = { argmemonly nounwind readonly }
11831183 ; CHECK: attributes #31 = { argmemonly nounwind }
11841184 ; CHECK: attributes #32 = { nounwind readonly }
1185 ; CHECK: attributes #33 = { builtin }
1185 ; CHECK: attributes #33 = { inaccessiblemem_or_argmemonly nounwind }
1186 ; CHECK: attributes #34 = { builtin }
11861187
11871188 ;; Metadata
11881189
10211021 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
10221022
10231023 call void @f.nobuiltin() builtin
1024 ; CHECK: call void @f.nobuiltin() #36
1024 ; CHECK: call void @f.nobuiltin() #37
10251025
10261026 call fastcc noalias i32* @f.noalias() noinline
10271027 ; CHECK: call fastcc noalias i32* @f.noalias() #12
12451245 ; CHECK: attributes #33 = { argmemonly nounwind readonly }
12461246 ; CHECK: attributes #34 = { argmemonly nounwind }
12471247 ; CHECK: attributes #35 = { nounwind readonly }
1248 ; CHECK: attributes #36 = { builtin }
1248 ; CHECK: attributes #36 = { inaccessiblemem_or_argmemonly nounwind }
1249 ; CHECK: attributes #37 = { builtin }
12491250
12501251 ;; Metadata
12511252
11691169 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
11701170
11711171 call void @f.nobuiltin() builtin
1172 ; CHECK: call void @f.nobuiltin() #39
1172 ; CHECK: call void @f.nobuiltin() #40
11731173
11741174 call fastcc noalias i32* @f.noalias() noinline
11751175 ; CHECK: call fastcc noalias i32* @f.noalias() #12
15551555 ; CHECK: attributes #36 = { argmemonly nounwind readonly }
15561556 ; CHECK: attributes #37 = { argmemonly nounwind }
15571557 ; CHECK: attributes #38 = { nounwind readonly }
1558 ; CHECK: attributes #39 = { builtin }
1558 ; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind }
1559 ; CHECK: attributes #40 = { builtin }
15591560
15601561 ;; Metadata
15611562
12401240 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
12411241
12421242 call void @f.nobuiltin() builtin
1243 ; CHECK: call void @f.nobuiltin() #40
1243 ; CHECK: call void @f.nobuiltin() #41
12441244
12451245 call fastcc noalias i32* @f.noalias() noinline
12461246 ; CHECK: call fastcc noalias i32* @f.noalias() #12
15871587 }
15881588
15891589 declare void @f.writeonly() writeonly
1590 ; CHECK: declare void @f.writeonly() #39
1590 ; CHECK: declare void @f.writeonly() #40
15911591
15921592 ; CHECK: attributes #0 = { alignstack=4 }
15931593 ; CHECK: attributes #1 = { alignstack=8 }
16281628 ; CHECK: attributes #36 = { argmemonly nounwind readonly }
16291629 ; CHECK: attributes #37 = { argmemonly nounwind }
16301630 ; CHECK: attributes #38 = { nounwind readonly }
1631 ; CHECK: attributes #39 = { writeonly }
1632 ; CHECK: attributes #40 = { builtin }
1631 ; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind }
1632 ; CHECK: attributes #40 = { writeonly }
1633 ; CHECK: attributes #41 = { builtin }
16331634
16341635 ;; Metadata
16351636
12401240 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
12411241
12421242 call void @f.nobuiltin() builtin
1243 ; CHECK: call void @f.nobuiltin() #40
1243 ; CHECK: call void @f.nobuiltin() #41
12441244
12451245 call fastcc noalias i32* @f.noalias() noinline
12461246 ; CHECK: call fastcc noalias i32* @f.noalias() #12
16051605
16061606
16071607 declare void @f.writeonly() writeonly
1608 ; CHECK: declare void @f.writeonly() #39
1608 ; CHECK: declare void @f.writeonly() #40
16091609
16101610 ;; Constant Expressions
16111611
16531653 ; CHECK: attributes #36 = { argmemonly nounwind readonly }
16541654 ; CHECK: attributes #37 = { argmemonly nounwind }
16551655 ; CHECK: attributes #38 = { nounwind readonly }
1656 ; CHECK: attributes #39 = { writeonly }
1657 ; CHECK: attributes #40 = { builtin }
1656 ; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind }
1657 ; CHECK: attributes #40 = { writeonly }
1658 ; CHECK: attributes #41 = { builtin }
16581659
16591660 ;; Metadata
16601661
12431243 ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8>
12441244
12451245 call void @f.nobuiltin() builtin
1246 ; CHECK: call void @f.nobuiltin() #40
1246 ; CHECK: call void @f.nobuiltin() #41
12471247
12481248 call fastcc noalias i32* @f.noalias() noinline
12491249 ; CHECK: call fastcc noalias i32* @f.noalias() #12
16081608
16091609
16101610 declare void @f.writeonly() writeonly
1611 ; CHECK: declare void @f.writeonly() #39
1611 ; CHECK: declare void @f.writeonly() #40
16121612
16131613 ;; Constant Expressions
16141614
16561656 ; CHECK: attributes #36 = { argmemonly nounwind readonly }
16571657 ; CHECK: attributes #37 = { argmemonly nounwind }
16581658 ; CHECK: attributes #38 = { nounwind readonly }
1659 ; CHECK: attributes #39 = { writeonly }
1660 ; CHECK: attributes #40 = { builtin }
1659 ; CHECK: attributes #39 = { inaccessiblemem_or_argmemonly nounwind }
1660 ; CHECK: attributes #40 = { writeonly }
1661 ; CHECK: attributes #41 = { builtin }
16611662
16621663 ;; Metadata
16631664
0 ; RUN: opt < %s -instcombine -S | FileCheck %s
1
2 %struct.C = type { %struct.C*, i32 }
3
4 ; Check that we instcombine the load across the prefetch.
5
6 ; CHECK-LABEL: define signext i32 @foo
7 define signext i32 @foo(%struct.C* %c) local_unnamed_addr #0 {
8 ; CHECK: store i32 %dec, i32* %length_
9 ; CHECK-NOT: load
10 ; CHECK: llvm.prefetch
11 ; CHECK-NEXT: ret
12 entry:
13 %next_ = getelementptr inbounds %struct.C, %struct.C* %c, i32 0, i32 0
14 %0 = load %struct.C*, %struct.C** %next_, align 8
15 %next_1 = getelementptr inbounds %struct.C, %struct.C* %0, i32 0, i32 0
16 %1 = load %struct.C*, %struct.C** %next_1, align 8
17 store %struct.C* %1, %struct.C** %next_, align 8
18 %length_ = getelementptr inbounds %struct.C, %struct.C* %c, i32 0, i32 1
19 %2 = load i32, i32* %length_, align 8
20 %dec = add nsw i32 %2, -1
21 store i32 %dec, i32* %length_, align 8
22 %3 = bitcast %struct.C* %1 to i8*
23 call void @llvm.prefetch(i8* %3, i32 0, i32 0, i32 1)
24 %4 = load i32, i32* %length_, align 8
25 ret i32 %4
26 }
27
28 ; Function Attrs: inaccessiblemem_or_argmemonly nounwind
29 declare void @llvm.prefetch(i8* nocapture readonly, i32, i32, i32)
30
31 attributes #0 = { noinline nounwind }
32 ; We've explicitly removed the function attrs from llvm.prefetch so we get the defaults.
33 ; attributes #1 = { inaccessiblemem_or_argmemonly nounwind }