[llvm] r373791 - [MachineOutliner] Disable outlining from noreturn functions

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 14:24:12 PDT 2019


Author: paquette
Date: Fri Oct  4 14:24:12 2019
New Revision: 373791

URL: http://llvm.org/viewvc/llvm-project?rev=373791&view=rev
Log:
[MachineOutliner] Disable outlining from noreturn functions

Outlining from noreturn functions doesn't do the correct thing right now. The
outliner should respect that the caller is marked noreturn. In the event that
we have a noreturn function, and the outlined code is in tail position, the
outliner will not see that the outlined function should be tail called. As a
result, you end up with a regular call containing a return.

Fixing this requires that we check that all candidates live inside noreturn
functions. So, for the sake of correctness, don't outline from noreturn
functions right now.

Add machine-outliner-noreturn.mir to test this.

Added:
    llvm/trunk/test/CodeGen/AArch64/machine-outliner-noreturn.mir
Modified:
    llvm/trunk/lib/CodeGen/MachineOutliner.cpp

Modified: llvm/trunk/lib/CodeGen/MachineOutliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOutliner.cpp?rev=373791&r1=373790&r2=373791&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOutliner.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOutliner.cpp Fri Oct  4 14:24:12 2019
@@ -1303,6 +1303,12 @@ void MachineOutliner::populateMapper(Ins
     if (F.empty())
       continue;
 
+    // Disable outlining from noreturn functions right now. Noreturn requires
+    // special handling for the case where what we are outlining could be a
+    // tail call.
+    if (F.hasFnAttribute(Attribute::NoReturn))
+      continue;
+
     // There's something in F. Check if it has a MachineFunction associated with
     // it.
     MachineFunction *MF = MMI.getMachineFunction(F);

Added: llvm/trunk/test/CodeGen/AArch64/machine-outliner-noreturn.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-outliner-noreturn.mir?rev=373791&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-outliner-noreturn.mir (added)
+++ llvm/trunk/test/CodeGen/AArch64/machine-outliner-noreturn.mir Fri Oct  4 14:24:12 2019
@@ -0,0 +1,56 @@
+# RUN: llc -mtriple=aarch64-unknown-unknown -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
+
+--- |
+  define void @foo() #0 { ret void }
+  define void @bar(i32 %a) #0 { ret void }
+  define void @baz(i32 %a) #0 { ret void }
+  attributes #0 = { noredzone noreturn }
+...
+---
+
+# Temporarily disable outlining from noreturn functions. To do this, we need
+# to verify thst every function we want to outline from is noreturn.
+
+# CHECK-NOT: OUTLINED_FUNCTION
+
+name:            foo
+alignment:       4
+tracksRegLiveness: true
+frameInfo:
+  maxAlignment:    1
+  maxCallFrameSize: 0
+machineFunctionInfo: {}
+body:             |
+  bb.0:
+    $w3 = ORRWri $wzr, 1
+    $w4 = ORRWri $wzr, 1
+    BRK 1
+...
+---
+name:            bar
+alignment:       4
+tracksRegLiveness: true
+frameInfo:
+  maxAlignment:    1
+  maxCallFrameSize: 0
+machineFunctionInfo: {}
+body:             |
+  bb.0:
+    $w3 = ORRWri $wzr, 1
+    $w4 = ORRWri $wzr, 1
+    BRK 1
+...
+---
+name:            baz
+alignment:       4
+tracksRegLiveness: true
+frameInfo:
+  maxAlignment:    1
+  maxCallFrameSize: 0
+machineFunctionInfo: {}
+body:             |
+  bb.0:
+    $w3 = ORRWri $wzr, 1
+    $w4 = ORRWri $wzr, 1
+    BRK 1
+...




More information about the llvm-commits mailing list