-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[X86] Fix RegAlloc issue by implementing TRI::getCustomEHPadPreservedMask #135518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
s-barannikov
wants to merge
3
commits into
llvm:main
Choose a base branch
from
s-barannikov:sjlj/x86-unwind-clobber
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc -mtriple=x86_64 -exception-model=sjlj -o - %s | FileCheck %s | ||
|
|
||
| declare i32 @__gxx_personality_sj0(...) | ||
| declare preserve_allcc void @foo(ptr) | ||
|
|
||
| ; Check that register allocator splits live ranges of loop invariant virtual | ||
| ; registers as they don't survive the unwind edge of an invoke. | ||
| ; The argument of `foo` (passed in %rdi) and the address of the jump table | ||
| ; (base register of `jmpq`) are loop invariant. They survive the call to `foo`, | ||
| ; but are clobbered by the unwinder when `foo` throws an exception, and so | ||
| ; their live ranges must be split around the unwind edge `callq foo` -> LBB0_3. | ||
| ; This is achieved by recalculating their values before each use rather than | ||
| ; once before the loop as was the case before register allocation. | ||
|
|
||
s-barannikov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| define void @test() personality ptr @__gxx_personality_sj0 { | ||
| ; CHECK-LABEL: test: | ||
| ; CHECK: # %bb.0: # %entry | ||
| ; CHECK-NEXT: pushq %rbp | ||
| ; CHECK-NEXT: movq %rsp, %rbp | ||
| ; CHECK-NEXT: pushq %r15 | ||
| ; CHECK-NEXT: pushq %r14 | ||
| ; CHECK-NEXT: pushq %r13 | ||
| ; CHECK-NEXT: pushq %r12 | ||
| ; CHECK-NEXT: pushq %rbx | ||
| ; CHECK-NEXT: subq $104, %rsp | ||
| ; CHECK-NEXT: movq __gxx_personality_sj0@GOTPCREL(%rip), %rax | ||
| ; CHECK-NEXT: movq %rax, -104(%rbp) | ||
| ; CHECK-NEXT: movq $GCC_except_table0, -96(%rbp) | ||
| ; CHECK-NEXT: movq %rbp, -88(%rbp) | ||
| ; CHECK-NEXT: movq %rsp, -72(%rbp) | ||
| ; CHECK-NEXT: movq $.LBB0_3, -80(%rbp) | ||
| ; CHECK-NEXT: leaq -136(%rbp), %rdi | ||
| ; CHECK-NEXT: callq _Unwind_SjLj_Register@PLT | ||
| ; CHECK-NEXT: leaq -44(%rbp), %rcx | ||
| ; CHECK-NEXT: .LBB0_1: # %while.cond | ||
| ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1 | ||
| ; CHECK-NEXT: movl $1, -128(%rbp) | ||
| ; CHECK-NEXT: .Ltmp0: | ||
| ; CHECK-NEXT: movq %rcx, %rdi | ||
| ; CHECK-NEXT: callq foo@PLT | ||
| ; CHECK-NEXT: .Ltmp1: | ||
| ; CHECK-NEXT: jmp .LBB0_2 | ||
| ; CHECK-NEXT: .LBB0_3: # in Loop: Header=BB0_1 Depth=1 | ||
| ; CHECK-NEXT: leaq -44(%rbp), %rcx | ||
| ; CHECK-NEXT: movl -128(%rbp), %eax | ||
| ; CHECK-NEXT: cmpl $1, %eax | ||
| ; CHECK-NEXT: jae .LBB0_5 | ||
| ; CHECK-NEXT: # %bb.4: # in Loop: Header=BB0_1 Depth=1 | ||
| ; CHECK-NEXT: leaq .LJTI0_0(%rip), %rdx | ||
| ; CHECK-NEXT: jmpq *(%rdx,%rax,8) | ||
| ; CHECK-NEXT: .LBB0_6: # %lpad | ||
| ; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1 | ||
| ; CHECK-NEXT: .Ltmp2: | ||
| ; CHECK-NEXT: movl -124(%rbp), %eax | ||
| ; CHECK-NEXT: movl -120(%rbp), %eax | ||
| ; CHECK-NEXT: jmp .LBB0_1 | ||
| ; CHECK-NEXT: .LBB0_2: # %while.end | ||
| ; CHECK-NEXT: leaq -136(%rbp), %rdi | ||
| ; CHECK-NEXT: callq _Unwind_SjLj_Unregister@PLT | ||
| ; CHECK-NEXT: addq $104, %rsp | ||
| ; CHECK-NEXT: popq %rbx | ||
| ; CHECK-NEXT: popq %r12 | ||
| ; CHECK-NEXT: popq %r13 | ||
| ; CHECK-NEXT: popq %r14 | ||
| ; CHECK-NEXT: popq %r15 | ||
| ; CHECK-NEXT: popq %rbp | ||
| ; CHECK-NEXT: retq | ||
| ; CHECK-NEXT: .LBB0_5: | ||
| ; CHECK-NEXT: ud2 | ||
| entry: | ||
| %ptr = alloca i32, align 4 | ||
| br label %while.cond | ||
|
|
||
| while.cond: | ||
| invoke preserve_allcc void @foo(ptr %ptr) | ||
| to label %while.end unwind label %lpad | ||
|
|
||
| lpad: | ||
| %lp = landingpad { ptr, i32 } | ||
| catch ptr null | ||
| br label %while.cond | ||
|
|
||
| while.end: | ||
| ret void | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not familar with SjLj. Is the following the same rule on both Linux and Windows?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! I never thought about supporting SJLJ on Windows, but I think it should be the same there.
Unlike DWARF unwinder, SJLJ implementation does not actually unwind the stack (does not step through frames), it just does
__builtin_longjmpto the dispatch block. The builtin only restores program counter and stack pointer(s), as that is all that is saved at the beginning of each function that can potentially throw an exception. (Saving all registers at the beginning of each function would be too expensive.)Also, there is a related workaround that adds the same "no-preserved" mask to an arbitrary instruction in the dispatch block. (It should be removed and any remaining issues fixed in the generic code, but I'm hesitant to do this as test SJLJ test coverage is pretty poor.)
Apparently, the link doesn't work, look for
in
X86ISelLowering.cpp