From e6f2df961065e3b723ef0fc78441f07c5577acd2 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Tue, 4 Dec 2012 07:11:52 +0000 Subject: [PATCH] Give scalar if-converted blocks half the score because they are not always executed due to CF. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169223 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/LoopVectorize.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index f538e081793..1de5b30c0ef 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2159,17 +2159,17 @@ unsigned LoopVectorizationCostModel::expectedCost(unsigned VF) { // For each instruction in the old loop. for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) { - unsigned C = getInstructionCost(it, VF); Cost += C; DEBUG(dbgs() << "LV: Found an estimated cost of "<< C <<" for VF " << VF << " For instruction: "<< *it << "\n"); } - // TODO: if-converted blocks can have a high-nest level. We need to - // calculate the loop nest level and multiply the cost accordingly. - if (Legal->blockNeedsPredication(*bb)) - BlockCost *= 2; + // We assume that if-converted blocks have a 50% chance of being executed. + // When the code is scalar then some of the blocks are avoided due to CF. + // When the code is vectorized we execute all code paths. + if (Legal->blockNeedsPredication(*bb) && VF == 1) + BlockCost /= 2; Cost += BlockCost; }