Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6375,6 +6375,12 @@ // Collect Uniform and Scalar instructions after vectorization with VF. CM.collectUniformsAndScalars(VF); + // collectUniformsAndScalars (and setCostBasedWideningDecision) change + // SCEV behaviour, which we haven't seen before, so check again if we need + // runtime checks. + if (CM.TheFunction->hasOptSize() && CM.runtimeChecksRequired()) + return None; + // Collect the instructions (and their associated costs) that will be more // profitable to scalarize. if (VF > 1) Index: llvm/test/Transforms/LoopVectorize/pr43371-optsize-scevchecks.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopVectorize/pr43371-optsize-scevchecks.ll @@ -0,0 +1,38 @@ +; RUN: opt -S -loop-vectorize -pass-remarks-analysis='loop-vectorize' < %s 2>&1 | FileCheck %s + +@cm_array = external global [2592 x i16], align 1 + +define void @pr43371() optsize { +; +; CHECK: remark: :0:0: loop not vectorized: runtime SCEV checks needed. Enable vectorization of this loop with '#pragma clang loop vectorize(enable)' when compiling with -Os/-Oz +; +; CHECK-LABEL: @pr43371 +; +; CHECK-NOT: vector.scevcheck: +; CHECK-NOT: vector.body: +; +entry: + br label %for.body + +for.cond.for.cond.cleanup_crit_edge: + br label %for.body29 + +for.body: + br label %for.cond.for.cond.cleanup_crit_edge + +for.cond.cleanup28: + unreachable + +for.body29: + %i24.0170 = phi i16 [ 0, %for.cond.for.cond.cleanup_crit_edge ], [ %inc37, %for.inc36 ] + %add33 = add i16 undef, %i24.0170 + %idxprom34 = zext i16 %add33 to i32 + %arrayidx35 = getelementptr [2592 x i16], [2592 x i16] * @cm_array, i32 0, i32 %idxprom34 + store i16 0, i16 * %arrayidx35, align 1 + br label %for.inc36 + +for.inc36: + %inc37 = add i16 %i24.0170, 1 + %cmp26 = icmp ult i16 %inc37, 756 + br i1 %cmp26, label %for.body29, label %for.cond.cleanup28 +}