1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3; This turns into a&1 != 0
4define <2 x i1> @test1(<2 x i64> %a) {
5  %t = trunc <2 x i64> %a to <2 x i1>
6  ret <2 x i1> %t
7
8; CHECK-LABEL: @test1(
9; CHECK:   and <2 x i64> %a, <i64 1, i64 1>
10; CHECK:   icmp ne <2 x i64> %1, zeroinitializer
11}
12
13; The ashr turns into an lshr.
14define <2 x i64> @test2(<2 x i64> %a) {
15  %b = and <2 x i64> %a, <i64 65535, i64 65535>
16  %t = ashr <2 x i64> %b, <i64 1, i64 1>
17  ret <2 x i64> %t
18
19; CHECK-LABEL: @test2(
20; CHECK:   and <2 x i64> %a, <i64 65535, i64 65535>
21; CHECK:   lshr <2 x i64> %b, <i64 1, i64 1>
22}
23
24
25
26define <2 x i64> @test3(<4 x float> %a, <4 x float> %b) nounwind readnone {
27entry:
28	%cmp = fcmp ord <4 x float> %a, zeroinitializer
29	%sext = sext <4 x i1> %cmp to <4 x i32>
30	%cmp4 = fcmp ord <4 x float> %b, zeroinitializer
31	%sext5 = sext <4 x i1> %cmp4 to <4 x i32>
32	%and = and <4 x i32> %sext, %sext5
33	%conv = bitcast <4 x i32> %and to <2 x i64>
34	ret <2 x i64> %conv
35
36; CHECK-LABEL: @test3(
37; CHECK:   fcmp ord <4 x float> %a, %b
38}
39
40define <2 x i64> @test4(<4 x float> %a, <4 x float> %b) nounwind readnone {
41entry:
42	%cmp = fcmp uno <4 x float> %a, zeroinitializer
43	%sext = sext <4 x i1> %cmp to <4 x i32>
44	%cmp4 = fcmp uno <4 x float> %b, zeroinitializer
45	%sext5 = sext <4 x i1> %cmp4 to <4 x i32>
46	%or = or <4 x i32> %sext, %sext5
47	%conv = bitcast <4 x i32> %or to <2 x i64>
48	ret <2 x i64> %conv
49; CHECK-LABEL: @test4(
50; CHECK:   fcmp uno <4 x float> %a, %b
51}
52
53
54; rdar://7434900
55define <2 x i64> @test5(<4 x float> %a, <4 x float> %b) nounwind readnone {
56entry:
57	%cmp = fcmp ult <4 x float> %a, zeroinitializer
58	%sext = sext <4 x i1> %cmp to <4 x i32>
59	%cmp4 = fcmp ult <4 x float> %b, zeroinitializer
60	%sext5 = sext <4 x i1> %cmp4 to <4 x i32>
61	%and = and <4 x i32> %sext, %sext5
62	%conv = bitcast <4 x i32> %and to <2 x i64>
63	ret <2 x i64> %conv
64
65; CHECK-LABEL: @test5(
66; CHECK:   sext <4 x i1> %cmp to <4 x i32>
67; The sext-and pair is canonicalized to a select.
68; CHECK:   select <4 x i1> %cmp4, <4 x i32>	%sext, <4 x i32> zeroinitializer
69}
70
71
72define void @convert(<2 x i32>* %dst.addr, <2 x i64> %src) nounwind {
73entry:
74  %val = trunc <2 x i64> %src to <2 x i32>
75  %add = add <2 x i32> %val, <i32 1, i32 1>
76  store <2 x i32> %add, <2 x i32>* %dst.addr
77  ret void
78}
79
80define <2 x i65> @foo(<2 x i64> %t) {
81  %a = trunc <2 x i64> %t to <2 x i32>
82  %b = zext <2 x i32> %a to <2 x i65>
83  ret <2 x i65> %b
84}
85define <2 x i64> @bar(<2 x i65> %t) {
86  %a = trunc <2 x i65> %t to <2 x i32>
87  %b = zext <2 x i32> %a to <2 x i64>
88  ret <2 x i64> %b
89}
90define <2 x i65> @foos(<2 x i64> %t) {
91  %a = trunc <2 x i64> %t to <2 x i32>
92  %b = sext <2 x i32> %a to <2 x i65>
93  ret <2 x i65> %b
94}
95define <2 x i64> @bars(<2 x i65> %t) {
96  %a = trunc <2 x i65> %t to <2 x i32>
97  %b = sext <2 x i32> %a to <2 x i64>
98  ret <2 x i64> %b
99}
100define <2 x i64> @quxs(<2 x i64> %t) {
101  %a = trunc <2 x i64> %t to <2 x i32>
102  %b = sext <2 x i32> %a to <2 x i64>
103  ret <2 x i64> %b
104}
105define <2 x i64> @quxt(<2 x i64> %t) {
106  %a = shl <2 x i64> %t, <i64 32, i64 32>
107  %b = ashr <2 x i64> %a, <i64 32, i64 32>
108  ret <2 x i64> %b
109}
110define <2 x double> @fa(<2 x double> %t) {
111  %a = fptrunc <2 x double> %t to <2 x float>
112  %b = fpext <2 x float> %a to <2 x double>
113  ret <2 x double> %b
114}
115define <2 x double> @fb(<2 x double> %t) {
116  %a = fptoui <2 x double> %t to <2 x i64>
117  %b = uitofp <2 x i64> %a to <2 x double>
118  ret <2 x double> %b
119}
120define <2 x double> @fc(<2 x double> %t) {
121  %a = fptosi <2 x double> %t to <2 x i64>
122  %b = sitofp <2 x i64> %a to <2 x double>
123  ret <2 x double> %b
124}
125
126; PR9228
127; This was a crasher, so no CHECK statements.
128define <4 x float> @f(i32 %a) nounwind alwaysinline {
129; CHECK-LABEL: @f(
130entry:
131  %dim = insertelement <4 x i32> undef, i32 %a, i32 0
132  %dim30 = insertelement <4 x i32> %dim, i32 %a, i32 1
133  %dim31 = insertelement <4 x i32> %dim30, i32 %a, i32 2
134  %dim32 = insertelement <4 x i32> %dim31, i32 %a, i32 3
135
136  %offset_ptr = getelementptr <4 x float>, <4 x float>* null, i32 1
137  %offset_int = ptrtoint <4 x float>* %offset_ptr to i64
138  %sizeof32 = trunc i64 %offset_int to i32
139
140  %smearinsert33 = insertelement <4 x i32> undef, i32 %sizeof32, i32 0
141  %smearinsert34 = insertelement <4 x i32> %smearinsert33, i32 %sizeof32, i32 1
142  %smearinsert35 = insertelement <4 x i32> %smearinsert34, i32 %sizeof32, i32 2
143  %smearinsert36 = insertelement <4 x i32> %smearinsert35, i32 %sizeof32, i32 3
144
145  %delta_scale = mul <4 x i32> %dim32, %smearinsert36
146  %offset_delta = add <4 x i32> zeroinitializer, %delta_scale
147
148  %offset_varying_delta = add <4 x i32> %offset_delta, undef
149
150  ret <4 x float> undef
151}
152
153define <8 x i32> @pr24458(<8 x float> %n) {
154; CHECK-LABEL: @pr24458
155  %notequal_b_load_.i = fcmp une <8 x float> %n, zeroinitializer
156  %equal_a_load72_.i = fcmp ueq <8 x float> %n, zeroinitializer
157  %notequal_b_load__to_boolvec.i = sext <8 x i1> %notequal_b_load_.i to <8 x i32>
158  %equal_a_load72__to_boolvec.i = sext <8 x i1> %equal_a_load72_.i to <8 x i32>
159  %wrong = or <8 x i32> %notequal_b_load__to_boolvec.i, %equal_a_load72__to_boolvec.i
160  ret <8 x i32> %wrong
161; CHECK-NEXT: ret <8 x i32> <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
162}
163
164