[PATCH] D75780: [Attributor][NFC] Fold terminators before changing instructions to unreachable

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 16:01:52 PST 2020


baziotis created this revision.
baziotis added reviewers: jdoerfert, uenoku, sstefan1.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

It is possible that an instruction to be changed to unreachable is in the same block with a terminator that can be constant-folded.
In this case, as of now, the instruction will be changed to unreachable before the terminator is folded. But, then the whole BB becomes
invalidated and so when we go ahead to fold the terminator, we trap.

Change the order of these two.


https://reviews.llvm.org/D75780

Files:
  llvm/lib/Transforms/IPO/Attributor.cpp


Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -7798,15 +7798,15 @@
           ToBeChangedToUnreachableInsts.insert(&NormalDestBB->front());
         }
       }
+    for (Instruction *I : TerminatorsToFold) {
+      CGModifiedFunctions.insert(I->getFunction());
+      ConstantFoldTerminator(I->getParent());
+    }
     for (auto &V : ToBeChangedToUnreachableInsts)
       if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
         CGModifiedFunctions.insert(I->getFunction());
         changeToUnreachable(I, /* UseLLVMTrap */ false);
       }
-    for (Instruction *I : TerminatorsToFold) {
-      CGModifiedFunctions.insert(I->getFunction());
-      ConstantFoldTerminator(I->getParent());
-    }
 
     for (auto &V : ToBeDeletedInsts) {
       if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75780.248853.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/e6046de3/attachment.bin>


More information about the llvm-commits mailing list