[llvm] r252822 - [WinEH] Don't forward branches across empty EH pad BBs

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 15:09:32 PST 2015


Author: rnk
Date: Wed Nov 11 17:09:31 2015
New Revision: 252822

URL: http://llvm.org/viewvc/llvm-project?rev=252822&view=rev
Log:
[WinEH] Don't forward branches across empty EH pad BBs

For really simple SEH catchpads, we tried to forward the invoke unwind
edge across the empty block.

Added:
    llvm/trunk/test/CodeGen/X86/catchret-empty-fallthrough.ll
Modified:
    llvm/trunk/lib/CodeGen/BranchFolding.cpp
    llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp

Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=252822&r1=252821&r2=252822&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Wed Nov 11 17:09:31 2015
@@ -1404,7 +1404,7 @@ ReoptimizeBlock:
     // other blocks across it.
     if (CurTBB && CurCond.empty() && !CurFBB &&
         IsBranchOnlyBlock(MBB) && CurTBB != MBB &&
-        !MBB->hasAddressTaken()) {
+        !MBB->hasAddressTaken() && !MBB->isEHPad()) {
       DebugLoc dl = getBranchDebugLoc(*MBB);
       // This block may contain just an unconditional branch.  Because there can
       // be 'non-branch terminators' in the block, try removing the branch and

Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=252822&r1=252821&r2=252822&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Wed Nov 11 17:09:31 2015
@@ -52,6 +52,7 @@ MCSymbol *MachineBasicBlock::getSymbol()
     const MachineFunction *MF = getParent();
     MCContext &Ctx = MF->getContext();
     const char *Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
+    assert(getNumber() >= 0 && "cannot get label for unreachable MBB");
     CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" +
                                            Twine(MF->getFunctionNumber()) +
                                            "_" + Twine(getNumber()));

Added: llvm/trunk/test/CodeGen/X86/catchret-empty-fallthrough.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/catchret-empty-fallthrough.ll?rev=252822&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/catchret-empty-fallthrough.ll (added)
+++ llvm/trunk/test/CodeGen/X86/catchret-empty-fallthrough.ll Wed Nov 11 17:09:31 2015
@@ -0,0 +1,53 @@
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
+
+; BranchFolding used to remove our empty landingpad block, which is
+; undesirable.
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+declare i32 @__C_specific_handler(...)
+
+declare void @bar()
+
+define void @foo(i1 %cond) personality i32 (...)* @__C_specific_handler {
+entry:
+  br i1 %cond, label %return, label %try
+
+try:                                              ; preds = %entry
+  invoke void @bar()
+          to label %fallthrough unwind label %dispatch
+
+dispatch:                                         ; preds = %try
+  %0 = catchpad [i8* null]
+          to label %catch unwind label %catchendblock.i.i
+
+catch:                                            ; preds = %dispatch
+  catchret %0 to label %return
+
+catchendblock.i.i:                                ; preds = %dispatch
+  catchendpad unwind to caller
+
+fallthrough:                                      ; preds = %try
+  unreachable
+
+return:                                           ; preds = %catch, %entry
+  ret void
+}
+
+; CHECK-LABEL: foo: # @foo
+; CHECK: testb $1, %cl
+; CHECK: jne .LBB0_[[return:[0-9]+]]
+; CHECK: .Ltmp0:
+; CHECK: callq bar
+; CHECK: .Ltmp1:
+; CHECK: .LBB0_[[catch:[0-9]+]]:
+; CHECK: .LBB0_[[return]]:
+
+; CHECK: .seh_handlerdata
+; CHECK-NEXT: .long   (.Llsda_end0-.Llsda_begin0)/16
+; CHECK-NEXT: .Llsda_begin0:
+; CHECK-NEXT: .long   .Ltmp0 at IMGREL+1
+; CHECK-NEXT: .long   .Ltmp1 at IMGREL+1
+; CHECK-NEXT: .long   1
+; CHECK-NEXT: .long   .LBB0_[[catch]]@IMGREL




More information about the llvm-commits mailing list