1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare <4 x float> @llvm.x86.sse41.insertps(<4 x float>, <4 x float>, i8) nounwind readnone
6 ; This should never happen, but make sure we don't crash handling a non-constant immediate byte.
8 define <4 x float> @insertps_non_const_imm(<4 x float> %v1, <4 x float> %v2, i8 %c) {
9 ; CHECK-LABEL: @insertps_non_const_imm(
10 ; CHECK-NEXT: [[RES:%.*]] = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 %c)
11 ; CHECK-NEXT: ret <4 x float> [[RES]]
13 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 %c)
18 ; If all zero mask bits are set, return a zero regardless of the other control bits.
20 define <4 x float> @insertps_0x0f(<4 x float> %v1, <4 x float> %v2) {
21 ; CHECK-LABEL: @insertps_0x0f(
22 ; CHECK-NEXT: ret <4 x float> zeroinitializer
24 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 15)
28 define <4 x float> @insertps_0xff(<4 x float> %v1, <4 x float> %v2) {
29 ; CHECK-LABEL: @insertps_0xff(
30 ; CHECK-NEXT: ret <4 x float> zeroinitializer
32 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 255)
37 ; If some zero mask bits are set that do not override the insertion, we do not change anything.
39 define <4 x float> @insertps_0x0c(<4 x float> %v1, <4 x float> %v2) {
40 ; CHECK-LABEL: @insertps_0x0c(
41 ; CHECK-NEXT: [[RES:%.*]] = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 12)
42 ; CHECK-NEXT: ret <4 x float> [[RES]]
44 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 12)
49 ; ...unless both input vectors are the same operand.
51 define <4 x float> @insertps_0x15_single_input(<4 x float> %v1) {
52 ; CHECK-LABEL: @insertps_0x15_single_input(
53 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> <float 0.000000e+00, float undef, float 0.000000e+00, float undef>, <4 x i32> <i32 4, i32 0, i32 6, i32 3>
54 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
56 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v1, i8 21)
61 ; The zero mask overrides the insertion lane.
63 define <4 x float> @insertps_0x1a_single_input(<4 x float> %v1) {
64 ; CHECK-LABEL: @insertps_0x1a_single_input(
65 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> <float undef, float 0.000000e+00, float undef, float 0.000000e+00>, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
66 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
68 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v1, i8 26)
73 ; The zero mask overrides the insertion lane, so the second input vector is not used.
75 define <4 x float> @insertps_0xc1(<4 x float> %v1, <4 x float> %v2) {
76 ; CHECK-LABEL: @insertps_0xc1(
77 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> %v1, float 0.000000e+00, i32 0
78 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
80 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 193)
85 ; If no zero mask bits are set, convert to a shuffle.
87 define <4 x float> @insertps_0x00(<4 x float> %v1, <4 x float> %v2) {
88 ; CHECK-LABEL: @insertps_0x00(
89 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 4, i32 1, i32 2, i32 3>
90 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
92 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 0)
97 define <4 x float> @insertps_0x10(<4 x float> %v1, <4 x float> %v2) {
98 ; CHECK-LABEL: @insertps_0x10(
99 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 4, i32 2, i32 3>
100 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
102 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 16)
107 define <4 x float> @insertps_0x20(<4 x float> %v1, <4 x float> %v2) {
108 ; CHECK-LABEL: @insertps_0x20(
109 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 4, i32 3>
110 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
112 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 32)
117 define <4 x float> @insertps_0x30(<4 x float> %v1, <4 x float> %v2) {
118 ; CHECK-LABEL: @insertps_0x30(
119 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 2, i32 4>
120 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
122 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 48)
127 define <4 x float> @insertps_0xc0(<4 x float> %v1, <4 x float> %v2) {
128 ; CHECK-LABEL: @insertps_0xc0(
129 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 7, i32 1, i32 2, i32 3>
130 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
132 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 192)
137 define <4 x float> @insertps_0xd0(<4 x float> %v1, <4 x float> %v2) {
138 ; CHECK-LABEL: @insertps_0xd0(
139 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 7, i32 2, i32 3>
140 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
142 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 208)
147 define <4 x float> @insertps_0xe0(<4 x float> %v1, <4 x float> %v2) {
148 ; CHECK-LABEL: @insertps_0xe0(
149 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 7, i32 3>
150 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
152 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 224)
157 define <4 x float> @insertps_0xf0(<4 x float> %v1, <4 x float> %v2) {
158 ; CHECK-LABEL: @insertps_0xf0(
159 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
160 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
162 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 240)