[llvm] e8bc77e - [MachineOutliner] Fix label outlining regression introduced in D125072
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 30 11:45:46 PDT 2023
Author: duk
Date: 2023-03-30T14:43:12-04:00
New Revision: e8bc77ec085cf23a743bf203d526000df8f45946
URL: https://github.com/llvm/llvm-project/commit/e8bc77ec085cf23a743bf203d526000df8f45946
DIFF: https://github.com/llvm/llvm-project/commit/e8bc77ec085cf23a743bf203d526000df8f45946.diff
LOG: [MachineOutliner] Fix label outlining regression introduced in D125072
Due to a change in the APIs used to determine what instructions can be outlined, the check for label outling was never hit. Instead, all labels were considered invisible, which is the opposite of the intended behavior and causes obscure crashes down the line. We now replicate the original behavior more closely, with explicit checks for known-good and known-bad instruction types.
Reviewed by: paquette
Differential Revision: https://reviews.llvm.org/D147178
Added:
llvm/test/CodeGen/AArch64/machine-outliner-labels.mir
Modified:
llvm/lib/CodeGen/TargetInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index e50c9222b1ff..5c5b6a07356d 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -1579,10 +1579,6 @@ outliner::InstrType TargetInstrInfo::getOutliningType(
// Just go right to the target implementation.
return getOutliningTypeImpl(MIT, Flags);
- // Don't allow instructions that don't materialize to impact analysis.
- if (MI.isMetaInstruction())
- return outliner::InstrType::Invisible;
-
// Be conservative about inline assembly.
if (MI.isInlineAsm())
return outliner::InstrType::Illegal;
@@ -1591,6 +1587,21 @@ outliner::InstrType TargetInstrInfo::getOutliningType(
if (MI.isLabel())
return outliner::InstrType::Illegal;
+ // Don't let debug instructions impact analysis.
+ if (MI.isDebugInstr())
+ return outliner::InstrType::Invisible;
+
+ // Some other special cases.
+ switch (MI.getOpcode()) {
+ case TargetOpcode::IMPLICIT_DEF:
+ case TargetOpcode::KILL:
+ case TargetOpcode::LIFETIME_START:
+ case TargetOpcode::LIFETIME_END:
+ return outliner::InstrType::Invisible;
+ default:
+ break;
+ }
+
// Is this a terminator for a basic block?
if (MI.isTerminator()) {
// If this is a branch to another block, we can't outline it.
diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-labels.mir b/llvm/test/CodeGen/AArch64/machine-outliner-labels.mir
new file mode 100644
index 000000000000..a38e1803cfb6
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-labels.mir
@@ -0,0 +1,49 @@
+# RUN: llc -mtriple aarch64 -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
+# CHECK-NOT: OUTLINED_FUNCTION
+
+...
+---
+name: foo1
+tracksRegLiveness: true
+machineFunctionInfo:
+ hasRedZone: false
+body: |
+ bb.0:
+ liveins: $x0
+ $x0 = ADDXri $x0, 0, 0
+ EH_LABEL <mcsymbol .Ltmp0>
+ EH_LABEL <mcsymbol .Ltmp1>
+ EH_LABEL <mcsymbol .Ltmp2>
+ EH_LABEL <mcsymbol .Ltmp3>
+ RET_ReallyLR implicit $x0
+...
+---
+name: foo2
+tracksRegLiveness: true
+machineFunctionInfo:
+ hasRedZone: false
+body: |
+ bb.0:
+ liveins: $x0
+ $x0 = ADDXri $x0, 0, 0
+ EH_LABEL <mcsymbol .Ltmp0>
+ EH_LABEL <mcsymbol .Ltmp1>
+ EH_LABEL <mcsymbol .Ltmp2>
+ EH_LABEL <mcsymbol .Ltmp3>
+ RET_ReallyLR implicit $x0
+...
+---
+name: foo3
+tracksRegLiveness: true
+machineFunctionInfo:
+ hasRedZone: false
+body: |
+ bb.0:
+ liveins: $x0
+ $x0 = ADDXri $x0, 0, 0
+ EH_LABEL <mcsymbol .Ltmp0>
+ EH_LABEL <mcsymbol .Ltmp1>
+ EH_LABEL <mcsymbol .Ltmp2>
+ EH_LABEL <mcsymbol .Ltmp3>
+ RET_ReallyLR implicit $x0
+...
More information about the llvm-commits
mailing list