[llvm] r249069 - [WinEH] Stop BranchFolding from merging across funclets

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 14:04:13 PDT 2015


Author: majnemer
Date: Thu Oct  1 16:04:13 2015
New Revision: 249069

URL: http://llvm.org/viewvc/llvm-project?rev=249069&view=rev
Log:
[WinEH] Stop BranchFolding from merging across funclets

BranchFolding would merge two funclets together, this is not OK.
Disable this and strengthen the assertion in FuncletLayout.

Modified:
    llvm/trunk/lib/CodeGen/BranchFolding.cpp
    llvm/trunk/lib/CodeGen/FuncletLayout.cpp
    llvm/trunk/test/CodeGen/X86/funclet-layout.ll

Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=249069&r1=249068&r2=249069&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Thu Oct  1 16:04:13 2015
@@ -94,9 +94,11 @@ bool BranchFolderPass::runOnMachineFunct
 
   TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
   // TailMerge can create jump into if branches that make CFG irreducible for
-  // HW that requires structurized CFG.
+  // HW that requires structurized CFG.  It can also cause BBs to get shared
+  // between funclets.
   bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() &&
-      PassConfig->getEnableTailMerge();
+                         !MF.getMMI().hasEHFunclets() &&
+                         PassConfig->getEnableTailMerge();
   BranchFolder Folder(EnableTailMerge, /*CommonHoist=*/true,
                       getAnalysis<MachineBlockFrequencyInfo>(),
                       getAnalysis<MachineBranchProbabilityInfo>());

Modified: llvm/trunk/lib/CodeGen/FuncletLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/FuncletLayout.cpp?rev=249069&r1=249068&r2=249069&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/FuncletLayout.cpp (original)
+++ llvm/trunk/lib/CodeGen/FuncletLayout.cpp Thu Oct  1 16:04:13 2015
@@ -39,17 +39,9 @@ collectFuncletMembers(DenseMap<MachineBa
                       int Funclet, MachineBasicBlock *MBB) {
   // Don't revisit blocks.
   if (FuncletMembership.count(MBB) > 0) {
-    // FIXME: This is a hack, we need to assert this unconditionally.
-    bool IsProbablyUnreachableBlock =
-        MBB->empty() ||
-        (MBB->succ_empty() && !MBB->getFirstTerminator()->isReturn() &&
-         MBB->size() == 1);
-
-    if (!IsProbablyUnreachableBlock) {
-      if (FuncletMembership[MBB] != Funclet) {
-        assert(false && "MBB is part of two funclets!");
-        report_fatal_error("MBB is part of two funclets!");
-      }
+    if (FuncletMembership[MBB] != Funclet) {
+      assert(false && "MBB is part of two funclets!");
+      report_fatal_error("MBB is part of two funclets!");
     }
     return;
   }

Modified: llvm/trunk/test/CodeGen/X86/funclet-layout.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/funclet-layout.ll?rev=249069&r1=249068&r2=249069&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/funclet-layout.ll (original)
+++ llvm/trunk/test/CodeGen/X86/funclet-layout.ll Thu Oct  1 16:04:13 2015
@@ -4,6 +4,10 @@ target datalayout = "e-m:w-i64:64-f80:12
 target triple = "x86_64-pc-windows-msvc"
 
 %eh.ThrowInfo = type { i32, i32, i32, i32 }
+%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
+
+@"\01??_7type_info@@6B@" = external constant i8*
+@"\01??_R0H at 8" = internal global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }
 
 define void @test1(i1 %B) personality i32 (...)* @__CxxFrameHandler3 {
 entry:
@@ -38,7 +42,7 @@ unreachable:
 ; CHECK: retq
 
 ; The catch funclet contains %catch and %catchret
-; CHECK: # %catch
+; CHECK: # %catch{{$}}
 ; CHECK: # %catchret
 ; CHECK: retq
 
@@ -94,9 +98,54 @@ unreachable:
 ; CHECK: retq
 
 ; The outer catch funclet contains %catch and %try.cont
-; CHECK: # %catch
+; CHECK: # %catch{{$}}
+; CHECK: # %try.cont{{$}}
+; CHECK: retq
+
+
+define void @test3() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
+entry:
+  invoke void @g()
+          to label %try.cont unwind label %catch.dispatch
+
+catch.dispatch:                                   ; preds = %entry
+  %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H at 8", i32 0, i8* null]
+          to label %catch.2 unwind label %catch.dispatch.1
+
+catch.2:                                          ; preds = %catch.dispatch
+  tail call void @exit(i32 0) #2
+  unreachable
+
+catch.dispatch.1:                                 ; preds = %catch.dispatch
+  %1 = catchpad [i8* null, i32 64, i8* null]
+          to label %catch unwind label %catchendblock
+
+catch:                                            ; preds = %catch.dispatch.1
+  tail call void @exit(i32 0) #2
+  unreachable
+
+catchendblock:                                    ; preds = %catch.dispatch.1
+  catchendpad unwind to caller
+
+try.cont:                                         ; preds = %entry
+  ret void
+}
+
+; CHECK-LABEL: test3:
+
+; The entry funclet contains %entry and %try.cont
+; CHECK: # %entry
 ; CHECK: # %try.cont
 ; CHECK: retq
 
+; The catch(int) funclet contains %catch.2
+; CHECK: # %catch.2
+; CHECK: callq exit
+
+; The catch(...) funclet contains %catch
+; CHECK: # %catch{{$}}
+; CHECK: callq exit
+
+declare void @exit(i32) noreturn nounwind
 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
 declare i32 @__CxxFrameHandler3(...)




More information about the llvm-commits mailing list