1 ; RUN: opt < %s -instcombine -S | FileCheck %s 2 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64" 3 @C.0.1248 = internal constant [128 x float] [ float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float -1.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float -1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 ], align 32 ; <[128 x float]*> [#uses=1] 4 5 define float @test1(i32 %hash, float %x, float %y, float %z, float %w) { 6 entry: 7 %lookupTable = alloca [128 x float], align 16 ; <[128 x float]*> [#uses=5] 8 %lookupTable1 = bitcast [128 x float]* %lookupTable to i8* ; <i8*> [#uses=1] 9 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %lookupTable1, i8* bitcast ([128 x float]* @C.0.1248 to i8*), i64 512, i32 16, i1 false) 10 11 ; CHECK-LABEL: @test1( 12 ; CHECK-NOT: alloca 13 ; CHECK-NOT: call{{.*}}@llvm.memcpy 14 15 %tmp3 = shl i32 %hash, 2 ; <i32> [#uses=1] 16 %tmp5 = and i32 %tmp3, 124 ; <i32> [#uses=4] 17 %tmp753 = getelementptr [128 x float], [128 x float]* %lookupTable, i32 0, i32 %tmp5 ; <float*> [#uses=1] 18 %tmp9 = load float, float* %tmp753 ; <float> [#uses=1] 19 %tmp11 = fmul float %tmp9, %x ; <float> [#uses=1] 20 %tmp13 = fadd float %tmp11, 0.000000e+00 ; <float> [#uses=1] 21 %tmp17.sum52 = or i32 %tmp5, 1 ; <i32> [#uses=1] 22 %tmp1851 = getelementptr [128 x float], [128 x float]* %lookupTable, i32 0, i32 %tmp17.sum52 ; <float*> [#uses=1] 23 %tmp19 = load float, float* %tmp1851 ; <float> [#uses=1] 24 %tmp21 = fmul float %tmp19, %y ; <float> [#uses=1] 25 %tmp23 = fadd float %tmp21, %tmp13 ; <float> [#uses=1] 26 %tmp27.sum50 = or i32 %tmp5, 2 ; <i32> [#uses=1] 27 %tmp2849 = getelementptr [128 x float], [128 x float]* %lookupTable, i32 0, i32 %tmp27.sum50 ; <float*> [#uses=1] 28 %tmp29 = load float, float* %tmp2849 ; <float> [#uses=1] 29 %tmp31 = fmul float %tmp29, %z ; <float> [#uses=1] 30 %tmp33 = fadd float %tmp31, %tmp23 ; <float> [#uses=1] 31 %tmp37.sum48 = or i32 %tmp5, 3 ; <i32> [#uses=1] 32 %tmp3847 = getelementptr [128 x float], [128 x float]* %lookupTable, i32 0, i32 %tmp37.sum48 ; <float*> [#uses=1] 33 %tmp39 = load float, float* %tmp3847 ; <float> [#uses=1] 34 %tmp41 = fmul float %tmp39, %w ; <float> [#uses=1] 35 %tmp43 = fadd float %tmp41, %tmp33 ; <float> [#uses=1] 36 ret float %tmp43 37 } 38 39 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind 40 declare void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* nocapture, i8* nocapture, i64, i32, i1) nounwind 41 declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind 42 declare void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind 43 44 %T = type { i8, [123 x i8] } 45 %U = type { i32, i32, i32, i32, i32 } 46 47 @G = constant %T {i8 1, [123 x i8] zeroinitializer } 48 @H = constant [2 x %U] zeroinitializer, align 16 49 50 define void @test2() { 51 %A = alloca %T 52 %B = alloca %T 53 %a = bitcast %T* %A to i8* 54 %b = bitcast %T* %B to i8* 55 56 ; CHECK-LABEL: @test2( 57 58 ; %A alloca is deleted 59 ; CHECK-NEXT: alloca [124 x i8] 60 ; CHECK-NEXT: getelementptr inbounds [124 x i8], [124 x i8]* 61 62 ; use @G instead of %A 63 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0) 64 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false) 65 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false) 66 call void @bar(i8* %b) 67 ret void 68 } 69 70 define void @test2_addrspacecast() { 71 %A = alloca %T 72 %B = alloca %T 73 %a = addrspacecast %T* %A to i8 addrspace(1)* 74 %b = addrspacecast %T* %B to i8 addrspace(1)* 75 76 ; CHECK-LABEL: @test2_addrspacecast( 77 78 ; %A alloca is deleted 79 ; This doesn't exactly match what test2 does, because folding the type 80 ; cast into the alloca doesn't work for the addrspacecast yet. 81 ; CHECK-NEXT: alloca [124 x i8] 82 ; CHECK-NEXT: getelementptr 83 ; CHECK-NEXT: addrspacecast 84 85 ; use @G instead of %A 86 ; CHECK-NEXT: call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %{{.*}}, 87 call void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false) 88 call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %b, i8 addrspace(1)* %a, i64 124, i32 4, i1 false) 89 call void @bar_as1(i8 addrspace(1)* %b) 90 ret void 91 } 92 93 declare void @bar(i8*) 94 declare void @bar_as1(i8 addrspace(1)*) 95 96 97 ;; Should be able to eliminate the alloca. 98 define void @test3() { 99 %A = alloca %T 100 %a = bitcast %T* %A to i8* 101 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false) 102 call void @bar(i8* %a) readonly 103 ; CHECK-LABEL: @test3( 104 ; CHECK-NEXT: call void @bar(i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0)) 105 ret void 106 } 107 108 define void @test3_addrspacecast() { 109 %A = alloca %T 110 %a = bitcast %T* %A to i8* 111 call void @llvm.memcpy.p0i8.p1i8.i64(i8* %a, i8 addrspace(1)* addrspacecast (%T* @G to i8 addrspace(1)*), i64 124, i32 4, i1 false) 112 call void @bar(i8* %a) readonly 113 ; CHECK-LABEL: @test3_addrspacecast( 114 ; CHECK-NEXT: call void @bar(i8* getelementptr inbounds (%T, %T* @G, i64 0, i32 0)) 115 ret void 116 } 117 118 119 define void @test4() { 120 %A = alloca %T 121 %a = bitcast %T* %A to i8* 122 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false) 123 call void @baz(i8* byval %a) 124 ; CHECK-LABEL: @test4( 125 ; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T, %T* @G, i64 0, i32 0)) 126 ret void 127 } 128 129 declare void @llvm.lifetime.start(i64, i8*) 130 define void @test5() { 131 %A = alloca %T 132 %a = bitcast %T* %A to i8* 133 call void @llvm.lifetime.start(i64 -1, i8* %a) 134 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false) 135 call void @baz(i8* byval %a) 136 ; CHECK-LABEL: @test5( 137 ; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T, %T* @G, i64 0, i32 0)) 138 ret void 139 } 140 141 142 declare void @baz(i8* byval) 143 144 145 define void @test6() { 146 %A = alloca %U, align 16 147 %a = bitcast %U* %A to i8* 148 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast ([2 x %U]* @H to i8*), i64 20, i32 16, i1 false) 149 call void @bar(i8* %a) readonly 150 ; CHECK-LABEL: @test6( 151 ; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*)) 152 ret void 153 } 154 155 define void @test7() { 156 %A = alloca %U, align 16 157 %a = bitcast %U* %A to i8* 158 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U], [2 x %U]* @H, i64 0, i32 0) to i8*), i64 20, i32 4, i1 false) 159 call void @bar(i8* %a) readonly 160 ; CHECK-LABEL: @test7( 161 ; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*)) 162 ret void 163 } 164 165 define void @test8() { 166 %A = alloca %U, align 16 167 %a = bitcast %U* %A to i8* 168 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U], [2 x %U]* @H, i64 0, i32 1) to i8*), i64 20, i32 4, i1 false) 169 call void @bar(i8* %a) readonly 170 ; CHECK-LABEL: @test8( 171 ; CHECK: llvm.memcpy 172 ; CHECK: bar 173 ret void 174 } 175 176 177 define void @test8_addrspacecast() { 178 %A = alloca %U, align 16 179 %a = bitcast %U* %A to i8* 180 call void @llvm.memcpy.p0i8.p1i8.i64(i8* %a, i8 addrspace(1)* addrspacecast (%U* getelementptr ([2 x %U], [2 x %U]* @H, i64 0, i32 1) to i8 addrspace(1)*), i64 20, i32 4, i1 false) 181 call void @bar(i8* %a) readonly 182 ; CHECK-LABEL: @test8_addrspacecast( 183 ; CHECK: llvm.memcpy 184 ; CHECK: bar 185 ret void 186 } 187 188 define void @test9() { 189 %A = alloca %U, align 4 190 %a = bitcast %U* %A to i8* 191 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U], [2 x %U]* @H, i64 0, i32 1) to i8*), i64 20, i32 4, i1 false) 192 call void @bar(i8* %a) readonly 193 ; CHECK-LABEL: @test9( 194 ; CHECK-NEXT: call void @bar(i8* bitcast (%U* getelementptr inbounds ([2 x %U], [2 x %U]* @H, i64 0, i64 1) to i8*)) 195 ret void 196 } 197 198 define void @test9_addrspacecast() { 199 %A = alloca %U, align 4 200 %a = bitcast %U* %A to i8* 201 call void @llvm.memcpy.p0i8.p1i8.i64(i8* %a, i8 addrspace(1)* addrspacecast (%U* getelementptr ([2 x %U], [2 x %U]* @H, i64 0, i32 1) to i8 addrspace(1)*), i64 20, i32 4, i1 false) 202 call void @bar(i8* %a) readonly 203 ; CHECK-LABEL: @test9_addrspacecast( 204 ; CHECK-NEXT: call void @bar(i8* bitcast (%U* getelementptr inbounds ([2 x %U], [2 x %U]* @H, i64 0, i64 1) to i8*)) 205 ret void 206 } 207