[PATCH] D37343: [CodegenPrepare] Merge empty case blocks if no extra moves are added.(WIP)

Balaram Makam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 31 11:04:04 PDT 2017


bmakam created this revision.
Herald added a subscriber: mcrosier.

Currently we skip merging when extra moves may be added in the header of
switch instead of the case block, if the case block is used as an incoming
block of a PHI. If all the incoming values of the PHIs are non-constants
then extra moves are likely not added by ISel, so there is no need to skip
merging in this case. I will add testcase if this looks reasonable.
Please take a look.


https://reviews.llvm.org/D37343

Files:
  lib/CodeGen/CodeGenPrepare.cpp


Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -668,6 +668,20 @@
   return MadeChange;
 }
 
+/// Check to see if all of the operands of the PHI are not simple constants
+/// (constantint/constantfp/undef).
+static bool HasAllNonCstPhiOps(BasicBlock *DestBB) {
+  BasicBlock::const_iterator DestBBI = DestBB->begin();
+  while (const PHINode *DestPN = dyn_cast<PHINode>(DestBBI++)) {
+    for (unsigned I = 0, E = DestPN->getNumIncomingValues(); I != E; ++I) {
+      if (isa<Constant>(DestPN->getIncomingValue(I)) &&
+          !isa<ConstantExpr>(DestPN->getIncomingValue(I)))
+        return false;
+    }
+  }
+  return true;
+}
+
 bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
                                                    BasicBlock *DestBB,
                                                    bool isPreheader) {
@@ -740,6 +754,12 @@
   if (SameIncomingValueBBs.count(Pred))
     return true;
 
+  // Check to see if phi operands are of constants, in such case extra COPYs
+  // are likely needed. If all the operands of the phis are not constant there
+  // is no reason to skip merging.
+  if (HasAllNonCstPhiOps(DestBB))
+    return true;
+
   if (!BFI) {
     Function &F = *BB->getParent();
     LoopInfo LI{DominatorTree(F)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37343.113435.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170831/18f6a1e8/attachment.bin>


More information about the llvm-commits mailing list