Skip to content

[MachineLICM] Recognize registers clobbered at EH landing pad entry #122446

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

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop,
if (const uint32_t *Mask = BB->getBeginClobberMask(TRI))
applyBitsNotInRegMaskToRegUnitsMask(*TRI, RUClobbers, Mask);

// EH landing pads clobber exception pointer/selector registers.
if (BB->isEHPad()) {
const MachineFunction &MF = *BB->getParent();
const Constant *PersonalityFn = MF.getFunction().getPersonalityFn();
const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
if (MCRegister Reg = TLI.getExceptionPointerRegister(PersonalityFn))
for (MCRegUnit Unit : TRI->regunits(Reg))
RUClobbers.set(Unit);
if (MCRegister Reg = TLI.getExceptionSelectorRegister(PersonalityFn))
for (MCRegUnit Unit : TRI->regunits(Reg))
RUClobbers.set(Unit);
}

SpeculationState = SpeculateUnknown;
for (MachineInstr &MI : *BB)
ProcessMI(&MI, RUDefs, RUClobbers, StoredFIs, Candidates, CurLoop);
Expand Down
59 changes: 59 additions & 0 deletions llvm/test/CodeGen/SystemZ/pr122315.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; Verify that MachineLICM recognizes that EH landing pad entry clobbers %r6/%r7
;
; RUN: llc < %s -verify-machineinstrs -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s

declare i64 @personality(i64, i64, i64, ptr, ptr)
declare void @callee(i64, i64, i64, i64, i64)
declare void @panic()

define void @test() uwtable personality ptr @personality {
; CHECK-LABEL: test:
; CHECK: .Lfunc_begin0:
; CHECK-NEXT: .cfi_startproc
; CHECK-NEXT: .cfi_personality 0, personality
; CHECK-NEXT: .cfi_lsda 0, .Lexception0
; CHECK-NEXT: # %bb.0: # %start
; CHECK-NEXT: stmg %r6, %r15, 48(%r15)
; CHECK-NEXT: .cfi_offset %r6, -112
; CHECK-NEXT: .cfi_offset %r7, -104
; CHECK-NEXT: .cfi_offset %r14, -48
; CHECK-NEXT: .cfi_offset %r15, -40
; CHECK-NEXT: aghi %r15, -160
; CHECK-NEXT: .cfi_def_cfa_offset 320
; CHECK-NEXT: .LBB0_1: # %bb1
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: lghi %r2, 0
; CHECK-NEXT: lghi %r3, 0
; CHECK-NEXT: lghi %r4, 0
; CHECK-NEXT: lghi %r5, 0
; CHECK-NEXT: lghi %r6, 0
; CHECK-NEXT: brasl %r14, callee@PLT
; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: brasl %r14, panic@PLT
; CHECK-NEXT: .Ltmp1:
; CHECK-NEXT: j .LBB0_3
; CHECK-NEXT: .LBB0_2: # %bb3
; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
; CHECK-NEXT: .Ltmp2:
; CHECK-NEXT: j .LBB0_1
; CHECK-NEXT: .LBB0_3: # %bb2
; CHECK-NEXT: lmg %r6, %r15, 208(%r15)
; CHECK-NEXT: br %r14
start:
br label %bb1

bb1:
call void @callee(i64 0, i64 0, i64 0, i64 0, i64 0)
invoke void @panic()
to label %bb2 unwind label %bb3

bb2:
ret void

bb3:
%lp = landingpad { ptr, i32 }
catch ptr null
br label %bb1
}

Loading