[llvm] r332514 - [MachineOutliner] Don't save/restore LR for tail calls.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed May 16 12:49:01 PDT 2018


Author: efriedma
Date: Wed May 16 12:49:01 2018
New Revision: 332514

URL: http://llvm.org/viewvc/llvm-project?rev=332514&view=rev
Log:
[MachineOutliner] Don't save/restore LR for tail calls.

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

Differential Revision: https://reviews.llvm.org/D46923


Added:
    llvm/trunk/test/CodeGen/AArch64/machine-outliner-tail.ll
Modified:
    llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp

Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp?rev=332514&r1=332513&r2=332514&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp Wed May 16 12:49:01 2018
@@ -5255,10 +5255,11 @@ void AArch64InstrInfo::fixupPostOutline(
 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);

Added: llvm/trunk/test/CodeGen/AArch64/machine-outliner-tail.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-outliner-tail.ll?rev=332514&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-outliner-tail.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/machine-outliner-tail.ll Wed May 16 12:49:01 2018
@@ -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
+}




More information about the llvm-commits mailing list