mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
SLPVectorizer: Bring back the insertelement patch (r205965) with fixes
When can't assume a vectorized tree is rooted in an instruction. The IRBuilder could have constant folded it. When we rebuild the build_vector (the series of InsertElement instructions) use the last original InsertElement instruction. The vectorized tree root is guaranteed to be before it. Also, we can't assume that the n-th InsertElement inserts the n-th element into a vector. This reverts r207746 which reverted the revert of the revert of r205018 or so. Fixes the test case in PR19621. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207939 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -195,6 +195,30 @@ define <4 x float> @simple_select_partial_vector(<4 x float> %a, <4 x float> %b,
|
||||
ret <4 x float> %rb
|
||||
}
|
||||
|
||||
; Make sure that vectorization happens even if insertelements operations
|
||||
; must be rescheduled. The case here is from compiling Julia.
|
||||
define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) {
|
||||
; CHECK-LABEL: @reschedule_extract(
|
||||
; CHECK: %1 = fadd <4 x float> %a, %b
|
||||
%a0 = extractelement <4 x float> %a, i32 0
|
||||
%b0 = extractelement <4 x float> %b, i32 0
|
||||
%c0 = fadd float %a0, %b0
|
||||
%v0 = insertelement <4 x float> undef, float %c0, i32 0
|
||||
%a1 = extractelement <4 x float> %a, i32 1
|
||||
%b1 = extractelement <4 x float> %b, i32 1
|
||||
%c1 = fadd float %a1, %b1
|
||||
%v1 = insertelement <4 x float> %v0, float %c1, i32 1
|
||||
%a2 = extractelement <4 x float> %a, i32 2
|
||||
%b2 = extractelement <4 x float> %b, i32 2
|
||||
%c2 = fadd float %a2, %b2
|
||||
%v2 = insertelement <4 x float> %v1, float %c2, i32 2
|
||||
%a3 = extractelement <4 x float> %a, i32 3
|
||||
%b3 = extractelement <4 x float> %b, i32 3
|
||||
%c3 = fadd float %a3, %b3
|
||||
%v3 = insertelement <4 x float> %v2, float %c3, i32 3
|
||||
ret <4 x float> %v3
|
||||
}
|
||||
|
||||
; Check that cost model for vectorization takes credit for
|
||||
; instructions that are erased.
|
||||
define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) {
|
||||
@@ -219,4 +243,40 @@ define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) {
|
||||
ret <4 x float> %v3
|
||||
}
|
||||
|
||||
; Make sure we handle multiple trees that feed one build vector correctly.
|
||||
define <4 x double> @multi_tree(double %w, double %x, double %y, double %z) {
|
||||
entry:
|
||||
%t0 = fadd double %w , 0.000000e+00
|
||||
%t1 = fadd double %x , 1.000000e+00
|
||||
%t2 = fadd double %y , 2.000000e+00
|
||||
%t3 = fadd double %z , 3.000000e+00
|
||||
%t4 = fmul double %t0, 1.000000e+00
|
||||
%i1 = insertelement <4 x double> undef, double %t4, i32 3
|
||||
%t5 = fmul double %t1, 1.000000e+00
|
||||
%i2 = insertelement <4 x double> %i1, double %t5, i32 2
|
||||
%t6 = fmul double %t2, 1.000000e+00
|
||||
%i3 = insertelement <4 x double> %i2, double %t6, i32 1
|
||||
%t7 = fmul double %t3, 1.000000e+00
|
||||
%i4 = insertelement <4 x double> %i3, double %t7, i32 0
|
||||
ret <4 x double> %i4
|
||||
}
|
||||
; CHECK-LABEL: @multi_tree
|
||||
; CHECK-DAG: %[[V0:.+]] = insertelement <2 x double> undef, double %w, i32 0
|
||||
; CHECK-DAG: %[[V1:.+]] = insertelement <2 x double> %[[V0]], double %x, i32 1
|
||||
; CHECK-DAG: %[[V2:.+]] = fadd <2 x double> %[[V1]], <double 0.000000e+00, double 1.000000e+00>
|
||||
; CHECK-DAG: %[[V3:.+]] = insertelement <2 x double> undef, double %y, i32 0
|
||||
; CHECK-DAG: %[[V4:.+]] = insertelement <2 x double> %[[V3]], double %z, i32 1
|
||||
; CHECK-DAG: %[[V5:.+]] = fadd <2 x double> %[[V4]], <double 2.000000e+00, double 3.000000e+00>
|
||||
; CHECK-DAG: %[[V6:.+]] = fmul <2 x double> <double 1.000000e+00, double 1.000000e+00>, %[[V2]]
|
||||
; CHECK-DAG: %[[V7:.+]] = extractelement <2 x double> %[[V6]], i32 0
|
||||
; CHECK-DAG: %[[I1:.+]] = insertelement <4 x double> undef, double %[[V7]], i32 3
|
||||
; CHECK-DAG: %[[V8:.+]] = extractelement <2 x double> %[[V6]], i32 1
|
||||
; CHECK-DAG: %[[I2:.+]] = insertelement <4 x double> %[[I1]], double %[[V8]], i32 2
|
||||
; CHECK-DAG: %[[V9:.+]] = fmul <2 x double> <double 1.000000e+00, double 1.000000e+00>, %[[V5]]
|
||||
; CHECK-DAG: %[[V10:.+]] = extractelement <2 x double> %[[V9]], i32 0
|
||||
; CHECK-DAG: %[[I3:.+]] = insertelement <4 x double> %i2, double %[[V10]], i32 1
|
||||
; CHECK-DAG: %[[V11:.+]] = extractelement <2 x double> %[[V9]], i32 1
|
||||
; CHECK-DAG: %[[I4:.+]] = insertelement <4 x double> %i3, double %[[V11]], i32 0
|
||||
; CHECK: ret <4 x double> %[[I4]]
|
||||
|
||||
attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
80
test/Transforms/SLPVectorizer/X86/value-bug.ll
Normal file
80
test/Transforms/SLPVectorizer/X86/value-bug.ll
Normal file
@@ -0,0 +1,80 @@
|
||||
; RUN: opt -slp-vectorizer < %s -S -mtriple="x86_64-grtev3-linux-gnu" -mcpu=corei7-avx | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-grtev3-linux-gnu"
|
||||
|
||||
; We used to crash on this example because we were building a constant
|
||||
; expression during vectorization and the vectorizer expects instructions
|
||||
; as elements of the vectorized tree.
|
||||
; CHECK-LABEL: @test
|
||||
; PR19621
|
||||
|
||||
define void @test() {
|
||||
bb279:
|
||||
br label %bb283
|
||||
|
||||
bb283:
|
||||
%Av.sroa.8.0 = phi float [ undef, %bb279 ], [ %tmp315, %exit ]
|
||||
%Av.sroa.5.0 = phi float [ undef, %bb279 ], [ %tmp319, %exit ]
|
||||
%Av.sroa.3.0 = phi float [ undef, %bb279 ], [ %tmp307, %exit ]
|
||||
%Av.sroa.0.0 = phi float [ undef, %bb279 ], [ %tmp317, %exit ]
|
||||
br label %bb284
|
||||
|
||||
bb284:
|
||||
%tmp7.i = fpext float %Av.sroa.3.0 to double
|
||||
%tmp8.i = fsub double %tmp7.i, undef
|
||||
%tmp9.i = fsub double %tmp8.i, undef
|
||||
%tmp17.i = fpext float %Av.sroa.8.0 to double
|
||||
%tmp19.i = fsub double %tmp17.i, undef
|
||||
%tmp20.i = fsub double %tmp19.i, undef
|
||||
br label %bb21.i
|
||||
|
||||
bb21.i:
|
||||
br i1 undef, label %bb22.i, label %exit
|
||||
|
||||
bb22.i:
|
||||
%tmp24.i = fadd double undef, %tmp9.i
|
||||
%tmp26.i = fadd double undef, %tmp20.i
|
||||
br label %bb32.i
|
||||
|
||||
bb32.i:
|
||||
%xs.0.i = phi double [ %tmp24.i, %bb22.i ], [ 0.000000e+00, %bb32.i ]
|
||||
%ys.0.i = phi double [ %tmp26.i, %bb22.i ], [ 0.000000e+00, %bb32.i ]
|
||||
br i1 undef, label %bb32.i, label %bb21.i
|
||||
|
||||
exit:
|
||||
%tmp303 = fpext float %Av.sroa.0.0 to double
|
||||
%tmp304 = fmul double %tmp303, undef
|
||||
%tmp305 = fadd double undef, %tmp304
|
||||
%tmp306 = fadd double %tmp305, undef
|
||||
%tmp307 = fptrunc double %tmp306 to float
|
||||
%tmp311 = fpext float %Av.sroa.5.0 to double
|
||||
%tmp312 = fmul double %tmp311, 0.000000e+00
|
||||
%tmp313 = fadd double undef, %tmp312
|
||||
%tmp314 = fadd double %tmp313, undef
|
||||
%tmp315 = fptrunc double %tmp314 to float
|
||||
%tmp317 = fptrunc double undef to float
|
||||
%tmp319 = fptrunc double undef to float
|
||||
br label %bb283
|
||||
}
|
||||
|
||||
; Make sure that we probably handle constant folded vectorized trees. The
|
||||
; vectorizer starts at the type (%t2, %t3) and wil constant fold the tree.
|
||||
; The code that handles insertelement instructions must handle this.
|
||||
define <4 x double> @constant_folding() {
|
||||
entry:
|
||||
%t0 = fadd double 1.000000e+00 , 0.000000e+00
|
||||
%t1 = fadd double 1.000000e+00 , 1.000000e+00
|
||||
%t2 = fmul double %t0, 1.000000e+00
|
||||
%i1 = insertelement <4 x double> undef, double %t2, i32 1
|
||||
%t3 = fmul double %t1, 1.000000e+00
|
||||
%i2 = insertelement <4 x double> %i1, double %t3, i32 0
|
||||
ret <4 x double> %i2
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @constant_folding
|
||||
; CHECK: %[[V0:.+]] = extractelement <2 x double> <double 1.000000e+00, double 2.000000e+00>, i32 0
|
||||
; CHECK: %[[V1:.+]] = insertelement <4 x double> undef, double %[[V0]], i32 1
|
||||
; CHECK: %[[V2:.+]] = extractelement <2 x double> <double 1.000000e+00, double 2.000000e+00>, i32 1
|
||||
; CHECK: %[[V3:.+]] = insertelement <4 x double> %[[V1]], double %[[V2]], i32 0
|
||||
; CHECK: ret <4 x double> %[[V3]]
|
Reference in New Issue
Block a user