Give scalar if-converted blocks half the score because they are not always executed...
authorNadav Rotem <nrotem@apple.com>
Tue, 4 Dec 2012 07:11:52 +0000 (07:11 +0000)
committerNadav Rotem <nrotem@apple.com>
Tue, 4 Dec 2012 07:11:52 +0000 (07:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169223 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Vectorize/LoopVectorize.cpp

index f538e0817930209364579133c1197037f030b245..1de5b30c0ef585956df4a832e86037a589fc646c 100644 (file)
@@ -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;
   }