1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 declare <4 x float> @llvm.x86.sse41.insertps(<4 x float>, <4 x float>, i8) nounwind readnone
5 ; This should never happen, but make sure we don't crash handling a non-constant immediate byte.
7 define <4 x float> @insertps_non_const_imm(<4 x float> %v1, <4 x float> %v2, i8 %c) {
8 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 %c)
11 ; CHECK-LABEL: @insertps_non_const_imm
12 ; CHECK-NEXT: call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 %c)
13 ; CHECK-NEXT: ret <4 x float>
16 ; If all zero mask bits are set, return a zero regardless of the other control bits.
18 define <4 x float> @insertps_0x0f(<4 x float> %v1, <4 x float> %v2) {
19 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 15)
22 ; CHECK-LABEL: @insertps_0x0f
23 ; CHECK-NEXT: ret <4 x float> zeroinitializer
25 define <4 x float> @insertps_0xff(<4 x float> %v1, <4 x float> %v2) {
26 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 255)
29 ; CHECK-LABEL: @insertps_0xff
30 ; CHECK-NEXT: ret <4 x float> zeroinitializer
33 ; If some zero mask bits are set, we do not change anything.
35 define <4 x float> @insertps_0x03(<4 x float> %v1, <4 x float> %v2) {
36 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 3)
39 ; CHECK-LABEL: @insertps_0x03
40 ; CHECK-NEXT: call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 3)
41 ; CHECK-NEXT: ret <4 x float>
44 ; If no zero mask bits are set, convert to a shuffle.
46 define <4 x float> @insertps_0x00(<4 x float> %v1, <4 x float> %v2) {
47 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 0)
50 ; CHECK-LABEL: @insertps_0x00
51 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 4, i32 1, i32 2, i32 3>
52 ; CHECK-NEXT: ret <4 x float>
55 define <4 x float> @insertps_0x10(<4 x float> %v1, <4 x float> %v2) {
56 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 16)
59 ; CHECK-LABEL: @insertps_0x10
60 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 4, i32 2, i32 3>
61 ; CHECK-NEXT: ret <4 x float>
64 define <4 x float> @insertps_0x20(<4 x float> %v1, <4 x float> %v2) {
65 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 32)
68 ; CHECK-LABEL: @insertps_0x20
69 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 4, i32 3>
70 ; CHECK-NEXT: ret <4 x float>
73 define <4 x float> @insertps_0x30(<4 x float> %v1, <4 x float> %v2) {
74 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 48)
77 ; CHECK-LABEL: @insertps_0x30
78 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 2, i32 4>
79 ; CHECK-NEXT: ret <4 x float>
82 define <4 x float> @insertps_0xc0(<4 x float> %v1, <4 x float> %v2) {
83 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 192)
86 ; CHECK-LABEL: @insertps_0xc0
87 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 7, i32 1, i32 2, i32 3>
88 ; CHECK-NEXT: ret <4 x float>
91 define <4 x float> @insertps_0xd0(<4 x float> %v1, <4 x float> %v2) {
92 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 208)
95 ; CHECK-LABEL: @insertps_0xd0
96 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 7, i32 2, i32 3>
97 ; CHECK-NEXT: ret <4 x float>
100 define <4 x float> @insertps_0xe0(<4 x float> %v1, <4 x float> %v2) {
101 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 224)
104 ; CHECK-LABEL: @insertps_0xe0
105 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 7, i32 3>
106 ; CHECK-NEXT: ret <4 x float>
109 define <4 x float> @insertps_0xf0(<4 x float> %v1, <4 x float> %v2) {
110 %res = call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %v1, <4 x float> %v2, i8 240)
113 ; CHECK-LABEL: @insertps_0xf0
114 ; CHECK-NEXT: shufflevector <4 x float> %v1, <4 x float> %v2, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
115 ; CHECK-NEXT: ret <4 x float>