[SimplifyCFG] Tweak heuristic for merging conditional stores
authorJames Molloy <james.molloy@arm.com>
Thu, 5 Nov 2015 08:40:19 +0000 (08:40 +0000)
committerJames Molloy <james.molloy@arm.com>
Thu, 5 Nov 2015 08:40:19 +0000 (08:40 +0000)
We were correctly skipping dbginfo intrinsics and terminators, but the initial bailout wasn't, causing it to bail out on almost any block.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252152 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp

index 0a0c4a1044ae24be756a84f62aa08cdb17a252e5..b119d2df035d4d6b358d1fc30a23e7772bd88ae0 100644 (file)
@@ -2426,14 +2426,20 @@ static bool mergeConditionalStoreToAddress(BasicBlock *PTB, BasicBlock *PFB,
     // Heuristic: if the block can be if-converted/phi-folded and the
     // instructions inside are all cheap (arithmetic/GEPs), it's worthwhile to
     // thread this store.
-    if (BB->size() > PHINodeFoldingThreshold)
-      return false;
-    for (auto &I : *BB)
-      if (!isa<BinaryOperator>(I) && !isa<GetElementPtrInst>(I) &&
-          !isa<StoreInst>(I) && !isa<TerminatorInst>(I) &&
-          !isa<DbgInfoIntrinsic>(I) && !IsaBitcastOfPointerType(I))
+    unsigned N = 0;
+    for (auto &I : *BB) {
+      // Cheap instructions viable for folding.
+      if (isa<BinaryOperator>(I) || isa<GetElementPtrInst>(I) ||
+          isa<StoreInst>(I))
+        ++N;
+      // Free instructions.
+      else if (isa<TerminatorInst>(I) || isa<DbgInfoIntrinsic>(I) ||
+               IsaBitcastOfPointerType(I))
+        continue;
+      else
         return false;
-    return true;
+    }
+    return N <= PHINodeFoldingThreshold;
   };
 
   if (!MergeCondStoresAggressively && (!IsWorthwhile(PTB) ||