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

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 7 02:43:05 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG01c48d7d11e6: [Attributor] Fold terminators before changing instructions to unreachable (authored by baziotis).

Changed prior to commit:
  https://reviews.llvm.org/D75780?vs=248860&id=248919#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75780/new/

https://reviews.llvm.org/D75780

Files:
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/Attributor/undefined_behavior.ll


Index: llvm/test/Transforms/Attributor/undefined_behavior.ll
===================================================================
--- llvm/test/Transforms/Attributor/undefined_behavior.ll
+++ llvm/test/Transforms/Attributor/undefined_behavior.ll
@@ -298,3 +298,27 @@
 e:
   ret i32 2
 }
+
+; Note that the `load` has UB (so it will be changed to unreachable)
+; and the branch is a terminator that can be constant-folded.
+; We want to test that doing both won't cause a segfault.
+define internal i32 @callee(i1 %C, i32* %A) {
+; ATTRIBUTOR-NOT: @callee(
+;
+entry:
+  %A.0 = load i32, i32* null
+  br i1 %C, label %T, label %F
+
+T:
+  ret i32 %A.0
+
+F:
+  ret i32 1
+}
+
+define i32 @foo() {
+; ATTRIBUTOR-LABEL: @foo()
+; ATTRIBUTOR-NEXT:    ret i32 1
+  %X = call i32 @callee(i1 false, i32* null)
+  ret i32 %X
+}
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.248919.patch
Type: text/x-patch
Size: 1789 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/0a1b5e43/attachment.bin>


More information about the llvm-commits mailing list