blob: 5557a8fd87540db95b3b5672d5825593d939d825 [file] [log] [blame]
Chris Lattnerd222e362010-11-18 06:16:43 +00001; RUN: opt < %s -scalarrepl -S | FileCheck %s
Kenneth Uildriksb908f8a2009-11-03 15:29:06 +00002target 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"
Chris Lattner54c4d402007-04-25 06:29:34 +00003@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
Chris Lattnerd222e362010-11-18 06:16:43 +00005define float @test1(i32 %hash, float %x, float %y, float %z, float %w) {
Chris Lattner54c4d402007-04-25 06:29:34 +00006entry:
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.i32( i8* %lookupTable1, i8* bitcast ([128 x float]* @C.0.1248 to i8*), i32 512, i32 16 )
Chris Lattnerd222e362010-11-18 06:16:43 +000010
11; CHECK: @test1
12; CHECK-NOT: alloca
13; CHECK-NOT: call{{.*}}@llvm.memcpy
14; CHECK: %lookupTable1 = bitcast [128 x float]* @C.0.1248 to i8*
15; CHECK-NOT: call{{.*}}@llvm.memcpy
16
Chris Lattner54c4d402007-04-25 06:29:34 +000017 %tmp3 = shl i32 %hash, 2 ; <i32> [#uses=1]
18 %tmp5 = and i32 %tmp3, 124 ; <i32> [#uses=4]
19 %tmp753 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp5 ; <float*> [#uses=1]
20 %tmp9 = load float* %tmp753 ; <float> [#uses=1]
Dan Gohmanae3a0be2009-06-04 22:49:04 +000021 %tmp11 = fmul float %tmp9, %x ; <float> [#uses=1]
22 %tmp13 = fadd float %tmp11, 0.000000e+00 ; <float> [#uses=1]
Chris Lattner54c4d402007-04-25 06:29:34 +000023 %tmp17.sum52 = or i32 %tmp5, 1 ; <i32> [#uses=1]
24 %tmp1851 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp17.sum52 ; <float*> [#uses=1]
25 %tmp19 = load float* %tmp1851 ; <float> [#uses=1]
Dan Gohmanae3a0be2009-06-04 22:49:04 +000026 %tmp21 = fmul float %tmp19, %y ; <float> [#uses=1]
27 %tmp23 = fadd float %tmp21, %tmp13 ; <float> [#uses=1]
Chris Lattner54c4d402007-04-25 06:29:34 +000028 %tmp27.sum50 = or i32 %tmp5, 2 ; <i32> [#uses=1]
29 %tmp2849 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp27.sum50 ; <float*> [#uses=1]
30 %tmp29 = load float* %tmp2849 ; <float> [#uses=1]
Dan Gohmanae3a0be2009-06-04 22:49:04 +000031 %tmp31 = fmul float %tmp29, %z ; <float> [#uses=1]
32 %tmp33 = fadd float %tmp31, %tmp23 ; <float> [#uses=1]
Chris Lattner54c4d402007-04-25 06:29:34 +000033 %tmp37.sum48 = or i32 %tmp5, 3 ; <i32> [#uses=1]
34 %tmp3847 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp37.sum48 ; <float*> [#uses=1]
35 %tmp39 = load float* %tmp3847 ; <float> [#uses=1]
Dan Gohmanae3a0be2009-06-04 22:49:04 +000036 %tmp41 = fmul float %tmp39, %w ; <float> [#uses=1]
37 %tmp43 = fadd float %tmp41, %tmp33 ; <float> [#uses=1]
Chris Lattner54c4d402007-04-25 06:29:34 +000038 ret float %tmp43
39}
40
41declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
Chris Lattner2e618492010-11-18 06:20:47 +000042
43
44
45declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
46
47%T = type { i8, [123 x i8] }
Peter Collingbourne9012c572012-05-19 22:52:10 +000048%U = type { i32, i32, i32, i32, i32 }
Chris Lattner2e618492010-11-18 06:20:47 +000049
50@G = constant %T {i8 1, [123 x i8] zeroinitializer }
Peter Collingbourne9012c572012-05-19 22:52:10 +000051@H = constant [2 x %U] zeroinitializer, align 16
Chris Lattner2e618492010-11-18 06:20:47 +000052
53define void @test2() {
54 %A = alloca %T
55 %B = alloca %T
56 %a = bitcast %T* %A to i8*
57 %b = bitcast %T* %B to i8*
58
59; CHECK: @test2
60
61; %A alloca is deleted
62; CHECK-NEXT: %B = alloca %T
63
64; use @G instead of %A
65; CHECK-NEXT: %a = bitcast %T* @G to i8*
66 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
67 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
68 call void @bar(i8* %b)
69 ret void
70}
71
72declare void @bar(i8*)
Chris Lattnera9be1df2010-11-18 06:26:49 +000073
74
75;; Should be able to eliminate the alloca.
76define void @test3() {
77 %A = alloca %T
78 %a = bitcast %T* %A to i8*
79 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
80 call void @bar(i8* %a) readonly
81; CHECK: @test3
82; CHECK-NEXT: %a = bitcast %T* @G to i8*
83; CHECK-NEXT: call void @bar(i8* %a)
84 ret void
85}
Chris Lattner62480652010-11-18 06:41:51 +000086
87define void @test4() {
88 %A = alloca %T
89 %a = bitcast %T* %A to i8*
90 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
91 call void @baz(i8* byval %a)
92; CHECK: @test4
93; CHECK-NEXT: %a = bitcast %T* @G to i8*
94; CHECK-NEXT: call void @baz(i8* byval %a)
95 ret void
96}
97
Nick Lewycky9174d5c2011-06-27 05:40:02 +000098declare void @llvm.lifetime.start(i64, i8*)
99define void @test5() {
100 %A = alloca %T
101 %a = bitcast %T* %A to i8*
102 call void @llvm.lifetime.start(i64 -1, i8* %a)
103 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
104 call void @baz(i8* byval %a)
105; CHECK: @test5
106; CHECK-NEXT: %a = bitcast %T* @G to i8*
107; CHECK-NEXT: call void @baz(i8* byval %a)
108 ret void
109}
110
111
Chris Lattner62480652010-11-18 06:41:51 +0000112declare void @baz(i8* byval)
Peter Collingbourne9012c572012-05-19 22:52:10 +0000113
114
115define void @test6() {
116 %A = alloca %U, align 16
117 %a = bitcast %U* %A to i8*
118 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast ([2 x %U]* @H to i8*), i64 20, i32 16, i1 false)
119 call void @bar(i8* %a) readonly
120; CHECK: @test6
121; CHECK-NEXT: %a = bitcast
122; CHECK-NEXT: call void @bar(i8* %a)
123 ret void
124}
125
126define void @test7() {
127 %A = alloca %U, align 16
128 %a = bitcast %U* %A to i8*
129 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U]* @H, i64 0, i32 0) to i8*), i64 20, i32 4, i1 false)
130 call void @bar(i8* %a) readonly
131; CHECK: @test7
132; CHECK-NEXT: %a = bitcast
133; CHECK-NEXT: call void @bar(i8* %a)
134 ret void
135}
136
137define void @test8() {
138 %A = alloca %U, align 16
139 %a = bitcast %U* %A to i8*
140 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%U* getelementptr ([2 x %U]* @H, i64 0, i32 1) to i8*), i64 20, i32 4, i1 false)
141 call void @bar(i8* %a) readonly
142; CHECK: @test8
143; CHECK: llvm.memcpy
144; CHECK: bar
145 ret void
146}