1
; RUN: opt < %s -basicaa -sink -S | FileCheck %s
3
@A = external global i32
4
@B = external global i32
6
; Sink should sink the load past the store (which doesn't overlap) into
7
; the block that uses it.
11
; CHECK-NEXT: %l = load i32, i32* @A
12
; CHECK-NEXT: ret i32 %l
14
define i32 @foo(i1 %z) {
15
%l = load i32, i32* @A
17
br i1 %z, label %true, label %false
24
; But don't sink load volatiles...
27
; CHECK: load volatile
28
; CHECK-NEXT: store i32
30
define i32 @foo2(i1 %z) {
31
%l = load volatile i32, i32* @A
33
br i1 %z, label %true, label %false
40
; Sink to the nearest post-dominator
42
; CHECK-LABEL: @diamond(
48
define i32 @diamond(i32 %a, i32 %b, i32 %c) {
49
%1 = mul nsw i32 %c, %b
50
%2 = icmp sgt i32 %a, 0
51
br i1 %2, label %B0, label %B1
60
%.01 = phi i32 [ %c, %B0 ], [ %a, %B1 ]
65
; We shouldn't sink constant sized allocas from the entry block, since CodeGen
66
; interprets allocas outside the entry block as dynamically sized stack objects.
68
; CHECK-LABEL: @alloca_nosink
71
define i32 @alloca_nosink(i32 %a, i32 %b) {
74
%1 = icmp ne i32 %a, 0
75
br i1 %1, label %if, label %endif
78
%2 = getelementptr i32, i32* %0, i32 1
81
%3 = getelementptr i32, i32* %0, i32 %b
82
%4 = load i32, i32* %3
89
; Make sure we sink dynamic sized allocas
91
; CHECK-LABEL: @alloca_sink_dynamic
96
define i32 @alloca_sink_dynamic(i32 %a, i32 %b, i32 %size) {
98
%0 = alloca i32, i32 %size
99
%1 = icmp ne i32 %a, 0
100
br i1 %1, label %if, label %endif
103
%2 = getelementptr i32, i32* %0, i32 1
106
%3 = getelementptr i32, i32* %0, i32 %b
107
%4 = load i32, i32* %3
114
; We also want to sink allocas that are not in the entry block. These
115
; will already be considered as dynamically sized stack objects, so sinking
116
; them does no further damage.
118
; CHECK-LABEL: @alloca_sink_nonentry
123
define i32 @alloca_sink_nonentry(i32 %a, i32 %b, i32 %c) {
125
%cmp = icmp ne i32 %c, 0
126
br i1 %cmp, label %endif, label %if0
130
%1 = icmp ne i32 %a, 0
131
br i1 %1, label %if, label %endif
134
%2 = getelementptr i32, i32* %0, i32 1
137
%3 = getelementptr i32, i32* %0, i32 %b
138
%4 = load i32, i32* %3