1 ; RUN: opt -instcombine -S < %s | FileCheck %s
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4 ; This test makes sure that these instructions are properly eliminated.
6 target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
8 @X = constant i32 42 ; <i32*> [#uses=2]
9 @X2 = constant i32 47 ; <i32*> [#uses=1]
10 @Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ] ; <[2 x { i32, float }]*> [#uses=2]
11 @Z = constant [2 x { i32, float }] zeroinitializer ; <[2 x { i32, float }]*> [#uses=1]
13 @GLOBAL = internal constant [4 x i32] zeroinitializer
16 ; CHECK-LABEL: @test1(
19 %B = load i32* @X ; <i32> [#uses=1]
23 ; CHECK-LABEL: @test2(
25 define float @test2() {
26 %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1 ; <float*> [#uses=1]
27 %B = load float* %A ; <float> [#uses=1]
31 ; CHECK-LABEL: @test3(
34 %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0 ; <i32*> [#uses=1]
35 %B = load i32* %A ; <i32> [#uses=1]
39 ; CHECK-LABEL: @test4(
42 %A = getelementptr [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0 ; <i32*> [#uses=1]
43 %B = load i32* %A ; <i32> [#uses=1]
47 ; CHECK-LABEL: @test5(
49 define i32 @test5(i1 %C) {
50 %Y = select i1 %C, i32* @X, i32* @X2 ; <i32*> [#uses=1]
51 %Z = load i32* %Y ; <i32> [#uses=1]
55 ; CHECK-LABEL: @test7(
57 define i32 @test7(i32 %X) {
58 %V = getelementptr i32* null, i32 %X ; <i32*> [#uses=1]
59 %R = load i32* %V ; <i32> [#uses=1]
63 ; CHECK-LABEL: @test8(
65 define i32 @test8(i32* %P) {
67 %X = load i32* %P ; <i32> [#uses=1]
71 ; CHECK-LABEL: @test9(
73 define i32 @test9(i32* %P) {
74 %X = load i32* %P ; <i32> [#uses=1]
75 %Y = load i32* %P ; <i32> [#uses=1]
76 %Z = sub i32 %X, %Y ; <i32> [#uses=1]
80 ; CHECK-LABEL: @test10(
82 define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
83 br i1 %C.upgrd.1, label %T, label %F
92 %V = load i32* %P ; <i32> [#uses=1]
96 ; CHECK-LABEL: @test11(
98 define double @test11(double* %p) {
99 %t0 = getelementptr double* %p, i32 1
100 store double 2.0, double* %t0
101 %t1 = getelementptr double* %p, i32 1
102 %x = load double* %t1
106 ; CHECK-LABEL: @test12(
108 define i32 @test12(i32* %P) {
110 store i32 123, i32* %A
111 ; Cast the result of the load not the source
112 %Q = bitcast i32* %A to i32*
117 ; CHECK-LABEL: @test13(
119 define <16 x i8> @test13(<2 x i64> %x) {
120 %tmp = load <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
124 define i8 @test14(i8 %x, i32 %y) {
125 ; This test must not have the store of %x forwarded to the load -- there is an
126 ; intervening store if %y. However, the intervening store occurs with a different
127 ; type and size and to a different pointer value. This is ensuring that none of
128 ; those confuse the analysis into thinking that the second store does not alias
130 ; CHECK-LABEL: @test14(
131 ; CHECK: %[[R:.*]] = load i8*
132 ; CHECK-NEXT: ret i8 %[[R]]
134 %a.i8 = bitcast i32* %a to i8*
135 store i8 %x, i8* %a.i8
136 store i32 %y, i32* %a
141 @test15_global = external global i32
143 define i8 @test15(i8 %x, i32 %y) {
144 ; Same test as @test14 essentially, but using a global instead of an alloca.
145 ; CHECK-LABEL: @test15(
146 ; CHECK: %[[R:.*]] = load i8*
147 ; CHECK-NEXT: ret i8 %[[R]]
148 %g.i8 = bitcast i32* @test15_global to i8*
149 store i8 %x, i8* %g.i8
150 store i32 %y, i32* @test15_global
155 define void @test16(i8* %x, i8* %a, i8* %b, i8* %c) {
156 ; Check that we canonicalize loads which are only stored to use integer types
157 ; when there is a valid integer type.
158 ; CHECK-LABEL: @test16(
159 ; CHECK: %[[L1:.*]] = load i32*
161 ; CHECK: store i32 %[[L1]], i32*
162 ; CHECK: store i32 %[[L1]], i32*
164 ; CHECK: %[[L1:.*]] = load i32*
166 ; CHECK: store i32 %[[L1]], i32*
167 ; CHECK: store i32 %[[L1]], i32*
172 %x.cast = bitcast i8* %x to float*
173 %a.cast = bitcast i8* %a to float*
174 %b.cast = bitcast i8* %b to float*
175 %c.cast = bitcast i8* %c to i32*
177 %x1 = load float* %x.cast
178 store float %x1, float* %a.cast
179 store float %x1, float* %b.cast
181 %x2 = load float* %x.cast
182 store float %x2, float* %b.cast
183 %x2.cast = bitcast float %x2 to i32
184 store i32 %x2.cast, i32* %c.cast
189 define void @test17(i8** %x, i8 %y) {
190 ; Check that in cases similar to @test16 we don't try to rewrite a load when
191 ; its only use is a store but it is used as the pointer to that store rather
194 ; CHECK-LABEL: @test17(
195 ; CHECK: %[[L:.*]] = load i8**
196 ; CHECK: store i8 %y, i8* %[[L]]
199 %x.load = load i8** %x
200 store i8 %y, i8* %x.load