[PATCH] D154294: [Windows SEH]: Do not fold branches for MSVC TableSEH function

Phoebe Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 08:02:15 PDT 2023


pengfei added a comment.

Thanks @efriedma and @rnk for the comments. And sorry just get time to look at back.

I haven't fully understand the algorithm in BranchFolding.cpp, but guess the problem might be related to the jumping edge issue @efriedma mentioned on https://reviews.llvm.org/D102817#3487499

> can you point at the MBB references that become stale with branchfolding? I think we mainly hold references to EHPad MBBs, which branch folding should ignore, but let me know if I'm wrong.

The EHPad BB (bb.4) is removed by https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/BranchFolding.cpp#L1218

At the beginning, bb.4 has a predecessor bb.3. However, since bb.1, bb.2, bb.3 are just empty BB with fallthrough (and probably due to we don't model their jumping edge bb.7, bb.6, bb.4 respectively), they will be merged to bb.5 finally. Then bb.4 will become an orphan BB and be removed by the code above.

I tried to modify some code in this pass or set BlockAddressTaken for the EHPad BB. Neither solve my problem.

Here are the MIR before the pass. Suggestions are welcome. But I'd prefer to land this patch to solve the problem first if the root cause is hard to fix.

  # Machine code for function main: NoPHIs, TracksLiveness, NoVRegs, TiedOpsRewritten, TracksDebugUserValues
  Frame Objects:
    fi#-1: size=8, align=16, fixed, at location [SP-8]
  
  bb.0.entry:
    successors: %bb.1(0x40000000), %bb.7(0x40000000); %bb.1(50.00%), %bb.7(50.00%)
  
    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
    frame-setup SEH_PushReg 52
    $rbp = MOV64rr $rsp
    frame-setup SEH_SetFrame 52, 0
    frame-setup SEH_EndPrologue
    JMP_1 %bb.1
  
  bb.1.invoke.cont:
  ; predecessors: %bb.0
    successors: %bb.2(0x40000000), %bb.7(0x40000000); %bb.2(50.00%), %bb.7(50.00%)
  
    JMP_1 %bb.2
  
  bb.2.invoke.cont1:
  ; predecessors: %bb.1
    successors: %bb.3(0x2aaaaaab), %bb.6(0x2aaaaaab), %bb.7(0x2aaaaaab); %bb.3(33.33%), %bb.6(33.33%), %bb.7(33.33%)
  
    JMP_1 %bb.3
  
  bb.3.invoke.cont2:
  ; predecessors: %bb.2
    successors: %bb.5(0x00000000), %bb.4(0x2aaaaaab), %bb.6(0x2aaaaaab), %bb.7(0x2aaaaaab); %bb.5(0.00%), %bb.4(33.33%), %bb.6(33.33%), %bb.7(33.33%)
  
    JMP_1 %bb.5
  
  bb.4.__except (landing-pad):
  ; predecessors: %bb.3
  
  
  bb.5.invoke.cont4:
  ; predecessors: %bb.3
  
    EH_LABEL <mcsymbol .Ltmp0>
    MOV32mi undef renamable $rax, 1, $noreg, 0, $noreg, 1 :: (volatile store (s32) into `ptr poison`)
    EH_LABEL <mcsymbol .Ltmp1>
  
  bb.6.__except11 (landing-pad):
  ; predecessors: %bb.2, %bb.3
  
  
  bb.7.ehcleanup (machine-block-address-taken, landing-pad, ehfunclet-entry):
  ; predecessors: %bb.0, %bb.1, %bb.2, %bb.3
    liveins: $rdx
    frame-setup MOV64mr killed $rsp, 1, $noreg, 16, $noreg, $rdx
    frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
    frame-setup SEH_PushReg 52
    $rbp = MOV64rr $rdx
    frame-setup SEH_EndPrologue
    SEH_Epilogue
    $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp
    CLEANUPRET
  
  # End machine code for function main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154294



More information about the llvm-commits mailing list