Skip to content

PEI clobbers live EFLAGS when using "probe-stack"="inline-asm" #49509

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

Closed
llvmbot opened this issue Apr 29, 2021 · 2 comments
Closed

PEI clobbers live EFLAGS when using "probe-stack"="inline-asm" #49509

llvmbot opened this issue Apr 29, 2021 · 2 comments
Labels
backend:X86 bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Member

llvmbot commented Apr 29, 2021

Bugzilla Link 50165
Version trunk
OS Linux
Attachments positdiv32 LLVM IR
Reporter LLVM Bugzilla Contributor
CC @alex,@topperc,@cuviper,@RKSimon,@phoebewang,@rotateright

Extended Description

When building attached llvm IR the eflags used by
liveins: $edi, $eflags, $esi
renamable $r15b = SETCCr 8, implicit $eflags

are clobbered after prologue insertion:
$rsp = frame-setup SUB64ri8 $rsp(tied-def 0), 8, implicit-def dead $eflags
renamable $r15b = SETCCr 8, implicit $eflags

Before Prologue/Epilogue Insertion & Frame Finalization (prologepilog)

bb.4.bb16.i:
; predecessors: %bb.2
successors: %bb.8(0x40000000), %bb.5(0x40000000); %bb.8(50.00%), %bb.5(50.00%)
liveins: $edi, $eflags, $esi
renamable $r15b = SETCCr 8, implicit $eflags
TEST32rr renamable $esi, renamable $esi, implicit-def $eflags
renamable $r14b = SETCCr 8, implicit $eflags
renamable $edx = COPY renamable $edi, implicit-def $rdx
renamable $edx = NEG32r renamable $edx(tied-def 0), implicit-def $eflags, implicit killed $rdx, implicit-def $rdx
renamable $edx = CMOV32rr renamable $edx(tied-def 0), killed renamable $edi, 12, implicit $eflags, implicit killed $rdx, implicit-def $rdx
renamable $eax = COPY renamable $esi, implicit-def $rax
renamable $eax = NEG32r renamable $eax(tied-def 0), implicit-def $eflags, implicit killed $rax, implicit-def $rax
renamable $eax = CMOV32rr renamable $eax(tied-def 0), killed renamable $esi, 12, implicit $eflags, implicit killed $rax, implicit-def $rax
renamable $ecx = LEA64_32r $noreg, 4, renamable $rdx, 0, $noreg, implicit-def $rcx
TEST32ri renamable $edx, 1073741824, implicit-def $eflags, implicit killed $rdx
JCC_1 %bb.8, 4, implicit $eflags
JMP_1 %bb.5

After Prologue/Epilogue Insertion & Frame Finalization (prologepilog):

bb.4.bb16.i:
; predecessors: %bb.2
successors: %bb.8(0x40000000), %bb.5(0x40000000); %bb.8(50.00%), %bb.5(50.00%)
liveins: $edi, $eflags, $esi, $rbp, $r15, $r14, $rbx
frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp
frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
$rsp = frame-setup SUB64ri8 $rsp(tied-def 0), 8, implicit-def dead $eflags
renamable $r15b = SETCCr 8, implicit $eflags
TEST32rr renamable $esi, renamable $esi, implicit-def $eflags
renamable $r14b = SETCCr 8, implicit $eflags
renamable $edx = COPY renamable $edi, implicit-def $rdx
renamable $edx = NEG32r renamable $edx(tied-def 0), implicit-def $eflags, implicit killed $rdx, implicit-def $rdx
renamable $edx = CMOV32rr renamable $edx(tied-def 0), killed renamable $edi, 12, implicit $eflags, implicit killed $rdx, implicit-def $rdx
renamable $eax = COPY renamable $esi, implicit-def $rax
renamable $eax = NEG32r renamable $eax(tied-def 0), implicit-def $eflags, implicit killed $rax, implicit-def $rax
renamable $eax = CMOV32rr renamable $eax(tied-def 0), killed renamable $esi, 12, implicit $eflags, implicit killed $rax, implicit-def $rax
renamable $ecx = LEA64_32r $noreg, 4, renamable $rdx, 0, $noreg, implicit-def $rcx
TEST32ri renamable $edx, 1073741824, implicit-def $eflags, implicit killed $rdx
JCC_1 %bb.8, 4, implicit $eflags
JMP_1 %bb.5

Originally reported in rust-lang/rust#84667

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@erikdesjardins
Copy link
Member

Godbolt: https://godbolt.org/z/ns7xKjq8e

@cuviper
Copy link
Member

cuviper commented Sep 22, 2022

Here's a minimization from llvm-reduce: reduced.ll

The clobbering can be seen here, subq followed by sets that wanted the previous flags:

# %bb.0:                                # %bb13.i
        testl   %edi, %edi
        je      .LBB0_1
# %bb.2:                                # %bb16.i
        pushq   %rbp
        pushq   %rbx
        subq    $8, %rsp
        sets    %bl

I'm working on a patch for canUseAsPrologue to return false for blocks with live EFLAGS when stack probes are enabled.

veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

3 participants