diff options
author | Michael Kuperstein <mkuper@google.com> | 2016-12-28 00:18:08 +0000 |
---|---|---|
committer | Michael Kuperstein <mkuper@google.com> | 2016-12-28 00:18:08 +0000 |
commit | 04912c82259bc53062cc23d241a011afd2f9b3d3 (patch) | |
tree | 2fd501939f5b3c1ccd16a3e8218e48e232dcbb12 /test | |
parent | d31ce373a9d586c3f88f9c7b3b00970b8fb67dc3 (diff) |
[InstCombine] Canonicalize insert splat sequences into an insert + shuffle
This adds a combine that canonicalizes a chain of inserts which broadcasts
a value into a single insert + a splat shufflevector.
This fixes PR31286.
Differential Revision: https://reviews.llvm.org/D27992
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Transforms/BBVectorize/X86/loop1.ll | 2 | ||||
-rw-r--r-- | test/Transforms/BBVectorize/loop1.ll | 6 | ||||
-rw-r--r-- | test/Transforms/BBVectorize/simple-int.ll | 2 | ||||
-rw-r--r-- | test/Transforms/InstCombine/broadcast.ll | 109 | ||||
-rw-r--r-- | test/Transforms/SLPVectorizer/X86/operandorder.ll | 12 |
5 files changed, 120 insertions, 11 deletions
diff --git a/test/Transforms/BBVectorize/X86/loop1.ll b/test/Transforms/BBVectorize/X86/loop1.ll index c3c30454ce3..551fbd73eb2 100644 --- a/test/Transforms/BBVectorize/X86/loop1.ll +++ b/test/Transforms/BBVectorize/X86/loop1.ll @@ -38,7 +38,7 @@ for.body: ; preds = %for.body, %entry ; CHECK-NEXT: insertelement ; CHECK-NEXT: fadd <2 x double> ; CHECK-NEXT: insertelement -; CHECK-NEXT: insertelement +; CHECK-NEXT: shufflevector ; CHECK-NEXT: fadd <2 x double> ; CHECK-NEXT: insertelement ; CHECK-NEXT: fmul <2 x double> diff --git a/test/Transforms/BBVectorize/loop1.ll b/test/Transforms/BBVectorize/loop1.ll index 0a0a6629897..7e7b603116f 100644 --- a/test/Transforms/BBVectorize/loop1.ll +++ b/test/Transforms/BBVectorize/loop1.ll @@ -46,10 +46,10 @@ for.body: ; preds = %for.body, %entry ; CHECK: %add4.v.i1.1 = insertelement <2 x double> undef, double %1, i32 0 ; CHECK: %add4.v.i1.2 = insertelement <2 x double> %add4.v.i1.1, double %0, i32 1 ; CHECK: %add4 = fadd <2 x double> %add4.v.i1.2, %add4.v.i1.2 -; CHECK: %add5.v.i1.1 = insertelement <2 x double> undef, double %0, i32 0 -; CHECK: %add5.v.i1.2 = insertelement <2 x double> %add5.v.i1.1, double %0, i32 1 +; CHECK: %2 = insertelement <2 x double> undef, double %0, i32 0 +; CHECK: %add5.v.i1.2 = shufflevector <2 x double> %2, <2 x double> undef, <2 x i32> zeroinitializer ; CHECK: %add5 = fadd <2 x double> %add4, %add5.v.i1.2 -; CHECK: %mul6.v.i0.2 = insertelement <2 x double> %add5.v.i1.1, double %mul8, i32 1 +; CHECK: %mul6.v.i0.2 = insertelement <2 x double> %2, double %mul8, i32 1 ; CHECK: %mul6 = fmul <2 x double> %mul6.v.i0.2, %add5 ; CHECK: %mul6.v.r1 = extractelement <2 x double> %mul6, i32 0 ; CHECK: %mul6.v.r2 = extractelement <2 x double> %mul6, i32 1 diff --git a/test/Transforms/BBVectorize/simple-int.ll b/test/Transforms/BBVectorize/simple-int.ll index e0c1efa5b97..6b50e2b4f2f 100644 --- a/test/Transforms/BBVectorize/simple-int.ll +++ b/test/Transforms/BBVectorize/simple-int.ll @@ -177,7 +177,7 @@ define double @testcopysign(double %A1, double %A2, double %B1, double %B2) { ; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0 ; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1 ; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2 -; CHECK: %Y1.v.i1.2 = insertelement <2 x double> %X1.v.i0.1, double %A1, i32 1 +; CHECK: %Y1.v.i1.2 = shufflevector <2 x double> %X1.v.i0.1, <2 x double> undef, <2 x i32> zeroinitializer ; CHECK: %Y1 = call <2 x double> @llvm.copysign.v2f64(<2 x double> %X1, <2 x double> %Y1.v.i1.2) ; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2 ; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0 diff --git a/test/Transforms/InstCombine/broadcast.ll b/test/Transforms/InstCombine/broadcast.ll new file mode 100644 index 00000000000..d852e2970fc --- /dev/null +++ b/test/Transforms/InstCombine/broadcast.ll @@ -0,0 +1,109 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -instcombine -S < %s | FileCheck %s + +; CHECK-LABEL: good1 +; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 +; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: ret <4 x float> %[[BCAST]] +define <4 x float> @good1(float %arg) { + %tmp = insertelement <4 x float> undef, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: good2 +; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 +; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: ret <4 x float> %[[BCAST]] +define <4 x float> @good2(float %arg) { + %tmp = insertelement <4 x float> undef, float %arg, i32 1 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 2 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 0 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: good3 +; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 +; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: ret <4 x float> %[[BCAST]] +define <4 x float> @good3(float %arg) { + %tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: good4 +; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 +; CHECK-NEXT: %[[ADD:.*]] = fadd <4 x float> %[[INS]], %[[INS]] +; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[ADD]], <4 x float> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: ret <4 x float> %[[BCAST]] +define <4 x float> @good4(float %arg) { + %tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + %tmp7 = fadd <4 x float> %tmp6, %tmp6 + ret <4 x float> %tmp7 +} + +; CHECK-LABEL: bad1 +; CHECK-NOT: shufflevector +define <4 x float> @bad1(float %arg) { + %tmp = insertelement <4 x float> undef, float %arg, i32 1 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: bad2 +; CHECK-NOT: shufflevector +define <4 x float> @bad2(float %arg) { + %tmp = insertelement <4 x float> undef, float %arg, i32 0 + %tmp5 = insertelement <4 x float> %tmp, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: bad3 +; CHECK-NOT: shufflevector +define <4 x float> @bad3(float %arg, float %arg2) { + %tmp = insertelement <4 x float> undef, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg2, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} + +; CHECK-LABEL: bad4 +; CHECK-NOT: shufflevector +define <1 x float> @bad4(float %arg) { + %tmp = insertelement <1 x float> undef, float %arg, i32 0 + ret <1 x float> %tmp +} + +; CHECK-LABEL: bad5 +; CHECK-NOT: shufflevector +define <4 x float> @bad5(float %arg) { + %tmp = insertelement <4 x float> undef, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + %tmp7 = fadd <4 x float> %tmp6, %tmp4 + ret <4 x float> %tmp7 +} + +; CHECK-LABEL: bad6 +; CHECK-NOT: shufflevector +define <4 x float> @bad6(float %arg, i32 %k) { + %tmp = insertelement <4 x float> undef, float %arg, i32 0 + %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 + %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 %k + %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 + ret <4 x float> %tmp6 +} diff --git a/test/Transforms/SLPVectorizer/X86/operandorder.ll b/test/Transforms/SLPVectorizer/X86/operandorder.ll index 109540bc769..dab7f296e20 100644 --- a/test/Transforms/SLPVectorizer/X86/operandorder.ll +++ b/test/Transforms/SLPVectorizer/X86/operandorder.ll @@ -26,7 +26,7 @@ define void @shuffle_operands1(double * noalias %from, double * noalias %to, ; CHECK-LABEL: shuffle_preserve_broadcast ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast(double * noalias %from, double * noalias %to, double %v1, double %v2) { @@ -51,7 +51,7 @@ ext: ; CHECK-LABEL: shuffle_preserve_broadcast2 ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast2(double * noalias %from, double * noalias %to, double %v1, double %v2) { @@ -76,7 +76,7 @@ ext: ; CHECK-LABEL: shuffle_preserve_broadcast3 ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast3(double * noalias %from, double * noalias %to, double %v1, double %v2) { @@ -102,7 +102,7 @@ ext: ; CHECK-LABEL: shuffle_preserve_broadcast4 ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast4(double * noalias %from, double * noalias %to, double %v1, double %v2) { @@ -127,7 +127,7 @@ ext: ; CHECK-LABEL: shuffle_preserve_broadcast5 ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast5(double * noalias %from, double * noalias %to, double %v1, double %v2) { @@ -153,7 +153,7 @@ ext: ; CHECK-LABEL: shuffle_preserve_broadcast6 ; CHECK: %[[BCAST:[a-z0-9]+]] = insertelement <2 x double> undef, double %v0_1 -; CHECK: = insertelement <2 x double> %[[BCAST]], double %v0_1 +; CHECK: = shufflevector <2 x double> %[[BCAST]], <2 x double> undef, <2 x i32> zeroinitializer define void @shuffle_preserve_broadcast6(double * noalias %from, double * noalias %to, double %v1, double %v2) { |