1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
4 declare void @capture(ptr)
5 declare void @some_call()
7 define i32 @test_call_before_capture(ptr %p) {
8 ; CHECK-LABEL: define i32 @test_call_before_capture(
9 ; CHECK-SAME: ptr [[P:%.*]]) {
10 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
11 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
12 ; CHECK-NEXT: call void @some_call()
13 ; CHECK-NEXT: call void @capture(ptr [[A]])
14 ; CHECK-NEXT: ret i32 123
18 call void @some_call()
20 call void @capture(ptr %a)
24 define i32 @test_call_after_capture(ptr %p) {
25 ; CHECK-LABEL: define i32 @test_call_after_capture(
26 ; CHECK-SAME: ptr [[P:%.*]]) {
27 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
28 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
29 ; CHECK-NEXT: call void @capture(ptr [[A]])
30 ; CHECK-NEXT: call void @some_call()
31 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
32 ; CHECK-NEXT: ret i32 [[V]]
36 call void @capture(ptr %a)
37 call void @some_call()
42 define i32 @test_store_before_capture(ptr %p) {
43 ; CHECK-LABEL: define i32 @test_store_before_capture(
44 ; CHECK-SAME: ptr [[P:%.*]]) {
45 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
46 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
47 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8
48 ; CHECK-NEXT: store i32 42, ptr [[P2]], align 4
49 ; CHECK-NEXT: call void @capture(ptr [[A]])
50 ; CHECK-NEXT: ret i32 123
54 %p2 = load ptr, ptr %p
57 call void @capture(ptr %a)
61 define i32 @test_store_after_capture(ptr %p) {
62 ; CHECK-LABEL: define i32 @test_store_after_capture(
63 ; CHECK-SAME: ptr [[P:%.*]]) {
64 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
65 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
66 ; CHECK-NEXT: call void @capture(ptr [[A]])
67 ; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8
68 ; CHECK-NEXT: store i32 42, ptr [[P2]], align 4
69 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
70 ; CHECK-NEXT: ret i32 [[V]]
74 call void @capture(ptr %a)
75 %p2 = load ptr, ptr %p
81 define i32 @test_capture_readonly() {
82 ; CHECK-LABEL: define i32 @test_capture_readonly() {
83 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
84 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
85 ; CHECK-NEXT: call void @capture(ptr readonly [[A]])
86 ; CHECK-NEXT: ret i32 123
90 call void @capture(ptr readonly %a)
95 define i32 @test_capture_readonly_with_following_call() {
96 ; CHECK-LABEL: define i32 @test_capture_readonly_with_following_call() {
97 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
98 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
99 ; CHECK-NEXT: call void @capture(ptr readonly [[A]])
100 ; CHECK-NEXT: call void @some_call()
101 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
102 ; CHECK-NEXT: ret i32 [[V]]
105 store i32 123, ptr %a
106 call void @capture(ptr readonly %a)
107 call void @some_call()
108 %v = load i32, ptr %a
112 declare void @use(i32)
114 define i32 @test_capture_readonly_in_loop() {
115 ; CHECK-LABEL: define i32 @test_capture_readonly_in_loop() {
116 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
117 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
118 ; CHECK-NEXT: br label [[LOOP:%.*]]
120 ; CHECK-NEXT: call void @capture(ptr readonly [[A]])
121 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
122 ; CHECK-NEXT: call void @use(i32 [[V]]) #[[ATTR0:[0-9]+]]
123 ; CHECK-NEXT: br label [[LOOP]]
126 store i32 123, ptr %a
130 call void @capture(ptr readonly %a)
131 %v = load i32, ptr %a
132 call void @use(i32 %v) memory(none)
136 define i32 @test_splat_gep_capture(<1 x i32> %index) {
137 ; CHECK-LABEL: define i32 @test_splat_gep_capture(
138 ; CHECK-SAME: <1 x i32> [[INDEX:%.*]]) {
139 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
140 ; CHECK-NEXT: store i32 123, ptr [[A]], align 4
141 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr inbounds i32, ptr [[A]], <1 x i32> [[INDEX]]
142 ; CHECK-NEXT: call void @some_call(<1 x ptr> [[PTRS]])
143 ; CHECK-NEXT: [[RELOAD:%.*]] = load i32, ptr [[A]], align 4
144 ; CHECK-NEXT: ret i32 [[RELOAD]]
147 store i32 123, ptr %a
148 %ptrs = getelementptr inbounds i32, ptr %a, <1 x i32> %index
149 call void @some_call(<1 x ptr> %ptrs)
150 %reload = load i32, ptr %a