From a3bdb086c7ebc1a21844059620f8728f56ce93b4 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Thu, 5 Nov 2015 08:40:19 +0000 Subject: [PATCH] [SimplifyCFG] Tweak heuristic for merging conditional stores 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 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 0a0c4a1044a..b119d2df035 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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(I) && !isa(I) && - !isa(I) && !isa(I) && - !isa(I) && !IsaBitcastOfPointerType(I)) + unsigned N = 0; + for (auto &I : *BB) { + // Cheap instructions viable for folding. + if (isa(I) || isa(I) || + isa(I)) + ++N; + // Free instructions. + else if (isa(I) || isa(I) || + IsaBitcastOfPointerType(I)) + continue; + else return false; - return true; + } + return N <= PHINodeFoldingThreshold; }; if (!MergeCondStoresAggressively && (!IsWorthwhile(PTB) || -- 2.34.1