Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5925,9 +5925,9 @@ // if-converted. This means that the block's instructions (aside from // stores and instructions that may divide by zero) will now be // unconditionally executed. For the scalar case, we may not always execute - // the predicated block. Thus, scale the block's cost by the probability of - // executing it. - if (VF == 1 && blockNeedsPredication(BB)) + // the predicated block, if it is an if-else block. Thus, scale the block's + // cost by the probability of executing it. + if (VF == 1 && Legal->blockNeedsPredication(BB)) BlockCost.first /= getReciprocalPredBlockProb(); Cost.first += BlockCost.first; Index: llvm/test/Transforms/LoopVectorize/ARM/scalar-block-cost.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/ARM/scalar-block-cost.ll +++ llvm/test/Transforms/LoopVectorize/ARM/scalar-block-cost.ll @@ -15,7 +15,7 @@ ; CHECK-COST-NEXT: LV: Found an estimated cost of 1 for VF 1 For instruction: store i32 %add1, i32* %arrayidx2, align 4 ; CHECK-COST-NEXT: LV: Found an estimated cost of 1 for VF 1 For instruction: %exitcond.not = icmp eq i32 %add, %n ; CHECK-COST-NEXT: LV: Found an estimated cost of 0 for VF 1 For instruction: br i1 %exitcond.not, label %exit.loopexit, label %for.body -; CHECK-COST-NEXT: LV: Scalar loop costs: 2. +; CHECK-COST-NEXT: LV: Scalar loop costs: 5. entry: %cmp8 = icmp sgt i32 %n, 0