Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7361,6 +7361,7 @@ bool Changed = false; SmallVector Incoming; SmallPtrSet VisitedInstrs; + unsigned MaxVecRegSize = R.getMaxVecRegSize(); bool HaveVectorizedPhiNodes = true; while (HaveVectorizedPhiNodes) { @@ -7387,8 +7388,18 @@ // Look for the next elements with the same type. SmallVector::iterator SameTypeIt = IncIt; + Type *EltTy = (*IncIt)->getType(); + unsigned EltSize = EltTy->isSized() ? DL->getTypeSizeInBits(EltTy) + : MaxVecRegSize; + unsigned MaxNumElts = MaxVecRegSize / EltSize; + if (MaxNumElts < 2) { + ++IncIt; + continue; + } + while (SameTypeIt != E && - (*SameTypeIt)->getType() == (*IncIt)->getType()) { + (*SameTypeIt)->getType() == EltTy && + (SameTypeIt - IncIt) < MaxNumElts) { VisitedInstrs.insert(*SameTypeIt); ++SameTypeIt; } Index: llvm/test/Transforms/SLPVectorizer/X86/remark_unsupported.ll =================================================================== --- llvm/test/Transforms/SLPVectorizer/X86/remark_unsupported.ll +++ llvm/test/Transforms/SLPVectorizer/X86/remark_unsupported.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -mtriple=x86_64-pc-linux-gnu -mcpu=generic -slp-vectorizer -pass-remarks-output=%t < %s | FileCheck %s +; RUN: opt -S -mtriple=x86_64-pc-linux-gnu -mcpu=generic -slp-vectorizer --slp-max-reg-size=256 -pass-remarks-output=%t < %s | FileCheck %s ; RUN: FileCheck --input-file=%t --check-prefix=YAML %s ; This type is not supported by SLP Index: llvm/test/Transforms/SLPVectorizer/slp-max-phi-size.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/SLPVectorizer/slp-max-phi-size.ll @@ -0,0 +1,132 @@ +; RUN: opt -slp-vectorizer -S -slp-max-reg-size=32 < %s | FileCheck -check-prefixes=FUNC,MAX32 %s +; RUN: opt -slp-vectorizer -S -slp-max-reg-size=128 < %s | FileCheck -check-prefixes=FUNC,MAX128 %s +; RUN: opt -slp-vectorizer -S -slp-max-reg-size=1024 < %s | FileCheck -check-prefixes=FUNC,MAX1024 %s + +; FUNC-LABEL: @phi_float32() +; MAX32-COUNT-32: phi float +; MAX128-COUNT-8: phi <4 x float> +; MAX1024-COUNT-1: phi <32 x float> + +define void @phi_float32() { +bb: + br label %bb1 + +bb1: + %i = fpext half undef to float + %i1 = fmul float %i, undef + %i2 = fadd float 0.000000e+00, %i1 + %i3 = fpext half undef to float + %i4 = fmul float %i3, undef + %i5 = fadd float 0.000000e+00, %i4 + %i6 = fpext half undef to float + %i7 = fmul float %i6, undef + %i8 = fadd float 0.000000e+00, %i7 + %i9 = fpext half undef to float + %i10 = fmul float %i9, undef + %i11 = fadd float 0.000000e+00, %i10 + %i12 = fmul float %i, undef + %i13 = fadd float 0.000000e+00, %i12 + %i14 = fmul float %i3, undef + %i15 = fadd float 0.000000e+00, %i14 + %i16 = fmul float %i6, undef + %i17 = fadd float 0.000000e+00, %i16 + %i18 = fmul float %i9, undef + %i19 = fadd float 0.000000e+00, %i18 + %i20 = fmul float %i, undef + %i21 = fadd float 0.000000e+00, %i20 + %i22 = fmul float %i3, undef + %i23 = fadd float 0.000000e+00, %i22 + %i24 = fmul float %i6, undef + %i25 = fadd float 0.000000e+00, %i24 + %i26 = fmul float %i9, undef + %i27 = fadd float 0.000000e+00, %i26 + %i28 = fmul float %i, undef + %i29 = fadd float 0.000000e+00, %i28 + %i30 = fmul float %i3, undef + %i31 = fadd float 0.000000e+00, %i30 + %i32 = fmul float %i6, undef + %i33 = fadd float 0.000000e+00, %i32 + %i34 = fmul float %i9, undef + %i35 = fadd float 0.000000e+00, %i34 + %i36 = fmul float %i, undef + %i37 = fadd float 0.000000e+00, %i36 + %i38 = fmul float %i3, undef + %i39 = fadd float 0.000000e+00, %i38 + %i40 = fmul float %i6, undef + %i41 = fadd float 0.000000e+00, %i40 + %i42 = fmul float %i9, undef + %i43 = fadd float 0.000000e+00, %i42 + %i44 = fmul float %i, undef + %i45 = fadd float 0.000000e+00, %i44 + %i46 = fmul float %i3, undef + %i47 = fadd float 0.000000e+00, %i46 + %i48 = fmul float %i6, undef + %i49 = fadd float 0.000000e+00, %i48 + %i50 = fmul float %i9, undef + %i51 = fadd float 0.000000e+00, %i50 + %i52 = fmul float %i, undef + %i53 = fadd float 0.000000e+00, %i52 + %i54 = fmul float %i3, undef + %i55 = fadd float 0.000000e+00, %i54 + %i56 = fmul float %i6, undef + %i57 = fadd float 0.000000e+00, %i56 + %i58 = fmul float %i9, undef + %i59 = fadd float 0.000000e+00, %i58 + %i60 = fmul float %i, undef + %i61 = fadd float 0.000000e+00, %i60 + %i62 = fmul float %i3, undef + %i63 = fadd float 0.000000e+00, %i62 + %i64 = fmul float %i6, undef + %i65 = fadd float 0.000000e+00, %i64 + %i66 = fmul float %i9, undef + %i67 = fadd float 0.000000e+00, %i66 + switch i32 undef, label %bb5 [ + i32 0, label %bb2 + i32 1, label %bb3 + i32 2, label %bb4 + ] + +bb3: + br label %bb2 + +bb4: + br label %bb2 + +bb5: + br label %bb2 + +bb2: + %phi1 = phi float [ %i19, %bb3 ], [ %i19, %bb4 ], [ undef, %bb5 ], [ %i19, %bb1 ] + %phi2 = phi float [ %i17, %bb3 ], [ undef, %bb4 ], [ %i17, %bb5 ], [ %i17, %bb1 ] + %phi3 = phi float [ %i15, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi4 = phi float [ %i13, %bb3 ], [ %i13, %bb4 ], [ %i13, %bb5 ], [ undef, %bb1 ] + %phi5 = phi float [ %i11, %bb3 ], [ %i11, %bb4 ], [ undef, %bb5 ], [ %i11, %bb1 ] + %phi6 = phi float [ %i8, %bb3 ], [ undef, %bb4 ], [ %i8, %bb5 ], [ %i8, %bb1 ] + %phi7 = phi float [ %i5, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi8 = phi float [ %i2, %bb3 ], [ %i2, %bb4 ], [ %i2, %bb5 ], [ undef, %bb1 ] + %phi9 = phi float [ %i21, %bb3 ], [ %i21, %bb4 ], [ %i21, %bb5 ], [ undef, %bb1 ] + %phi10 = phi float [ %i23, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi11 = phi float [ %i25, %bb3 ], [ undef, %bb4 ], [ %i25, %bb5 ], [ %i25, %bb1 ] + %phi12 = phi float [ %i27, %bb3 ], [ %i27, %bb4 ], [ undef, %bb5 ], [ %i27, %bb1 ] + %phi13 = phi float [ %i29, %bb3 ], [ %i29, %bb4 ], [ %i29, %bb5 ], [ undef, %bb1 ] + %phi14 = phi float [ %i31, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi15 = phi float [ %i33, %bb3 ], [ undef, %bb4 ], [ %i33, %bb5 ], [ %i33, %bb1 ] + %phi16 = phi float [ %i35, %bb3 ], [ %i35, %bb4 ], [ undef, %bb5 ], [ %i35, %bb1 ] + %phi17 = phi float [ %i37, %bb3 ], [ %i37, %bb4 ], [ %i37, %bb5 ], [ undef, %bb1 ] + %phi18 = phi float [ %i39, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi19 = phi float [ %i41, %bb3 ], [ undef, %bb4 ], [ %i41, %bb5 ], [ %i41, %bb1 ] + %phi20 = phi float [ %i43, %bb3 ], [ %i43, %bb4 ], [ undef, %bb5 ], [ %i43, %bb1 ] + %phi21 = phi float [ %i45, %bb3 ], [ %i45, %bb4 ], [ %i45, %bb5 ], [ undef, %bb1 ] + %phi22 = phi float [ %i47, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi23 = phi float [ %i49, %bb3 ], [ undef, %bb4 ], [ %i49, %bb5 ], [ %i49, %bb1 ] + %phi24 = phi float [ %i51, %bb3 ], [ %i51, %bb4 ], [ undef, %bb5 ], [ %i51, %bb1 ] + %phi25 = phi float [ %i53, %bb3 ], [ %i53, %bb4 ], [ %i53, %bb5 ], [ undef, %bb1 ] + %phi26 = phi float [ %i55, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi27 = phi float [ %i57, %bb3 ], [ undef, %bb4 ], [ %i57, %bb5 ], [ %i57, %bb1 ] + %phi28 = phi float [ %i59, %bb3 ], [ %i59, %bb4 ], [ undef, %bb5 ], [ %i59, %bb1 ] + %phi29 = phi float [ %i61, %bb3 ], [ %i61, %bb4 ], [ %i61, %bb5 ], [ undef, %bb1 ] + %phi30 = phi float [ %i63, %bb3 ], [ undef, %bb4 ], [ undef, %bb5 ], [ undef, %bb1 ] + %phi31 = phi float [ %i65, %bb3 ], [ undef, %bb4 ], [ %i65, %bb5 ], [ %i65, %bb1 ] + %phi32 = phi float [ %i67, %bb3 ], [ %i67, %bb4 ], [ undef, %bb5 ], [ %i67, %bb1 ] + ret void +}