blob: 83c893e17dd6d35d9b7a37225b3cbf8e235d1bf8 [file] [log] [blame]
Chandler Carruthc908ca12012-08-21 08:39:44 +00001; RUN: opt < %s -instcombine -S | FileCheck %s
Kenneth Uildriks90fedc62009-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 Lattner7ebda6b2007-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 Lattner94341842010-11-18 06:16:43 +00005define float @test1(i32 %hash, float %x, float %y, float %z, float %w) {
Chris Lattner7ebda6b2007-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]
Chandler Carruthc908ca12012-08-21 08:39:44 +00009 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)
Chris Lattner94341842010-11-18 06:16:43 +000010
11; CHECK: @test1
12; CHECK-NOT: alloca
13; CHECK-NOT: call{{.*}}@llvm.memcpy
Chris Lattner94341842010-11-18 06:16:43 +000014
Chris Lattner7ebda6b2007-04-25 06:29:34 +000015 %tmp3 = shl i32 %hash, 2 ; <i32> [#uses=1]
16 %tmp5 = and i32 %tmp3, 124 ; <i32> [#uses=4]
17 %tmp753 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp5 ; <float*> [#uses=1]
18 %tmp9 = load float* %tmp753 ; <float> [#uses=1]
Dan Gohmana5b96452009-06-04 22:49:04 +000019 %tmp11 = fmul float %tmp9, %x ; <float> [#uses=1]
20 %tmp13 = fadd float %tmp11, 0.000000e+00 ; <float> [#uses=1]
Chris Lattner7ebda6b2007-04-25 06:29:34 +000021 %tmp17.sum52 = or i32 %tmp5, 1 ; <i32> [#uses=1]
22 %tmp1851 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp17.sum52 ; <float*> [#uses=1]
23 %tmp19 = load float* %tmp1851 ; <float> [#uses=1]
Dan Gohmana5b96452009-06-04 22:49:04 +000024 %tmp21 = fmul float %tmp19, %y ; <float> [#uses=1]
25 %tmp23 = fadd float %tmp21, %tmp13 ; <float> [#uses=1]
Chris Lattner7ebda6b2007-04-25 06:29:34 +000026 %tmp27.sum50 = or i32 %tmp5, 2 ; <i32> [#uses=1]
27 %tmp2849 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp27.sum50 ; <float*> [#uses=1]
28 %tmp29 = load float* %tmp2849 ; <float> [#uses=1]
Dan Gohmana5b96452009-06-04 22:49:04 +000029 %tmp31 = fmul float %tmp29, %z ; <float> [#uses=1]
30 %tmp33 = fadd float %tmp31, %tmp23 ; <float> [#uses=1]
Chris Lattner7ebda6b2007-04-25 06:29:34 +000031 %tmp37.sum48 = or i32 %tmp5, 3 ; <i32> [#uses=1]
32 %tmp3847 = getelementptr [128 x float]* %lookupTable, i32 0, i32 %tmp37.sum48 ; <float*> [#uses=1]
33 %tmp39 = load float* %tmp3847 ; <float> [#uses=1]
Dan Gohmana5b96452009-06-04 22:49:04 +000034 %tmp41 = fmul float %tmp39, %w ; <float> [#uses=1]
35 %tmp43 = fadd float %tmp41, %tmp33 ; <float> [#uses=1]
Chris Lattner7ebda6b2007-04-25 06:29:34 +000036 ret float %tmp43
37}
38
Chris Lattner7aeae252010-11-18 06:20:47 +000039declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
40
41%T = type { i8, [123 x i8] }
Peter Collingbourne97b10762012-05-19 22:52:10 +000042%U = type { i32, i32, i32, i32, i32 }
Chris Lattner7aeae252010-11-18 06:20:47 +000043
44@G = constant %T {i8 1, [123 x i8] zeroinitializer }
Peter Collingbourne97b10762012-05-19 22:52:10 +000045@H = constant [2 x %U] zeroinitializer, align 16
Chris Lattner7aeae252010-11-18 06:20:47 +000046
47define void @test2() {
48 %A = alloca %T
49 %B = alloca %T
50 %a = bitcast %T* %A to i8*
51 %b = bitcast %T* %B to i8*
52
53; CHECK: @test2
54
55; %A alloca is deleted
Chandler Carruthc908ca12012-08-21 08:39:44 +000056; CHECK-NEXT: alloca [124 x i8]
57; CHECK-NEXT: getelementptr inbounds [124 x i8]*
Chris Lattner7aeae252010-11-18 06:20:47 +000058
59; use @G instead of %A
Chandler Carruthc908ca12012-08-21 08:39:44 +000060; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* getelementptr inbounds (%T* @G, i64 0, i32 0)
Chris Lattner7aeae252010-11-18 06:20:47 +000061 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
62 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
63 call void @bar(i8* %b)
64 ret void
65}
66
67declare void @bar(i8*)
Chris Lattnerf183d5c2010-11-18 06:26:49 +000068
69
70;; Should be able to eliminate the alloca.
71define void @test3() {
72 %A = alloca %T
73 %a = bitcast %T* %A to i8*
74 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
75 call void @bar(i8* %a) readonly
76; CHECK: @test3
Chandler Carruthc908ca12012-08-21 08:39:44 +000077; CHECK-NEXT: call void @bar(i8* getelementptr inbounds (%T* @G, i64 0, i32 0))
Chris Lattnerf183d5c2010-11-18 06:26:49 +000078 ret void
79}
Chris Lattnerac570132010-11-18 06:41:51 +000080
81define void @test4() {
82 %A = alloca %T
83 %a = bitcast %T* %A to i8*
84 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
85 call void @baz(i8* byval %a)
86; CHECK: @test4
Chandler Carruthc908ca12012-08-21 08:39:44 +000087; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T* @G, i64 0, i32 0))
Chris Lattnerac570132010-11-18 06:41:51 +000088 ret void
89}
90
Nick Lewyckya61df3f2011-06-27 05:40:02 +000091declare void @llvm.lifetime.start(i64, i8*)
92define void @test5() {
93 %A = alloca %T
94 %a = bitcast %T* %A to i8*
95 call void @llvm.lifetime.start(i64 -1, i8* %a)
96 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
97 call void @baz(i8* byval %a)
98; CHECK: @test5
Chandler Carruthc908ca12012-08-21 08:39:44 +000099; CHECK-NEXT: call void @baz(i8* byval getelementptr inbounds (%T* @G, i64 0, i32 0))
Nick Lewyckya61df3f2011-06-27 05:40:02 +0000100 ret void
101}
102
103
Chris Lattnerac570132010-11-18 06:41:51 +0000104declare void @baz(i8* byval)
Peter Collingbourne97b10762012-05-19 22:52:10 +0000105
106
107define void @test6() {
108 %A = alloca %U, align 16
109 %a = bitcast %U* %A to i8*
110 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast ([2 x %U]* @H to i8*), i64 20, i32 16, i1 false)
111 call void @bar(i8* %a) readonly
112; CHECK: @test6
Chandler Carruthc908ca12012-08-21 08:39:44 +0000113; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*))
Peter Collingbourne97b10762012-05-19 22:52:10 +0000114 ret void
115}
116
117define void @test7() {
118 %A = alloca %U, align 16
119 %a = bitcast %U* %A to i8*
120 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)
121 call void @bar(i8* %a) readonly
122; CHECK: @test7
Chandler Carruthc908ca12012-08-21 08:39:44 +0000123; CHECK-NEXT: call void @bar(i8* bitcast ([2 x %U]* @H to i8*))
Peter Collingbourne97b10762012-05-19 22:52:10 +0000124 ret void
125}
126
127define void @test8() {
128 %A = alloca %U, align 16
129 %a = bitcast %U* %A to i8*
130 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)
131 call void @bar(i8* %a) readonly
132; CHECK: @test8
133; CHECK: llvm.memcpy
134; CHECK: bar
135 ret void
136}