xref: /llvm-project/llvm/test/Feature/OperandBundles/early-cse.ll (revision 1842a2909e80da9432c5d79a95ec2c331bd99744)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -passes=early-cse -earlycse-debug-hash < %s | FileCheck %s
3
4; While it is normally okay to do memory optimizations over calls to
5; @readonly_function and @readnone_function, we cannot do that if
6; they're carrying unknown operand bundles since the presence of
7; unknown operand bundles implies arbitrary memory effects.
8
9declare void @readonly_function() readonly nounwind willreturn
10declare void @readnone_function() readnone nounwind willreturn
11
12define i32 @test0(ptr %x) {
13; CHECK-LABEL: @test0(
14; CHECK-NEXT:  entry:
15; CHECK-NEXT:    store i32 100, ptr [[X:%.*]], align 4
16; CHECK-NEXT:    call void @readonly_function() [ "tag"() ]
17; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[X]], align 4
18; CHECK-NEXT:    ret i32 [[V]]
19;
20  entry:
21  store i32 100, ptr %x
22  call void @readonly_function() [ "tag"() ]
23
24  %v = load i32, ptr %x
25  ret i32 %v
26}
27
28define i32 @test1(ptr %x) {
29; CHECK-LABEL: @test1(
30; CHECK-NEXT:  entry:
31; CHECK-NEXT:    store i32 100, ptr [[X:%.*]], align 4
32; CHECK-NEXT:    ret i32 100
33;
34  entry:
35  store i32 100, ptr %x
36  call void @readonly_function() readonly [ "tag"() ]
37  %v = load i32, ptr %x
38  ret i32 %v
39}
40
41define i32 @test3(ptr %x) {
42; CHECK-LABEL: @test3(
43; CHECK-NEXT:  entry:
44; CHECK-NEXT:    store i32 100, ptr [[X:%.*]], align 4
45; CHECK-NEXT:    ret i32 100
46;
47  entry:
48  store i32 100, ptr %x
49  call void @readonly_function()
50  %v = load i32, ptr %x
51  ret i32 %v
52}
53
54define void @test4(ptr %x) {
55; CHECK-LABEL: @test4(
56; CHECK-NEXT:  entry:
57; CHECK-NEXT:    store i32 100, ptr [[X:%.*]], align 4
58; CHECK-NEXT:    call void @readnone_function() [ "tag"() ]
59; CHECK-NEXT:    store i32 200, ptr [[X]], align 4
60; CHECK-NEXT:    ret void
61;
62  entry:
63  store i32 100, ptr %x
64  call void @readnone_function() [ "tag"() ]
65  store i32 200, ptr %x
66  ret void
67}
68
69define void @test5(ptr %x) {
70; CHECK-LABEL: @test5(
71; CHECK-NEXT:  entry:
72; CHECK-NEXT:    store i32 200, ptr [[X:%.*]], align 4
73; CHECK-NEXT:    ret void
74;
75  entry:
76  store i32 100, ptr %x
77  call void @readnone_function() readnone [ "tag"() ]
78  store i32 200, ptr %x
79  ret void
80}
81
82define void @test6(ptr %x) {
83; The "deopt" operand bundle does not make the call to
84; @readonly_function read-write; and so the nounwind readonly call can
85; be deleted.
86; CHECK-LABEL: @test6(
87; CHECK-NEXT:  entry:
88; CHECK-NEXT:    store i32 200, ptr [[X:%.*]], align 4
89; CHECK-NEXT:    ret void
90;
91  entry:
92
93
94  store i32 100, ptr %x
95  call void @readonly_function() [ "deopt"() ]
96  store i32 200, ptr %x
97  ret void
98}
99