[PATCH] D61154: [PredicateInfo] Do not process unreachable operands.

Taewook Oh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 14:32:22 PDT 2019


twoh created this revision.
twoh added reviewers: dberlin, mgrang, davide.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

We should excluded unreachable operands from processing as their DFS visitation order is undefined. When `renameUses` function sorts `OpsToRename` (https://fburl.com/d2wubn60), the comparator assumes that the parent block of the operand has a corresponding dominator tree node. This is not the case for unreachable operands and crashes the compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61154

Files:
  llvm/lib/Transforms/Utils/PredicateInfo.cpp


Index: llvm/lib/Transforms/Utils/PredicateInfo.cpp
===================================================================
--- llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -338,6 +338,11 @@
       collectCmpOps(Cmp, CmpOperands);
       // Now add our copy infos for our operands
       for (auto *Op : CmpOperands) {
+        // Unreachable Ops are out of interest.
+        if (Instruction *I = dyn_cast<Instruction>(Op))
+          if (!DT.getNode(I->getParent()))
+            continue;
+
         auto *PA = new PredicateAssume(Op, II, Cmp);
         addInfoFor(OpsToRename, Op, PA);
       }
@@ -346,6 +351,10 @@
       // Otherwise, it should be an AND.
       assert(BinOp->getOpcode() == Instruction::And &&
              "Should have been an AND");
+      // Unreachable Ops are out of interest.
+      if (!DT.getNode(BinOp->getParent()))
+        continue;
+
       auto *PA = new PredicateAssume(BinOp, II, BinOp);
       addInfoFor(OpsToRename, BinOp, PA);
     } else {
@@ -366,6 +375,11 @@
   SmallVector<Value *, 2> ConditionsToProcess;
 
   auto InsertHelper = [&](Value *Op, bool isAnd, bool isOr, Value *Cond) {
+    // Unreachable Ops are out of interest.
+    if (Instruction *I = dyn_cast<Instruction>(Op))
+      if (!DT.getNode(I->getParent()))
+        return;
+
     for (auto *Succ : SuccsToProcess) {
       // Don't try to insert on a self-edge. This is mainly because we will
       // eliminate during renaming anyway.
@@ -432,6 +446,11 @@
   if ((!isa<Instruction>(Op) && !isa<Argument>(Op)) || Op->hasOneUse())
     return;
 
+  // Unreachable Ops are out of interest.
+  if (Instruction *I = dyn_cast<Instruction>(Op))
+    if (!DT.getNode(I->getParent()))
+      return;
+
   // Remember how many outgoing edges there are to every successor.
   SmallDenseMap<BasicBlock *, unsigned, 16> SwitchEdges;
   for (unsigned i = 0, e = SI->getNumSuccessors(); i != e; ++i) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61154.196729.patch
Type: text/x-patch
Size: 1949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190425/b2c8b3b0/attachment.bin>


More information about the llvm-commits mailing list