Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=sse2 | FileCheck %s --check-prefix=ALL --check-prefix=SSEANY --check-prefix=SSE2 |
| 3 | ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=sse4.1 | FileCheck %s --check-prefix=ALL --check-prefix=SSEANY --check-prefix=SSE4 |
| 4 | ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx | FileCheck %s --check-prefix=ALL --check-prefix=AVX |
| 5 | |
| 6 | define <4 x i32> @ins_elt_0(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 7 | ; SSE2-LABEL: ins_elt_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 8 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 9 | ; SSE2-NEXT: movd %edi, %xmm0 |
| 10 | ; SSE2-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3] |
| 11 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 12 | ; SSE2-NEXT: retq |
| 13 | ; |
| 14 | ; SSE4-LABEL: ins_elt_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 15 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 16 | ; SSE4-NEXT: pinsrd $0, %edi, %xmm0 |
| 17 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7] |
| 18 | ; SSE4-NEXT: retq |
| 19 | ; |
| 20 | ; AVX-LABEL: ins_elt_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 21 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 22 | ; AVX-NEXT: vpinsrd $0, %edi, %xmm0, %xmm0 |
| 23 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7] |
| 24 | ; AVX-NEXT: retq |
| 25 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 0 |
| 26 | %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 0, i32 5, i32 6, i32 7> |
| 27 | ret <4 x i32> %shuf |
| 28 | } |
| 29 | |
| 30 | define <4 x i32> @ins_elt_1(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 31 | ; SSE2-LABEL: ins_elt_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 32 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 33 | ; SSE2-NEXT: movd %edi, %xmm2 |
| 34 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,0],xmm0[0,0] |
| 35 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,2],xmm1[0,0] |
| 36 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[2,0],xmm1[2,3] |
| 37 | ; SSE2-NEXT: movaps %xmm2, %xmm0 |
| 38 | ; SSE2-NEXT: retq |
| 39 | ; |
| 40 | ; SSE4-LABEL: ins_elt_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 41 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 42 | ; SSE4-NEXT: pinsrd $1, %edi, %xmm0 |
| 43 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5,6,7] |
| 44 | ; SSE4-NEXT: retq |
| 45 | ; |
| 46 | ; AVX-LABEL: ins_elt_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 47 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 48 | ; AVX-NEXT: vpinsrd $1, %edi, %xmm0, %xmm0 |
| 49 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5,6,7] |
| 50 | ; AVX-NEXT: retq |
| 51 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 1 |
| 52 | %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 4, i32 1, i32 6, i32 7> |
| 53 | ret <4 x i32> %shuf |
| 54 | } |
| 55 | |
| 56 | ; Verify that the transform still works when the insert element is the 2nd operand to the shuffle. |
| 57 | |
| 58 | define <4 x i32> @ins_elt_2_commute(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 59 | ; SSE2-LABEL: ins_elt_2_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 60 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 61 | ; SSE2-NEXT: movd %edi, %xmm2 |
| 62 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,0],xmm0[3,0] |
| 63 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm2[0,2] |
| 64 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[2,0],xmm1[3,0] |
| 65 | ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,1],xmm0[0,2] |
| 66 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 67 | ; SSE2-NEXT: retq |
| 68 | ; |
| 69 | ; SSE4-LABEL: ins_elt_2_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 70 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 71 | ; SSE4-NEXT: pinsrd $2, %edi, %xmm0 |
| 72 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5],xmm1[6,7] |
| 73 | ; SSE4-NEXT: retq |
| 74 | ; |
| 75 | ; AVX-LABEL: ins_elt_2_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 76 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 77 | ; AVX-NEXT: vpinsrd $2, %edi, %xmm0, %xmm0 |
| 78 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5],xmm1[6,7] |
| 79 | ; AVX-NEXT: retq |
| 80 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 2 |
| 81 | %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 6, i32 3> |
| 82 | ret <4 x i32> %shuf |
| 83 | } |
| 84 | |
| 85 | define <4 x i32> @ins_elt_3_commute(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 86 | ; SSE2-LABEL: ins_elt_3_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 87 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 88 | ; SSE2-NEXT: movd %edi, %xmm2 |
| 89 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,0],xmm0[2,0] |
| 90 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,0] |
| 91 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[3,0],xmm1[2,0] |
| 92 | ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,1],xmm0[2,0] |
| 93 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 94 | ; SSE2-NEXT: retq |
| 95 | ; |
| 96 | ; SSE4-LABEL: ins_elt_3_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 97 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 98 | ; SSE4-NEXT: pinsrd $3, %edi, %xmm0 |
| 99 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3,4,5],xmm0[6,7] |
| 100 | ; SSE4-NEXT: retq |
| 101 | ; |
| 102 | ; AVX-LABEL: ins_elt_3_commute: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 103 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 104 | ; AVX-NEXT: vpinsrd $3, %edi, %xmm0, %xmm0 |
| 105 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1,2,3,4,5],xmm0[6,7] |
| 106 | ; AVX-NEXT: retq |
| 107 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 3 |
| 108 | %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 2, i32 7> |
| 109 | ret <4 x i32> %shuf |
| 110 | } |
| 111 | |
| 112 | ; In the next 4 tests, the shuffle moves the inserted scalar to a different position in the output vector. |
| 113 | |
| 114 | define <4 x i32> @ins_elt_0_to_2(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 115 | ; SSE2-LABEL: ins_elt_0_to_2: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 116 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 117 | ; SSE2-NEXT: movd %edi, %xmm0 |
| 118 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,0],xmm1[3,0] |
| 119 | ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,1],xmm0[0,2] |
| 120 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 121 | ; SSE2-NEXT: retq |
| 122 | ; |
| 123 | ; SSE4-LABEL: ins_elt_0_to_2: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 124 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 125 | ; SSE4-NEXT: pinsrd $0, %edi, %xmm0 |
| 126 | ; SSE4-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] |
| 127 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5],xmm1[6,7] |
| 128 | ; SSE4-NEXT: retq |
| 129 | ; |
| 130 | ; AVX-LABEL: ins_elt_0_to_2: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 131 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 132 | ; AVX-NEXT: vpinsrd $0, %edi, %xmm0, %xmm0 |
| 133 | ; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] |
| 134 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5],xmm1[6,7] |
| 135 | ; AVX-NEXT: retq |
| 136 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 0 |
| 137 | %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 4, i32 5, i32 0, i32 7> |
| 138 | ret <4 x i32> %shuf |
| 139 | } |
| 140 | |
| 141 | define <4 x i32> @ins_elt_1_to_0(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 142 | ; SSE2-LABEL: ins_elt_1_to_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 143 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 144 | ; SSE2-NEXT: movd %edi, %xmm0 |
| 145 | ; SSE2-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3] |
| 146 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 147 | ; SSE2-NEXT: retq |
| 148 | ; |
| 149 | ; SSE4-LABEL: ins_elt_1_to_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 150 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 151 | ; SSE4-NEXT: pinsrd $1, %edi, %xmm0 |
| 152 | ; SSE4-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,2,3] |
| 153 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7] |
| 154 | ; SSE4-NEXT: retq |
| 155 | ; |
| 156 | ; AVX-LABEL: ins_elt_1_to_0: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 157 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 158 | ; AVX-NEXT: vpinsrd $1, %edi, %xmm0, %xmm0 |
| 159 | ; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[1,1,2,3] |
| 160 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7] |
| 161 | ; AVX-NEXT: retq |
| 162 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 1 |
| 163 | %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 1, i32 5, i32 6, i32 7> |
| 164 | ret <4 x i32> %shuf |
| 165 | } |
| 166 | |
| 167 | define <4 x i32> @ins_elt_2_to_3(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 168 | ; SSE2-LABEL: ins_elt_2_to_3: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 169 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 170 | ; SSE2-NEXT: movd %edi, %xmm2 |
| 171 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,0],xmm0[3,0] |
| 172 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm2[0,2] |
| 173 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[2,0],xmm1[2,0] |
| 174 | ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,1],xmm0[2,0] |
| 175 | ; SSE2-NEXT: movaps %xmm1, %xmm0 |
| 176 | ; SSE2-NEXT: retq |
| 177 | ; |
| 178 | ; SSE4-LABEL: ins_elt_2_to_3: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 179 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 180 | ; SSE4-NEXT: pinsrd $2, %edi, %xmm0 |
| 181 | ; SSE4-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,2,2] |
| 182 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3,4,5],xmm0[6,7] |
| 183 | ; SSE4-NEXT: retq |
| 184 | ; |
| 185 | ; AVX-LABEL: ins_elt_2_to_3: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 186 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 187 | ; AVX-NEXT: vpinsrd $2, %edi, %xmm0, %xmm0 |
| 188 | ; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,2,2] |
| 189 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1,2,3,4,5],xmm0[6,7] |
| 190 | ; AVX-NEXT: retq |
| 191 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 2 |
| 192 | %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 2, i32 6> |
| 193 | ret <4 x i32> %shuf |
| 194 | } |
| 195 | |
| 196 | define <4 x i32> @ins_elt_3_to_1(i32 %x, <4 x i32> %v1, <4 x i32> %v2) { |
| 197 | ; SSE2-LABEL: ins_elt_3_to_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 198 | ; SSE2: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 199 | ; SSE2-NEXT: movd %edi, %xmm2 |
| 200 | ; SSE2-NEXT: shufps {{.*#+}} xmm2 = xmm2[0,0],xmm0[2,0] |
| 201 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,0] |
| 202 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[3,0],xmm1[0,0] |
| 203 | ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[2,0],xmm1[2,3] |
| 204 | ; SSE2-NEXT: retq |
| 205 | ; |
| 206 | ; SSE4-LABEL: ins_elt_3_to_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 207 | ; SSE4: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 208 | ; SSE4-NEXT: pinsrd $3, %edi, %xmm0 |
| 209 | ; SSE4-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,3,0,1] |
| 210 | ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5,6,7] |
| 211 | ; SSE4-NEXT: retq |
| 212 | ; |
| 213 | ; AVX-LABEL: ins_elt_3_to_1: |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 214 | ; AVX: # %bb.0: |
Sanjay Patel | c0d1b2e | 2017-11-18 16:25:38 +0000 | [diff] [blame] | 215 | ; AVX-NEXT: vpinsrd $3, %edi, %xmm0, %xmm0 |
| 216 | ; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,3,0,1] |
| 217 | ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5,6,7] |
| 218 | ; AVX-NEXT: retq |
| 219 | %ins = insertelement <4 x i32> %v1, i32 %x, i32 3 |
| 220 | %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 7, i32 2, i32 3> |
| 221 | ret <4 x i32> %shuf |
| 222 | } |
| 223 | |