[X86, SSE] instcombine common cases of insertps intrinsics into shuffles
[oota-llvm.git] / test / Transforms / InstCombine / x86-insertps.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
3 declare <4 x float> @llvm.x86.sse41.insertps(<4 x float>, <4 x float>, i8) nounwind readnone
4
5 ; This should never happen, but make sure we don't crash handling a non-constant immediate byte.
6
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)
9   ret <4 x float> %res
10
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>
14 }
15
16 ; If all zero mask bits are set, return a zero regardless of the other control bits.
17
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)
20   ret <4 x float> %res
21
22 ; CHECK-LABEL: @insertps_0x0f
23 ; CHECK-NEXT:  ret <4 x float> zeroinitializer
24 }
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)
27   ret <4 x float> %res
28
29 ; CHECK-LABEL: @insertps_0xff
30 ; CHECK-NEXT:  ret <4 x float> zeroinitializer
31 }
32
33 ; If some zero mask bits are set, we do not change anything.
34
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)
37   ret <4 x float> %res
38
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>
42 }
43
44 ; If no zero mask bits are set, convert to a shuffle.
45
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)
48   ret <4 x float> %res
49
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>
53 }
54
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)
57   ret <4 x float> %res
58
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>
62 }
63
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)
66   ret <4 x float> %res
67
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>
71 }
72
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)
75   ret <4 x float> %res
76
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>
80 }
81
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)
84   ret <4 x float> %res
85
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>
89 }
90
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)
93   ret <4 x float> %res
94
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>
98 }
99
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)
102   ret <4 x float> %res
103
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>
107 }
108
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)
111   ret <4 x float> %res
112
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>
116 }
117