From 84b3f53bcb753d886663dfda1423325bf4056720 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 2 Oct 2014 07:42:58 +0000 Subject: [PATCH] [x86] Merge the second set of vector combining tests into a common test file. Some of these really don't make sense to test -- we're testing for the *lack* of combining two shuffles into one, presumably because the two would generate better shuffles in the end. But if you look at the generated code shown here, in many cases the generated code is, frankly, terrible. Or we combine any two generated shuffles back into a single instruction! I've left a FIXME to revisit these decisions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218859 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/X86/combine-vec-shuffle-2.ll | 317 ------------- test/CodeGen/X86/vector-shuffle-combining.ll | 470 +++++++++++++++++++ 2 files changed, 470 insertions(+), 317 deletions(-) delete mode 100644 test/CodeGen/X86/combine-vec-shuffle-2.ll diff --git a/test/CodeGen/X86/combine-vec-shuffle-2.ll b/test/CodeGen/X86/combine-vec-shuffle-2.ll deleted file mode 100644 index 872384ca0a1..00000000000 --- a/test/CodeGen/X86/combine-vec-shuffle-2.ll +++ /dev/null @@ -1,317 +0,0 @@ -; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 | FileCheck %s - -; Check that DAGCombiner correctly folds the following pairs of shuffles -; using the following rules: -; 1. shuffle(shuffle(x, y), undef) -> x -; 2. shuffle(shuffle(x, y), undef) -> y -; 3. shuffle(shuffle(x, y), undef) -> shuffle(x, undef) -; 4. shuffle(shuffle(x, y), undef) -> shuffle(undef, y) -; -; Rules 3. and 4. are used only if the resulting shuffle mask is legal. - -define <4 x i32> @test1(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test1 -; Mask: [3,0,0,1] -; CHECK: pshufd $67 -; CHECK-NEXT: ret - - -define <4 x i32> @test2(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test2 -; Mask: [2,0,0,3] -; CHECK: pshufd $-62 -; CHECK-NEXT: ret - - -define <4 x i32> @test3(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test3 -; Mask: [2,0,0,3] -; CHECK: pshufd $-62 -; CHECK-NEXT: ret - - -define <4 x i32> @test4(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test4 -; Mask: [0,0,0,1] -; CHECK: pshufd $64 -; CHECK-NEXT: ret - - -define <4 x i32> @test5(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test5 -; Mask: [1,1] -; CHECK: movhlps -; CHECK-NEXT: ret - - -define <4 x i32> @test6(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test6 -; Mask: [2,0,0,0] -; CHECK: pshufd $2 -; CHECK-NEXT: ret - - -define <4 x i32> @test7(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test7 -; Mask: [0,2,0,2] -; CHECK: pshufd $-120 -; CHECK-NEXT: ret - - -define <4 x i32> @test8(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test8 -; Mask: [1,0,3,0] -; CHECK: pshufd $49 -; CHECK-NEXT: ret - - -define <4 x i32> @test9(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test9 -; Mask: [1,3,0,2] -; CHECK: pshufd $-115 -; CHECK-NEXT: ret - - -define <4 x i32> @test10(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test10 -; Mask: [1,0,1,0] -; CHECK: pshufd $17 -; CHECK-NEXT: ret - - -define <4 x i32> @test11(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test11 -; Mask: [1,0,2,1] -; CHECK: pshufd $97 -; CHECK-NEXT: ret - - -define <4 x i32> @test12(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test12 -; Mask: [0,0,0,0] -; CHECK: pshufd $0 -; CHECK-NEXT: ret - - -; The following pair of shuffles is folded into vector %A. -define <4 x i32> @test13(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test13 -; CHECK-NOT: pshufd -; CHECK: ret - - -; The following pair of shuffles is folded into vector %B. -define <4 x i32> @test14(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test14 -; CHECK-NOT: pshufd -; CHECK: ret - - -; Verify that we don't optimize the following cases. We expect more than one shuffle. - -define <4 x i32> @test15(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test15 -; CHECK: shufps $114 -; CHECK-NEXT: pshufd $-58 -; CHECK-NEXT: ret - - -define <4 x i32> @test16(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test16 -; CHECK: blendps $10 -; CHECK-NEXT: pshufd $-58 -; CHECK-NEXT: ret - - -define <4 x i32> @test17(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test17 -; CHECK: shufps $120 -; CHECK-NEXT: pshufd $-58 -; CHECK-NEXT: ret - - -define <4 x i32> @test18(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test18 -; CHECK-NOT: blendps -; CHECK: pshufd {{.*}} # xmm0 = xmm1[1,1,0,3] -; CHECK-NEXT: ret - -define <4 x i32> @test19(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test19 -; CHECK: shufps $-104 -; CHECK-NEXT: pshufd $2 -; CHECK-NEXT: ret - - -define <4 x i32> @test20(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test20 -; CHECK: shufps $11 -; CHECK-NEXT: pshufd $-58 -; CHECK-NEXT: ret - - -define <4 x i32> @test21(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test21 -; CHECK: shufps $120 -; CHECK-NEXT: pshufd $-60 -; CHECK-NEXT: ret - -; Test that we correctly combine shuffles according to rule -; shuffle(shuffle(x, y), undef) -> shuffle(y, undef) - -define <4 x i32> @test22(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test22 -; CHECK-NOT: blendps -; CHECK: pshufd {{.*}} # xmm0 = xmm1[1,1,1,3] -; CHECK-NEXT: ret - -define <4 x i32> @test23(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test23 -; CHECK-NOT: blendps -; CHECK: pshufd {{.*}} # xmm0 = xmm1[0,1,0,3] -; CHECK-NEXT: ret - -define <4 x i32> @test24(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test24 -; CHECK-NOT: blendps -; CHECK: pshufd {{.*}} # xmm0 = xmm1[0,3,2,0] -; CHECK-NEXT: ret - -define <4 x i32> @test25(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test25 -; CHECK-NOT: shufps -; CHECK: pshufd {{.*}} # xmm0 = xmm0[0,1,0,1] -; CHECK-NEXT: ret - -define <4 x i32> @test26(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test26 -; CHECK-NOT: shufps -; CHECK: movhlps {{.*}} # xmm0 = xmm0[1,1] -; CHECK-NEXT: ret - -define <4 x i32> @test27(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test27 -; CHECK-NOT: shufps -; CHECK-NOT: movhlps -; CHECK: pshufd {{.*}} # xmm0 = xmm0[0,1,0,1] -; CHECK-NEXT: ret - -define <4 x i32> @test28(<4 x i32> %A, <4 x i32> %B) { - %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> - %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> - ret <4 x i32> %2 -} -; CHECK-LABEL: test28 -; CHECK-NOT: shufps -; CHECK-NOT: movhlps -; CHECK: pshufd {{.*}} # xmm0 = xmm0[0,1,1,0] -; CHECK-NEXT: ret - diff --git a/test/CodeGen/X86/vector-shuffle-combining.ll b/test/CodeGen/X86/vector-shuffle-combining.ll index 7255d8f7bc7..d8e6cf2b8c1 100644 --- a/test/CodeGen/X86/vector-shuffle-combining.ll +++ b/test/CodeGen/X86/vector-shuffle-combining.ll @@ -627,3 +627,473 @@ define <4 x i32> @combine_bitwise_ops_test6c(<4 x i32> %a, <4 x i32> %b, <4 x i3 %xor = xor <4 x i32> %shuf1, %shuf2 ret <4 x i32> %xor } + +define <4 x i32> @combine_nested_undef_test1(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test1: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,0,0,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test1: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[3,0,0,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test2(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test2: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,0,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test2: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,0,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test3(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test3: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,0,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test3: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,0,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test4(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test4: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,0,0,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test4: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,0,0,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test5(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test5: +; SSE: # BB#0: +; SSE-NEXT: movhlps {{.*#+}} xmm0 = xmm0[1,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test5: +; AVX: # BB#0: +; AVX-NEXT: vmovhlps {{.*#+}} xmm0 = xmm0[1,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test6(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test6: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,0,0,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test6: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,0,0,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test7(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test7: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,0,2] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test7: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,2,0,2] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test8(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test8: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,0,3,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test8: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[1,0,3,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test9(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test9: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,3,0,2] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test9: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[1,3,0,2] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test10(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test10: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,0,1,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test10: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[1,0,1,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test11(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test11: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,0,2,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test11: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[1,0,2,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test12(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test12: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,0,0,0] +; SSE-NEXT: retq +; +; AVX1-LABEL: combine_nested_undef_test12: +; AVX1: # BB#0: +; AVX1-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,0,0,0] +; AVX1-NEXT: retq +; +; AVX2-LABEL: combine_nested_undef_test12: +; AVX2: # BB#0: +; AVX2-NEXT: vbroadcastss %xmm0, %xmm0 +; AVX2-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +; The following pair of shuffles is folded into vector %A. +define <4 x i32> @combine_nested_undef_test13(<4 x i32> %A, <4 x i32> %B) { +; ALL-LABEL: combine_nested_undef_test13: +; ALL: # BB#0: +; ALL-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +; The following pair of shuffles is folded into vector %B. +define <4 x i32> @combine_nested_undef_test14(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test14: +; SSE: # BB#0: +; SSE-NEXT: movaps %xmm1, %xmm0 +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test14: +; AVX: # BB#0: +; AVX-NEXT: vmovaps %xmm1, %xmm0 +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + + +; Verify that we don't optimize the following cases. We expect more than one shuffle. +; +; FIXME: Many of these already don't make sense, and the rest should stop +; making sense with th enew vector shuffle lowering. Revisit at least testing for +; it. + +define <4 x i32> @combine_nested_undef_test15(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test15: +; SSE: # BB#0: +; SSE-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0] +; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,0],xmm0[3,1] +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[2,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test15: +; AVX: # BB#0: +; AVX-NEXT: vmovlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0] +; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[2,0],xmm0[3,1] +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test16(<4 x i32> %A, <4 x i32> %B) { +; SSE2-LABEL: combine_nested_undef_test16: +; SSE2: # BB#0: +; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,3] +; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,2,0,3] +; SSE2-NEXT: retq +; +; SSSE3-LABEL: combine_nested_undef_test16: +; SSSE3: # BB#0: +; SSSE3-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,3] +; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,2,0,3] +; SSSE3-NEXT: retq +; +; SSE41-LABEL: combine_nested_undef_test16: +; SSE41: # BB#0: +; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3] +; SSE41-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; SSE41-NEXT: retq +; +; AVX1-LABEL: combine_nested_undef_test16: +; AVX1: # BB#0: +; AVX1-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3] +; AVX1-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; AVX1-NEXT: retq +; +; AVX2-LABEL: combine_nested_undef_test16: +; AVX2: # BB#0: +; AVX2-NEXT: vpblendd {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3] +; AVX2-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; AVX2-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test17(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test17: +; SSE: # BB#0: +; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[1,0] +; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,2],xmm0[3,1] +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[2,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test17: +; AVX: # BB#0: +; AVX-NEXT: vshufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[1,0] +; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,2],xmm0[3,1] +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test18(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test18: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[1,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test18: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm1[1,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test19(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test19: +; SSE: # BB#0: +; SSE-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0] +; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,2] +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,0,0,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test19: +; AVX: # BB#0: +; AVX-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0] +; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,2] +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,0,0,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test20(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test20: +; SSE: # BB#0: +; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[3,2],xmm1[0,0] +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test20: +; AVX: # BB#0: +; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm0[3,2],xmm1[0,0] +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test21(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test21: +; SSE: # BB#0: +; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[1,0] +; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,2],xmm0[3,1] +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[0,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test21: +; AVX: # BB#0: +; AVX-NEXT: vshufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[1,0] +; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,2],xmm0[3,1] +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + + +; Test that we correctly combine shuffles according to rule +; shuffle(shuffle(x, y), undef) -> shuffle(y, undef) + +define <4 x i32> @combine_nested_undef_test22(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test22: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[1,1,1,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test22: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm1[1,1,1,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test23(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test23: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[0,1,0,3] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test23: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm1[0,1,0,3] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test24(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test24: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[0,3,2,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test24: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm1[0,3,2,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test25(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test25: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test25: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test26(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test26: +; SSE: # BB#0: +; SSE-NEXT: movhlps {{.*#+}} xmm0 = xmm0[1,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test26: +; AVX: # BB#0: +; AVX-NEXT: vmovhlps {{.*#+}} xmm0 = xmm0[1,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test27(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test27: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test27: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} + +define <4 x i32> @combine_nested_undef_test28(<4 x i32> %A, <4 x i32> %B) { +; SSE-LABEL: combine_nested_undef_test28: +; SSE: # BB#0: +; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,1,0] +; SSE-NEXT: retq +; +; AVX-LABEL: combine_nested_undef_test28: +; AVX: # BB#0: +; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,1,0] +; AVX-NEXT: retq + %1 = shufflevector <4 x i32> %B, <4 x i32> %A, <4 x i32> + %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> + ret <4 x i32> %2 +} -- 2.34.1