[PATCH] D30429: [JumpThread] Simplify CmpInst-as-Condition branch-folding a bit.

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 11:11:11 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL297186: [JumpThread] Simplify CmpInst-as-Condition branch-folding a bit. (authored by trentxintong).

Changed prior to commit:
  https://reviews.llvm.org/D30429?vs=89934&id=90893#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30429

Files:
  llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp


Index: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
@@ -808,7 +808,12 @@
     // TODO: This should be extended to handle switches as well.
     BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator());
     Constant *CondConst = dyn_cast<Constant>(CondCmp->getOperand(1));
-    if (CondBr && CondConst && CondBr->isConditional()) {
+    if (CondBr && CondConst) {
+      // We should have returned as soon as we turn a conditional branch to
+      // unconditional. Because its no longer interesting as far as jump
+      // threading is concerned.
+      assert(CondBr->isConditional() && "Threading on unconditional terminator");
+
       LazyValueInfo::Tristate Ret =
         LVI->getPredicateAt(CondCmp->getPredicate(), CondCmp->getOperand(0),
                             CondConst, CondBr);
@@ -831,10 +836,12 @@
         }
         return true;
       }
-    }
 
-    if (CondBr && CondConst && TryToUnfoldSelect(CondCmp, BB))
-      return true;
+      // We did not manage to simplify this branch, try to see whether
+      // CondCmp depends on a known phi-select pattern.
+      if (TryToUnfoldSelect(CondCmp, BB))
+        return true;
+    }
   }
 
   // Check for some cases that are worth simplifying.  Right now we want to look


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30429.90893.patch
Type: text/x-patch
Size: 1435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170307/e4334ece/attachment.bin>


More information about the llvm-commits mailing list