Commit 22a64d4a authored by Jessica Paquette's avatar Jessica Paquette
Browse files

[MachineOutliner][AArch64] Ensure LR is live-in when inserting reg-save calls

Similar to other code which handles creating the function frame.

If LR isn't live-in to the block that we're inserting the call into, we'll get
a MachineVerifier error.
parent eae44c8a
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -7350,7 +7350,11 @@ MachineBasicBlock::iterator AArch64InstrInfo::insertOutlinedCall(
    unsigned Reg = findRegisterToSaveLRTo(C);
    assert(Reg != 0 && "No callee-saved register available?");

    // Save and restore LR from that register.
    // LR has to be a live in so that we can save it.
    if (!MBB.isLiveIn(AArch64::LR))
      MBB.addLiveIn(AArch64::LR);

    // Save and restore LR from Reg.
    Save = BuildMI(MF, DebugLoc(), get(AArch64::ORRXrs), Reg)
               .addReg(AArch64::XZR)
               .addReg(AArch64::LR)
+50 −0
Original line number Diff line number Diff line
# RUN: llc -mtriple=aarch64-apple-darwin -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
# In bb.4,  we save + restore LR using a register. We need LR to be live-in to
# the block to prevent MachineVerifier errors.

name:            lr_not_live_in
tracksRegLiveness: true
fixedStack:
machineFunctionInfo:
  hasRedZone:      false
body:             |
  bb.0:
    $x9 = ORRXri $xzr, 1
  bb.1:
    liveins: $w9
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 2
  bb.2:
    liveins: $w9
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 2
  bb.3:
    liveins: $w9
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 2
  bb.4:
    liveins: $w9
    ; CHECK-LABEL: bb.4
    ; CHECK: liveins: $w9, $lr
    ; CHECK: BL
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 1
    $w9 = ORRWri $wzr, 2
  bb.5:
    liveins: $w9, $lr
    RET undef $lr