[PATCH] D13040: [SimplifyCFG] Constant fold a branch implied by it's incoming edge

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 28 20:14:53 PDT 2015


reames marked an inline comment as done.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:2515
@@ +2514,3 @@
+      PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
+      BB->getSinglePredecessor()) {
+    // Turn this into a branch on constant.
----------------
sanjoy wrote:
> I don't think you need to check `PBI->getSuccessor(0) != PBI->getSuccessor(1)` -- please verify this, but I think `getSinglePredecessor` (as opposed to `getUniquePredecessor`) should return `nullptr` if you have two branches from the same block to `BB`.
After reading the code, I wasn't sure about this.  I saw nothing which made it obvious, so I left the code as is.  

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:2518
@@ +2517,3 @@
+    auto *OldCond = BI->getCondition();
+    BI->setCondition(ConstantInt::getTrue(Type::getInt1Ty(BB->getContext())));
+    RecursivelyDeleteTriviallyDeadInstructions(OldCond);
----------------
sanjoy wrote:
> Since you're not creating vectors of `i1`s, I think `ConstantInt::getTrue(BB->getContext())` should be sufficient.
Fixed.


Repository:
  rL LLVM

http://reviews.llvm.org/D13040





More information about the llvm-commits mailing list