blob: de9242d45099faeafcdb30c7b6093a8fd5d3f7be [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -passes=slp-vectorizer -mcpu=skx -mtriple=x86_64-unknown -S < %s | FileCheck %s
; Compares feeding a uniform single-use chain that ends in heterogeneous sinks.
; vectorizeCmpInsts() roots the SLP tree at the compares, so only the compares
; themselves are vectorized and the chain they feed stays scalar.
define i32 @cmp_deep_chain_hetero_sinks(ptr %a, ptr %b, ptr %s, i32 %x) {
; CHECK-LABEL: define i32 @cmp_deep_chain_hetero_sinks(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[S:%.*]], i32 [[X:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, ptr [[A]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, ptr [[B]], align 4
; CHECK-NEXT: [[TMP2:%.*]] = fcmp olt <4 x float> [[TMP0]], [[TMP1]]
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x i1> [[TMP2]], i64 0
; CHECK-NEXT: [[Z0:%.*]] = zext i1 [[TMP3]] to i32
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x i1> [[TMP2]], i64 1
; CHECK-NEXT: [[Z1:%.*]] = zext i1 [[TMP4]] to i32
; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x i1> [[TMP2]], i64 2
; CHECK-NEXT: [[Z2:%.*]] = zext i1 [[TMP5]] to i32
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i1> [[TMP2]], i64 3
; CHECK-NEXT: [[Z3:%.*]] = zext i1 [[TMP6]] to i32
; CHECK-NEXT: [[M0:%.*]] = mul i32 [[Z0]], 7
; CHECK-NEXT: [[M1:%.*]] = mul i32 [[Z1]], 7
; CHECK-NEXT: [[M2:%.*]] = mul i32 [[Z2]], 7
; CHECK-NEXT: [[M3:%.*]] = mul i32 [[Z3]], 7
; CHECK-NEXT: [[O0:%.*]] = or i32 [[M0]], 3
; CHECK-NEXT: [[O1:%.*]] = or i32 [[M1]], 3
; CHECK-NEXT: [[O2:%.*]] = or i32 [[M2]], 3
; CHECK-NEXT: [[O3:%.*]] = or i32 [[M3]], 3
; CHECK-NEXT: [[X0:%.*]] = xor i32 [[O0]], 5
; CHECK-NEXT: [[X1:%.*]] = xor i32 [[O1]], 5
; CHECK-NEXT: [[X2:%.*]] = xor i32 [[O2]], 5
; CHECK-NEXT: [[X3:%.*]] = xor i32 [[O3]], 5
; CHECK-NEXT: store i32 [[X0]], ptr [[S]], align 4
; CHECK-NEXT: [[H1:%.*]] = mul i32 [[X1]], [[X]]
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X2]], [[H1]]
; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[ADD]], [[X3]]
; CHECK-NEXT: ret i32 [[SUB]]
;
entry:
%a0 = load float, ptr %a, align 4
%pa1 = getelementptr inbounds float, ptr %a, i64 1
%a1 = load float, ptr %pa1, align 4
%pa2 = getelementptr inbounds float, ptr %a, i64 2
%a2 = load float, ptr %pa2, align 4
%pa3 = getelementptr inbounds float, ptr %a, i64 3
%a3 = load float, ptr %pa3, align 4
%b0 = load float, ptr %b, align 4
%pb1 = getelementptr inbounds float, ptr %b, i64 1
%b1 = load float, ptr %pb1, align 4
%pb2 = getelementptr inbounds float, ptr %b, i64 2
%b2 = load float, ptr %pb2, align 4
%pb3 = getelementptr inbounds float, ptr %b, i64 3
%b3 = load float, ptr %pb3, align 4
%c0 = fcmp olt float %a0, %b0
%c1 = fcmp olt float %a1, %b1
%c2 = fcmp olt float %a2, %b2
%c3 = fcmp olt float %a3, %b3
%z0 = zext i1 %c0 to i32
%z1 = zext i1 %c1 to i32
%z2 = zext i1 %c2 to i32
%z3 = zext i1 %c3 to i32
%m0 = mul i32 %z0, 7
%m1 = mul i32 %z1, 7
%m2 = mul i32 %z2, 7
%m3 = mul i32 %z3, 7
%o0 = or i32 %m0, 3
%o1 = or i32 %m1, 3
%o2 = or i32 %m2, 3
%o3 = or i32 %m3, 3
%x0 = xor i32 %o0, 5
%x1 = xor i32 %o1, 5
%x2 = xor i32 %o2, 5
%x3 = xor i32 %o3, 5
store i32 %x0, ptr %s, align 4
%h1 = mul i32 %x1, %x
%add = add i32 %x2, %h1
%sub = sub i32 %add, %x3
ret i32 %sub
}
; The same shape after the earlier pipeline passes have canonicalized it: the
; bool-to-float conversion and the multiply by the loaded weights survive as a
; uitofp/fmul chain. Only two of the four lanes are reachable bottom-up from the
; sinks, so the compares are again rooted by vectorizeCmpInsts().
define float @cmp_uitofp_fmul_hetero_sinks(ptr %a, ptr %b, ptr %w, ptr %s) {
; CHECK-LABEL: define float @cmp_uitofp_fmul_hetero_sinks(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[W:%.*]], ptr [[S:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[PA2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
; CHECK-NEXT: [[PB2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
; CHECK-NEXT: [[W0:%.*]] = load float, ptr [[W]], align 4
; CHECK-NEXT: [[PW1:%.*]] = getelementptr inbounds float, ptr [[W]], i64 1
; CHECK-NEXT: [[W1:%.*]] = load float, ptr [[PW1]], align 4
; CHECK-NEXT: [[PW2:%.*]] = getelementptr inbounds float, ptr [[W]], i64 2
; CHECK-NEXT: [[TMP0:%.*]] = load <2 x float>, ptr [[A]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x float>, ptr [[B]], align 4
; CHECK-NEXT: [[TMP2:%.*]] = fcmp olt <2 x float> [[TMP0]], [[TMP1]]
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i1> [[TMP2]], i64 0
; CHECK-NEXT: [[Z0:%.*]] = uitofp i1 [[TMP3]] to float
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i1> [[TMP2]], i64 1
; CHECK-NEXT: [[Z1:%.*]] = uitofp i1 [[TMP4]] to float
; CHECK-NEXT: [[M0:%.*]] = fmul float [[W0]], [[Z0]]
; CHECK-NEXT: [[M1:%.*]] = fmul float [[W1]], [[Z1]]
; CHECK-NEXT: [[TMP5:%.*]] = load <2 x float>, ptr [[PA2]], align 4
; CHECK-NEXT: [[TMP6:%.*]] = load <2 x float>, ptr [[PB2]], align 4
; CHECK-NEXT: [[TMP7:%.*]] = load <2 x float>, ptr [[PW2]], align 4
; CHECK-NEXT: [[TMP8:%.*]] = fcmp olt <2 x float> [[TMP5]], [[TMP6]]
; CHECK-NEXT: [[TMP9:%.*]] = uitofp <2 x i1> [[TMP8]] to <2 x float>
; CHECK-NEXT: [[TMP10:%.*]] = fmul <2 x float> [[TMP7]], [[TMP9]]
; CHECK-NEXT: store float [[M0]], ptr [[S]], align 4
; CHECK-NEXT: [[H1:%.*]] = fmul float [[W1]], [[M1]]
; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x float> [[TMP10]], i64 0
; CHECK-NEXT: [[ADD:%.*]] = fadd float [[TMP11]], [[H1]]
; CHECK-NEXT: [[TMP12:%.*]] = extractelement <2 x float> [[TMP10]], i64 1
; CHECK-NEXT: [[SUB:%.*]] = fsub float [[ADD]], [[TMP12]]
; CHECK-NEXT: ret float [[SUB]]
;
entry:
%a0 = load float, ptr %a, align 4
%pa1 = getelementptr inbounds float, ptr %a, i64 1
%a1 = load float, ptr %pa1, align 4
%pa2 = getelementptr inbounds float, ptr %a, i64 2
%a2 = load float, ptr %pa2, align 4
%pa3 = getelementptr inbounds float, ptr %a, i64 3
%a3 = load float, ptr %pa3, align 4
%b0 = load float, ptr %b, align 4
%pb1 = getelementptr inbounds float, ptr %b, i64 1
%b1 = load float, ptr %pb1, align 4
%pb2 = getelementptr inbounds float, ptr %b, i64 2
%b2 = load float, ptr %pb2, align 4
%pb3 = getelementptr inbounds float, ptr %b, i64 3
%b3 = load float, ptr %pb3, align 4
%w0 = load float, ptr %w, align 4
%pw1 = getelementptr inbounds float, ptr %w, i64 1
%w1 = load float, ptr %pw1, align 4
%pw2 = getelementptr inbounds float, ptr %w, i64 2
%w2 = load float, ptr %pw2, align 4
%pw3 = getelementptr inbounds float, ptr %w, i64 3
%w3 = load float, ptr %pw3, align 4
%c0 = fcmp olt float %a0, %b0
%c1 = fcmp olt float %a1, %b1
%c2 = fcmp olt float %a2, %b2
%c3 = fcmp olt float %a3, %b3
%z0 = uitofp i1 %c0 to float
%z1 = uitofp i1 %c1 to float
%z2 = uitofp i1 %c2 to float
%z3 = uitofp i1 %c3 to float
%m0 = fmul float %w0, %z0
%m1 = fmul float %w1, %z1
%m2 = fmul float %w2, %z2
%m3 = fmul float %w3, %z3
store float %m0, ptr %s, align 4
%h1 = fmul float %w1, %m1
%add = fadd float %m2, %h1
%sub = fsub float %add, %m3
ret float %sub
}