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

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 8 17:44:52 PDT 2021


Author: Jessica Paquette
Date: 2021-09-08T17:44:27-07:00
New Revision: 22a64d4a143d0d549cc762e1a19260078d1836c2

URL: https://github.com/llvm/llvm-project/commit/22a64d4a143d0d549cc762e1a19260078d1836c2
DIFF: https://github.com/llvm/llvm-project/commit/22a64d4a143d0d549cc762e1a19260078d1836c2.diff

LOG: [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.

Added: 
    llvm/test/CodeGen/AArch64/machine-outliner-create-lr-livein.mir

Modified: 
    llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 289e453e112dc..382360feb67ad 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -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)

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner-create-lr-livein.mir b/llvm/test/CodeGen/AArch64/machine-outliner-create-lr-livein.mir
new file mode 100644
index 0000000000000..f1f34f5c4b25a
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-create-lr-livein.mir
@@ -0,0 +1,50 @@
+# 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


        


More information about the llvm-commits mailing list