1; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+sse2,-sse4.1 < %s | FileCheck %s 2 3; Verify that we don't emit packed vector shifts instructions if the 4; condition used by the vector select is a vector of constants. 5 6define <4 x float> @test1(<4 x float> %a, <4 x float> %b) { 7; CHECK-LABEL: test1: 8; CHECK: # BB#0: 9; CHECK-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,3] 10; CHECK-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2,1,3] 11; CHECK-NEXT: retq 12 %1 = select <4 x i1> <i1 true, i1 false, i1 true, i1 false>, <4 x float> %a, <4 x float> %b 13 ret <4 x float> %1 14} 15 16define <4 x float> @test2(<4 x float> %a, <4 x float> %b) { 17; CHECK-LABEL: test2: 18; CHECK: # BB#0: 19; CHECK-NEXT: movsd {{.*#+}} xmm1 = xmm0[0],xmm1[1] 20; CHECK-NEXT: movapd %xmm1, %xmm0 21; CHECK-NEXT: retq 22 %1 = select <4 x i1> <i1 true, i1 true, i1 false, i1 false>, <4 x float> %a, <4 x float> %b 23 ret <4 x float> %1 24} 25 26define <4 x float> @test3(<4 x float> %a, <4 x float> %b) { 27; CHECK-LABEL: test3: 28; CHECK: # BB#0: 29; CHECK-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1] 30; CHECK-NEXT: retq 31 %1 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %a, <4 x float> %b 32 ret <4 x float> %1 33} 34 35define <4 x float> @test4(<4 x float> %a, <4 x float> %b) { 36; CHECK-LABEL: test4: 37; CHECK: # BB#0: 38; CHECK-NEXT: movaps %xmm1, %xmm0 39; CHECK-NEXT: retq 40 %1 = select <4 x i1> <i1 false, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b 41 ret <4 x float> %1 42} 43 44define <4 x float> @test5(<4 x float> %a, <4 x float> %b) { 45; CHECK-LABEL: test5: 46; CHECK: # BB#0: 47; CHECK-NEXT: retq 48 %1 = select <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b 49 ret <4 x float> %1 50} 51 52define <8 x i16> @test6(<8 x i16> %a, <8 x i16> %b) { 53; CHECK-LABEL: test6: 54; CHECK: # BB#0: 55; CHECK-NEXT: retq 56 %1 = select <8 x i1> <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>, <8 x i16> %a, <8 x i16> %a 57 ret <8 x i16> %1 58} 59 60define <8 x i16> @test7(<8 x i16> %a, <8 x i16> %b) { 61; CHECK-LABEL: test7: 62; CHECK: # BB#0: 63; CHECK-NEXT: movsd {{.*#+}} xmm1 = xmm0[0],xmm1[1] 64; CHECK-NEXT: movapd %xmm1, %xmm0 65; CHECK-NEXT: retq 66 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b 67 ret <8 x i16> %1 68} 69 70define <8 x i16> @test8(<8 x i16> %a, <8 x i16> %b) { 71; CHECK-LABEL: test8: 72; CHECK: # BB#0: 73; CHECK-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1] 74; CHECK-NEXT: retq 75 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b 76 ret <8 x i16> %1 77} 78 79define <8 x i16> @test9(<8 x i16> %a, <8 x i16> %b) { 80; CHECK-LABEL: test9: 81; CHECK: # BB#0: 82; CHECK-NEXT: movaps %xmm1, %xmm0 83; CHECK-NEXT: retq 84 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b 85 ret <8 x i16> %1 86} 87 88define <8 x i16> @test10(<8 x i16> %a, <8 x i16> %b) { 89; CHECK-LABEL: test10: 90; CHECK: # BB#0: 91; CHECK-NEXT: retq 92 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b 93 ret <8 x i16> %1 94} 95 96define <8 x i16> @test11(<8 x i16> %a, <8 x i16> %b) { 97; CHECK-LABEL: test11: 98; CHECK: # BB#0: 99; CHECK-NEXT: movaps {{.*#+}} xmm2 = [0,65535,65535,0,65535,65535,65535,65535] 100; CHECK-NEXT: andps %xmm2, %xmm0 101; CHECK-NEXT: andnps %xmm1, %xmm2 102; CHECK-NEXT: orps %xmm2, %xmm0 103; CHECK-NEXT: retq 104 %1 = select <8 x i1> <i1 false, i1 true, i1 true, i1 false, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b 105 ret <8 x i16> %1 106} 107 108define <8 x i16> @test12(<8 x i16> %a, <8 x i16> %b) { 109; CHECK-LABEL: test12: 110; CHECK: # BB#0: 111; CHECK-NEXT: movaps %xmm1, %xmm0 112; CHECK-NEXT: retq 113 %1 = select <8 x i1> <i1 false, i1 false, i1 undef, i1 false, i1 false, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b 114 ret <8 x i16> %1 115} 116 117define <8 x i16> @test13(<8 x i16> %a, <8 x i16> %b) { 118; CHECK-LABEL: test13: 119; CHECK: # BB#0: 120; CHECK-NEXT: movaps %xmm1, %xmm0 121; CHECK-NEXT: retq 122 %1 = select <8 x i1> <i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef>, <8 x i16> %a, <8 x i16> %b 123 ret <8 x i16> %1 124} 125 126; Fold (vselect (build_vector AllOnes), N1, N2) -> N1 127define <4 x float> @test14(<4 x float> %a, <4 x float> %b) { 128; CHECK-LABEL: test14: 129; CHECK: # BB#0: 130; CHECK-NEXT: retq 131 %1 = select <4 x i1> <i1 true, i1 undef, i1 true, i1 undef>, <4 x float> %a, <4 x float> %b 132 ret <4 x float> %1 133} 134 135define <8 x i16> @test15(<8 x i16> %a, <8 x i16> %b) { 136; CHECK-LABEL: test15: 137; CHECK: # BB#0: 138; CHECK-NEXT: retq 139 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 undef, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b 140 ret <8 x i16> %1 141} 142 143; Fold (vselect (build_vector AllZeros), N1, N2) -> N2 144define <4 x float> @test16(<4 x float> %a, <4 x float> %b) { 145; CHECK-LABEL: test16: 146; CHECK: # BB#0: 147; CHECK-NEXT: movaps %xmm1, %xmm0 148; CHECK-NEXT: retq 149 %1 = select <4 x i1> <i1 false, i1 undef, i1 false, i1 undef>, <4 x float> %a, <4 x float> %b 150 ret <4 x float> %1 151} 152 153define <8 x i16> @test17(<8 x i16> %a, <8 x i16> %b) { 154; CHECK-LABEL: test17: 155; CHECK: # BB#0: 156; CHECK-NEXT: movaps %xmm1, %xmm0 157; CHECK-NEXT: retq 158 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 undef, i1 undef, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b 159 ret <8 x i16> %1 160} 161 162define <4 x float> @test18(<4 x float> %a, <4 x float> %b) { 163; CHECK-LABEL: test18: 164; CHECK: # BB#0: 165; CHECK-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3] 166; CHECK-NEXT: retq 167 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b 168 ret <4 x float> %1 169} 170 171define <4 x i32> @test19(<4 x i32> %a, <4 x i32> %b) { 172; CHECK-LABEL: test19: 173; CHECK: # BB#0: 174; CHECK-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3] 175; CHECK-NEXT: retq 176 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x i32> %a, <4 x i32> %b 177 ret <4 x i32> %1 178} 179 180define <2 x double> @test20(<2 x double> %a, <2 x double> %b) { 181; CHECK-LABEL: test20: 182; CHECK: # BB#0: 183; CHECK-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1] 184; CHECK-NEXT: retq 185 %1 = select <2 x i1> <i1 false, i1 true>, <2 x double> %a, <2 x double> %b 186 ret <2 x double> %1 187} 188 189define <2 x i64> @test21(<2 x i64> %a, <2 x i64> %b) { 190; CHECK-LABEL: test21: 191; CHECK: # BB#0: 192; CHECK-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1] 193; CHECK-NEXT: retq 194 %1 = select <2 x i1> <i1 false, i1 true>, <2 x i64> %a, <2 x i64> %b 195 ret <2 x i64> %1 196} 197 198define <4 x float> @test22(<4 x float> %a, <4 x float> %b) { 199; CHECK-LABEL: test22: 200; CHECK: # BB#0: 201; CHECK-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3] 202; CHECK-NEXT: movaps %xmm1, %xmm0 203; CHECK-NEXT: retq 204 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b 205 ret <4 x float> %1 206} 207 208define <4 x i32> @test23(<4 x i32> %a, <4 x i32> %b) { 209; CHECK-LABEL: test23: 210; CHECK: # BB#0: 211; CHECK-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3] 212; CHECK-NEXT: movaps %xmm1, %xmm0 213; CHECK-NEXT: retq 214 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x i32> %a, <4 x i32> %b 215 ret <4 x i32> %1 216} 217 218define <2 x double> @test24(<2 x double> %a, <2 x double> %b) { 219; CHECK-LABEL: test24: 220; CHECK: # BB#0: 221; CHECK-NEXT: movsd {{.*#+}} xmm1 = xmm0[0],xmm1[1] 222; CHECK-NEXT: movapd %xmm1, %xmm0 223; CHECK-NEXT: retq 224 %1 = select <2 x i1> <i1 true, i1 false>, <2 x double> %a, <2 x double> %b 225 ret <2 x double> %1 226} 227 228define <2 x i64> @test25(<2 x i64> %a, <2 x i64> %b) { 229; CHECK-LABEL: test25: 230; CHECK: # BB#0: 231; CHECK-NEXT: movsd {{.*#+}} xmm1 = xmm0[0],xmm1[1] 232; CHECK-NEXT: movapd %xmm1, %xmm0 233; CHECK-NEXT: retq 234 %1 = select <2 x i1> <i1 true, i1 false>, <2 x i64> %a, <2 x i64> %b 235 ret <2 x i64> %1 236} 237 238define <4 x float> @select_of_shuffles_0(<2 x float> %a0, <2 x float> %b0, <2 x float> %a1, <2 x float> %b1) { 239; CHECK-LABEL: select_of_shuffles_0: 240; CHECK: # BB#0: 241; CHECK-NEXT: unpcklpd {{.*#+}} xmm0 = xmm0[0],xmm2[0] 242; CHECK-NEXT: unpcklpd {{.*#+}} xmm1 = xmm1[0],xmm3[0] 243; CHECK-NEXT: subps %xmm1, %xmm0 244; CHECK-NEXT: retq 245 %1 = shufflevector <2 x float> %a0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef> 246 %2 = shufflevector <2 x float> %a1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1> 247 %3 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %2, <4 x float> %1 248 %4 = shufflevector <2 x float> %b0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef> 249 %5 = shufflevector <2 x float> %b1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1> 250 %6 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %5, <4 x float> %4 251 %7 = fsub <4 x float> %3, %6 252 ret <4 x float> %7 253} 254 255; PR20677 256define <16 x double> @select_illegal(<16 x double> %a, <16 x double> %b) { 257; CHECK-LABEL: select_illegal: 258; CHECK: # BB#0: 259; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm4 260; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm5 261; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm6 262; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm7 263; CHECK-NEXT: movaps %xmm7, 112(%rdi) 264; CHECK-NEXT: movaps %xmm6, 96(%rdi) 265; CHECK-NEXT: movaps %xmm5, 80(%rdi) 266; CHECK-NEXT: movaps %xmm4, 64(%rdi) 267; CHECK-NEXT: movaps %xmm3, 48(%rdi) 268; CHECK-NEXT: movaps %xmm2, 32(%rdi) 269; CHECK-NEXT: movaps %xmm1, 16(%rdi) 270; CHECK-NEXT: movaps %xmm0, (%rdi) 271; CHECK-NEXT: movq %rdi, %rax 272; CHECK-NEXT: retq 273 %sel = select <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <16 x double> %a, <16 x double> %b 274 ret <16 x double> %sel 275} 276