1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare void @use_f32(float)
5 declare void @use_v4f32(<4 x float>)
7 define <4 x float> @bitcast_inselt(i32 %x, <4 x i32> %v) {
8 ; CHECK-LABEL: @bitcast_inselt(
9 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> [[V:%.*]], i32 [[X:%.*]], i32 0
10 ; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[TMP1]] to <4 x float>
11 ; CHECK-NEXT: ret <4 x float> [[R]]
13 %xf = bitcast i32 %x to float
14 %vf = bitcast <4 x i32> %v to <4 x float>
15 %r = insertelement <4 x float> %vf, float %xf, i32 0
19 define <4 x float> @bitcast_inselt_use1(i32 %x, <4 x i32> %v) {
20 ; CHECK-LABEL: @bitcast_inselt_use1(
21 ; CHECK-NEXT: [[XF:%.*]] = bitcast i32 [[X:%.*]] to float
22 ; CHECK-NEXT: call void @use_f32(float [[XF]])
23 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> [[V:%.*]], i32 [[X]], i32 1
24 ; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[TMP1]] to <4 x float>
25 ; CHECK-NEXT: ret <4 x float> [[R]]
27 %xf = bitcast i32 %x to float
28 call void @use_f32(float %xf)
29 %vf = bitcast <4 x i32> %v to <4 x float>
30 %r = insertelement <4 x float> %vf, float %xf, i32 1
34 define <4 x float> @bitcast_inselt_use2(i32 %x, <4 x i32> %v, i32 %index) {
35 ; CHECK-LABEL: @bitcast_inselt_use2(
36 ; CHECK-NEXT: [[VF:%.*]] = bitcast <4 x i32> [[V:%.*]] to <4 x float>
37 ; CHECK-NEXT: call void @use_v4f32(<4 x float> [[VF]])
38 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> [[V]], i32 [[X:%.*]], i32 [[INDEX:%.*]]
39 ; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[TMP1]] to <4 x float>
40 ; CHECK-NEXT: ret <4 x float> [[R]]
42 %xf = bitcast i32 %x to float
43 %vf = bitcast <4 x i32> %v to <4 x float>
44 call void @use_v4f32(<4 x float> %vf)
45 %r = insertelement <4 x float> %vf, float %xf, i32 %index
49 ; Negative test - 2 extra uses would require an extra instruction.
51 define <4 x float> @bitcast_inselt_use3(i32 %x, <4 x i32> %v) {
52 ; CHECK-LABEL: @bitcast_inselt_use3(
53 ; CHECK-NEXT: [[XF:%.*]] = bitcast i32 [[X:%.*]] to float
54 ; CHECK-NEXT: call void @use_f32(float [[XF]])
55 ; CHECK-NEXT: [[VF:%.*]] = bitcast <4 x i32> [[V:%.*]] to <4 x float>
56 ; CHECK-NEXT: call void @use_v4f32(<4 x float> [[VF]])
57 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[VF]], float [[XF]], i32 0
58 ; CHECK-NEXT: ret <4 x float> [[R]]
60 %xf = bitcast i32 %x to float
61 call void @use_f32(float %xf)
62 %vf = bitcast <4 x i32> %v to <4 x float>
63 call void @use_v4f32(<4 x float> %vf)
64 %r = insertelement <4 x float> %vf, float %xf, i32 0
68 ; Negative test - wrong source type for vector.
70 define <2 x float> @bitcast_inselt_wrong_bitcast1(i32 %x, i64 %notv) {
71 ; CHECK-LABEL: @bitcast_inselt_wrong_bitcast1(
72 ; CHECK-NEXT: [[XF:%.*]] = bitcast i32 [[X:%.*]] to float
73 ; CHECK-NEXT: [[VF:%.*]] = bitcast i64 [[NOTV:%.*]] to <2 x float>
74 ; CHECK-NEXT: [[R:%.*]] = insertelement <2 x float> [[VF]], float [[XF]], i32 0
75 ; CHECK-NEXT: ret <2 x float> [[R]]
77 %xf = bitcast i32 %x to float
78 %vf = bitcast i64 %notv to <2 x float>
79 %r = insertelement <2 x float> %vf, float %xf, i32 0
83 ; Negative test - wrong source type for scalar.
85 define <2 x float> @bitcast_inselt_wrong_bitcast2(<2 x i16> %notscalar, <2 x i32> %v) {
86 ; CHECK-LABEL: @bitcast_inselt_wrong_bitcast2(
87 ; CHECK-NEXT: [[XF:%.*]] = bitcast <2 x i16> [[NOTSCALAR:%.*]] to float
88 ; CHECK-NEXT: [[VF:%.*]] = bitcast <2 x i32> [[V:%.*]] to <2 x float>
89 ; CHECK-NEXT: [[R:%.*]] = insertelement <2 x float> [[VF]], float [[XF]], i32 0
90 ; CHECK-NEXT: ret <2 x float> [[R]]
92 %xf = bitcast <2 x i16> %notscalar to float
93 %vf = bitcast <2 x i32> %v to <2 x float>
94 %r = insertelement <2 x float> %vf, float %xf, i32 0