<div dir="ltr">Hi Tom, there's a request to merge this bug fix into 10.0.1, is that ok?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 21, 2020 at 3:19 PM Arthur Eubanks via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Arthur Eubanks<br>
Date: 2020-05-21T15:19:10-07:00<br>
New Revision: fc937806efd71eb3803b35d0920bb7d76bc3040b<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/fc937806efd71eb3803b35d0920bb7d76bc3040b" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/fc937806efd71eb3803b35d0920bb7d76bc3040b</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/fc937806efd71eb3803b35d0920bb7d76bc3040b.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/fc937806efd71eb3803b35d0920bb7d76bc3040b.diff</a><br>
<br>
LOG: Don't jump to landing pads in Control Flow Optimizer<br>
<br>
Summary: Likely fixes <a href="https://bugs.llvm.org/show_bug.cgi?id=45858" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=45858</a>.<br>
<br>
Subscribers: hiraditya, llvm-commits<br>
<br>
Tags: #llvm<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D80047" rel="noreferrer" target="_blank">https://reviews.llvm.org/D80047</a><br>
<br>
Added: <br>
    llvm/test/CodeGen/X86/branchfolding-ehpad.mir<br>
<br>
Modified: <br>
    llvm/lib/CodeGen/BranchFolding.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp<br>
index eb72542b6efe..852bfb36c720 100644<br>
--- a/llvm/lib/CodeGen/BranchFolding.cpp<br>
+++ b/llvm/lib/CodeGen/BranchFolding.cpp<br>
@@ -921,10 +921,10 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,<br>
       continue;<br>
     }<br>
<br>
-    // If one of the blocks is the entire common tail (and not the entry<br>
-    // block, which we can't jump to), we can treat all blocks with this same<br>
-    // tail at once.  Use PredBB if that is one of the possibilities, as that<br>
-    // will not introduce any extra branches.<br>
+    // If one of the blocks is the entire common tail (and is not the entry<br>
+    // block/an EH pad, which we can't jump to), we can treat all blocks with<br>
+    // this same tail at once.  Use PredBB if that is one of the possibilities,<br>
+    // as that will not introduce any extra branches.<br>
     MachineBasicBlock *EntryBB =<br>
         &MergePotentials.front().getBlock()->getParent()->front();<br>
     unsigned commonTailIndex = SameTails.size();<br>
@@ -932,19 +932,21 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,<br>
     // into the other.<br>
     if (SameTails.size() == 2 &&<br>
         SameTails[0].getBlock()->isLayoutSuccessor(SameTails[1].getBlock()) &&<br>
-        SameTails[1].tailIsWholeBlock())<br>
+        SameTails[1].tailIsWholeBlock() && !SameTails[1].getBlock()->isEHPad())<br>
       commonTailIndex = 1;<br>
     else if (SameTails.size() == 2 &&<br>
              SameTails[1].getBlock()->isLayoutSuccessor(<br>
-                                                     SameTails[0].getBlock()) &&<br>
-             SameTails[0].tailIsWholeBlock())<br>
+                 SameTails[0].getBlock()) &&<br>
+             SameTails[0].tailIsWholeBlock() &&<br>
+             !SameTails[0].getBlock()->isEHPad())<br>
       commonTailIndex = 0;<br>
     else {<br>
       // Otherwise just pick one, favoring the fall-through predecessor if<br>
       // there is one.<br>
       for (unsigned i = 0, e = SameTails.size(); i != e; ++i) {<br>
         MachineBasicBlock *MBB = SameTails[i].getBlock();<br>
-        if (MBB == EntryBB && SameTails[i].tailIsWholeBlock())<br>
+        if ((MBB == EntryBB || MBB->isEHPad()) &&<br>
+            SameTails[i].tailIsWholeBlock())<br>
           continue;<br>
         if (MBB == PredBB) {<br>
           commonTailIndex = i;<br>
<br>
diff  --git a/llvm/test/CodeGen/X86/branchfolding-ehpad.mir b/llvm/test/CodeGen/X86/branchfolding-ehpad.mir<br>
new file mode 100644<br>
index 000000000000..d445cd206803<br>
--- /dev/null<br>
+++ b/llvm/test/CodeGen/X86/branchfolding-ehpad.mir<br>
@@ -0,0 +1,28 @@<br>
+# RUN: llc -mtriple=x86_64-windows-msvc -verify-machineinstrs -run-pass branch-folder -o - %s | FileCheck %s<br>
+<br>
+# Check that branch-folder does not create a fallthrough to a landing pad.<br>
+# Also make sure that the landing pad still can be tail merged.<br>
+---<br>
+name: foo<br>
+body: |<br>
+  ; CHECK-LABEL: name: foo<br>
+  bb.0:<br>
+    successors: %bb.1, %bb.3<br>
+  bb.1:<br>
+    JCC_1 %bb.4, 5, implicit killed $eflags<br>
+  bb.2:<br>
+    MOV8mi $r13, 1, $noreg, 0, $noreg, 0<br>
+    JMP_1 %bb.5<br>
+  ; CHECK: bb.2:<br>
+  ; CHECK-NOT: successors: {{.*}}bb.3<br>
+  ; CHECK: bb.3 (landing-pad):<br>
+  ; CHECK-NOT: MOV8mi<br>
+  bb.3(landing-pad):<br>
+    MOV8mi $r13, 1, $noreg, 0, $noreg, 0<br>
+    JMP_1 %bb.5<br>
+  ; CHECK: bb.4:<br>
+  bb.4:<br>
+    MOV8mi $r13, 2, $noreg, 0, $noreg, 0<br>
+  bb.5:<br>
+    RET 0<br>
+...<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>