Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1512,6 +1512,18 @@ })); } + bool canVectorizeInstructionTypes(Loop *TheLoop, ElementCount VF) { + bool IllegalTy = false; + for (BasicBlock *BB : TheLoop->blocks()) + for (Instruction &I : BB->instructionsWithoutDebug()) { + auto *Ty = I.getType(); + if (!Ty->isVoidTy() && + !TTI.isLegalToVectorizeElementType(Ty, VF.isScalable())) + IllegalTy = true; + } + return !IllegalTy; + } + /// Returns true if \p I is an instruction that will be scalarized with /// predication. Such instructions include conditional stores and /// instructions that may divide by zero. @@ -5671,6 +5683,14 @@ return ElementCount::getScalable(0); } + if (!canVectorizeInstructionTypes(TheLoop, MaxScalableVF)) { + reportVectorizationInfo( + "Scalable vectorization is not supported for all element " + "types found in this loop.", + "ScalableVFUnfeasible", ORE, TheLoop); + return ElementCount::getScalable(0); + } + if (Legal->isSafeForAnyVectorWidth()) return MaxScalableVF; Index: llvm/test/Transforms/LoopVectorize/AArch64/scalable-reductions.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/AArch64/scalable-reductions.ll +++ llvm/test/Transforms/LoopVectorize/AArch64/scalable-reductions.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -loop-vectorize -pass-remarks=loop-vectorize -pass-remarks-analysis=loop-vectorize -pass-remarks-missed=loop-vectorize -mtriple aarch64-unknown-linux-gnu -mattr=+sve -S 2>%t | FileCheck %s -check-prefix=CHECK +; RUN: opt < %s -loop-vectorize -pass-remarks=loop-vectorize -pass-remarks-analysis=loop-vectorize -pass-remarks-missed=loop-vectorize -mtriple aarch64-unknown-linux-gnu -mattr=+sve,+bf16 -S 2>%t | FileCheck %s -check-prefix=CHECK ; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARK ; Reduction can be vectorized Index: llvm/test/Transforms/LoopVectorize/sve-illegal-type.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopVectorize/sve-illegal-type.ll @@ -0,0 +1,82 @@ +; RUN: opt < %s -loop-vectorize -mtriple aarch64-linux-gnu -force-target-supports-scalable-vectors=true -force-vector-width=4 -pass-remarks-analysis=loop-vectorize -S 2>%t | FileCheck %s +; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARKS + +; CHECK-REMARKS: Scalable vectorization is not supported for all element types found in this loop +define dso_local void @loop_sve_i128(i128* nocapture %ptr, i64 %N) { +; CHECK-LABEL: @loop_sve_i128 +; CHECK: vector.body +; CHECK: load i128, i128* {{.*}} +; CHECK-NEXT: load i128, i128* {{.*}} +; CHECK-NEXT: add nsw i128 {{.*}}, 42 +; CHECK-NEXT: add nsw i128 {{.*}}, 42 +; CHECK-NEXT: store i128 %4, i128* {{.*}} +; CHECK-NEXT: store i128 %5, i128* {{.*}} +entry: + br label %for.body + +for.body: + %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] + %arrayidx = getelementptr inbounds i128, i128* %ptr, i64 %iv + %0 = load i128, i128* %arrayidx, align 16 + %add = add nsw i128 %0, 42 + store i128 %add, i128* %arrayidx, align 16 + %iv.next = add i64 %iv, 1 + %exitcond.not = icmp eq i64 %iv.next, %N + br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0 + +for.end: + ret void +} + +; CHECK-REMARKS: Scalable vectorization is not supported for all element types found in this loop +define dso_local void @loop_sve_f128(fp128* nocapture %ptr, i64 %N) { +; CHECK-LABEL: @loop_sve_f128 +; CHECK: vector.body +; CHECK: load fp128, fp128* +; CHECK-NEXT: load fp128, fp128* +; CHECK-NEXT: fsub fp128 {{.*}}, 0xL00000000000000008000000000000000 +; CHECK-NEXT: fsub fp128 {{.*}}, 0xL00000000000000008000000000000000 +; CHECK-NEXT: store fp128 %4, fp128* {{.*}} +; CHECK-NEXT: store fp128 %5, fp128* {{.*}} +entry: + br label %for.body + +for.body: + %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] + %arrayidx = getelementptr inbounds fp128, fp128* %ptr, i64 %iv + %0 = load fp128, fp128* %arrayidx, align 16 + %add = fsub fp128 %0, 0xL00000000000000008000000000000000 + store fp128 %add, fp128* %arrayidx, align 16 + %iv.next = add nuw nsw i64 %iv, 1 + %exitcond.not = icmp eq i64 %iv.next, %N + br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0 + +for.end: + ret void +} + +; CHECK-REMARKS: Scalable vectorization is not supported for all element types found in this loop +define dso_local void @loop_fixed_width_i128(i128* nocapture %ptr, i64 %N) { +; CHECK-LABEL: @loop_fixed_width_i128 +; CHECK:load <4 x i128>, <4 x i128>* +; CHECK: add nsw <4 x i128> {{.*}}, +; CHECK: store <4 x i128> {{.*}} <4 x i128>* +entry: + br label %for.body + +for.body: + %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] + %arrayidx = getelementptr inbounds i128, i128* %ptr, i64 %iv + %0 = load i128, i128* %arrayidx, align 16 + %add = add nsw i128 %0, 42 + store i128 %add, i128* %arrayidx, align 16 + %iv.next = add i64 %iv, 1 + %exitcond.not = icmp eq i64 %iv.next, %N + br i1 %exitcond.not, label %for.end, label %for.body + +for.end: + ret void +} + +!0 = distinct !{!0, !1} +!1 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}