[PATCH] D46923: [MachineOutliner] Don't save/restore LR for tail calls.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 18:45:26 PDT 2018


efriedma created this revision.
efriedma added a reviewer: paquette.
Herald added a reviewer: javed.absar.

The cost computation correctly assumes we do this, but the actual lowering was wrong.


Repository:
  rL LLVM

https://reviews.llvm.org/D46923

Files:
  lib/Target/AArch64/AArch64InstrInfo.cpp
  test/CodeGen/AArch64/machine-outliner-tail.ll


Index: test/CodeGen/AArch64/machine-outliner-tail.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/machine-outliner-tail.ll
@@ -0,0 +1,22 @@
+; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple=aarch64-linux-gnu < %s | FileCheck %s
+
+; CHECK: OUTLINED_FUNCTION_0:
+; CHECK:      orr     w0, wzr, #0x1
+; CHECK-NEXT: orr     w1, wzr, #0x2
+; CHECK-NEXT: orr     w2, wzr, #0x3
+; CHECK-NEXT: orr     w3, wzr, #0x4
+; CHECK-NEXT: b       z
+
+define void @a() {
+entry:
+  tail call void @z(i32 1, i32 2, i32 3, i32 4)
+  ret void
+}
+
+declare void @z(i32, i32, i32, i32)
+
+define dso_local void @b(i32* nocapture readnone %p) {
+entry:
+  tail call void @z(i32 1, i32 2, i32 3, i32 4)
+  ret void
+}
Index: lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- lib/Target/AArch64/AArch64InstrInfo.cpp
+++ lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -5267,10 +5267,11 @@
 void AArch64InstrInfo::insertOutlinerEpilogue(
     MachineBasicBlock &MBB, MachineFunction &MF,
     const MachineOutlinerInfo &MInfo) const {
-
   // Is there a call in the outlined range?
-  if (std::any_of(MBB.instr_begin(), MBB.instr_end(),
-                  [](MachineInstr &MI) { return MI.isCall(); })) {
+  auto IsNonTailCall = [](MachineInstr &MI) {
+    return MI.isCall() && !MI.isReturn();
+  };
+  if (std::any_of(MBB.instr_begin(), MBB.instr_end(), IsNonTailCall)) {
     // Fix up the instructions in the range, since we're going to modify the
     // stack.
     fixupPostOutline(MBB);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46923.146980.patch
Type: text/x-patch
Size: 1609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180516/38a84fca/attachment.bin>


More information about the llvm-commits mailing list