-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[X86][NewPM] Port X86 FP Stackifier Pass to NewPM #167911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
boomanaiden154
merged 5 commits into
main
from
users/boomanaiden154/x86newpm-port-x86-fp-stackifier-pass-to-newpm
Nov 13, 2025
Merged
[X86][NewPM] Port X86 FP Stackifier Pass to NewPM #167911
boomanaiden154
merged 5 commits into
main
from
users/boomanaiden154/x86newpm-port-x86-fp-stackifier-pass-to-newpm
Nov 13, 2025
+93
−46
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.7 [skip ci]
Created using spr 1.3.7
Member
|
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-debuginfo Author: Aiden Grossman (boomanaiden154) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167911.diff 7 Files Affected:
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index 200ca80adb232..03706aaaab237 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -44,7 +44,13 @@ FunctionPass *createCleanupLocalDynamicTLSPass();
/// This function returns a pass which converts floating-point register
/// references and pseudo instructions into floating-point stack references and
/// physical instructions.
-FunctionPass *createX86FloatingPointStackifierPass();
+class X86FPStackifierPass : public PassInfoMixin<X86FPStackifierPass> {
+public:
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+};
+
+FunctionPass *createX86FPStackifierLegacyPass();
/// This pass inserts AVX vzeroupper instructions before each call to avoid
/// transition penalty between functions encoded with AVX and SSE.
@@ -229,7 +235,6 @@ FunctionPass *createX86ArgumentStackSlotPass();
FunctionPass *createX86SuppressAPXForRelocationPass();
void initializeCompressEVEXPassPass(PassRegistry &);
-void initializeFPSPass(PassRegistry &);
void initializeFixupBWInstPassPass(PassRegistry &);
void initializeFixupLEAPassPass(PassRegistry &);
void initializeX86ArgumentStackSlotPassPass(PassRegistry &);
@@ -246,6 +251,7 @@ void initializeX86DomainReassignmentPass(PassRegistry &);
void initializeX86DynAllocaExpanderLegacyPass(PassRegistry &);
void initializeX86ExecutionDomainFixPass(PassRegistry &);
void initializeX86ExpandPseudoPass(PassRegistry &);
+void initializeX86FPStackifierLegacyPass(PassRegistry &);
void initializeX86FastPreTileConfigPass(PassRegistry &);
void initializeX86FastTileConfigPass(PassRegistry &);
void initializeX86FixupSetCCPassPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86FloatingPoint.cpp b/llvm/lib/Target/X86/X86FloatingPoint.cpp
index bc9d354cd8e1a..6af2050d8b9d0 100644
--- a/llvm/lib/Target/X86/X86FloatingPoint.cpp
+++ b/llvm/lib/Target/X86/X86FloatingPoint.cpp
@@ -31,6 +31,8 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/EdgeBundles.h"
#include "llvm/CodeGen/LiveRegUnits.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -38,6 +40,7 @@
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/IR/Analysis.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
@@ -48,7 +51,7 @@
#include <bitset>
using namespace llvm;
-#define DEBUG_TYPE "x86-codegen"
+#define DEBUG_TYPE "x86-fp-stackifier"
STATISTIC(NumFXCH, "Number of fxch instructions inserted");
STATISTIC(NumFP, "Number of floating point instructions");
@@ -56,25 +59,10 @@ STATISTIC(NumFP, "Number of floating point instructions");
namespace {
const unsigned ScratchFPReg = 7;
-struct FPS : public MachineFunctionPass {
- static char ID;
- FPS() : MachineFunctionPass(ID) {}
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesCFG();
- AU.addRequired<EdgeBundlesWrapperLegacy>();
- AU.addPreservedID(MachineLoopInfoID);
- AU.addPreservedID(MachineDominatorsID);
- MachineFunctionPass::getAnalysisUsage(AU);
- }
-
- bool runOnMachineFunction(MachineFunction &MF) override;
-
- MachineFunctionProperties getRequiredProperties() const override {
- return MachineFunctionProperties().setNoVRegs();
- }
-
- StringRef getPassName() const override { return "X86 FP Stackifier"; }
+class FPS {
+public:
+ bool shouldRun(MachineFunction &MF);
+ bool run(MachineFunction &MF, EdgeBundles *EdgeBundles);
private:
const TargetInstrInfo *TII = nullptr; // Machine instruction info.
@@ -292,15 +280,43 @@ struct FPS : public MachineFunctionPass {
void setKillFlags(MachineBasicBlock &MBB) const;
};
+
+class X86FPStackifierLegacy : public MachineFunctionPass {
+public:
+ X86FPStackifierLegacy() : MachineFunctionPass(ID) {}
+
+ static char ID;
+
+private:
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesCFG();
+ AU.addRequired<EdgeBundlesWrapperLegacy>();
+ AU.addPreservedID(MachineLoopInfoID);
+ AU.addPreservedID(MachineDominatorsID);
+ MachineFunctionPass::getAnalysisUsage(AU);
+ }
+
+ bool runOnMachineFunction(MachineFunction &MF) override;
+
+ MachineFunctionProperties getRequiredProperties() const override {
+ return MachineFunctionProperties().setNoVRegs();
+ }
+
+ StringRef getPassName() const override { return "X86 FP Stackifier"; }
+};
} // namespace
-char FPS::ID = 0;
+char X86FPStackifierLegacy::ID = 0;
-INITIALIZE_PASS_BEGIN(FPS, DEBUG_TYPE, "X86 FP Stackifier", false, false)
+INITIALIZE_PASS_BEGIN(X86FPStackifierLegacy, DEBUG_TYPE, "X86 FP Stackifier",
+ false, false)
INITIALIZE_PASS_DEPENDENCY(EdgeBundlesWrapperLegacy)
-INITIALIZE_PASS_END(FPS, DEBUG_TYPE, "X86 FP Stackifier", false, false)
+INITIALIZE_PASS_END(X86FPStackifierLegacy, DEBUG_TYPE, "X86 FP Stackifier",
+ false, false)
-FunctionPass *llvm::createX86FloatingPointStackifierPass() { return new FPS(); }
+FunctionPass *llvm::createX86FPStackifierLegacyPass() {
+ return new X86FPStackifierLegacy();
+}
/// getFPReg - Return the X86::FPx register number for the specified operand.
/// For example, this returns 3 for X86::FP3.
@@ -311,28 +327,25 @@ static unsigned getFPReg(const MachineOperand &MO) {
return Reg - X86::FP0;
}
-/// runOnMachineFunction - Loop over all of the basic blocks, transforming FP
-/// register references into FP stack references.
-///
-bool FPS::runOnMachineFunction(MachineFunction &MF) {
+bool FPS::shouldRun(MachineFunction &MF) {
// We only need to run this pass if there are any FP registers used in this
// function. If it is all integer, there is nothing for us to do!
- bool FPIsUsed = false;
-
static_assert(X86::FP6 == X86::FP0 + 6,
"Register enums aren't sorted right!");
const MachineRegisterInfo &MRI = MF.getRegInfo();
- for (unsigned i = 0; i <= 6; ++i)
- if (!MRI.reg_nodbg_empty(X86::FP0 + i)) {
- FPIsUsed = true;
- break;
+ for (unsigned I = 0; I <= 6; ++I)
+ if (!MRI.reg_nodbg_empty(X86::FP0 + I)) {
+ return true;
}
- // Early exit.
- if (!FPIsUsed)
- return false;
+ return false;
+}
- Bundles = &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
+/// runOnMachineFunction - Loop over all of the basic blocks, transforming FP
+/// register references into FP stack references.
+///
+bool FPS::run(MachineFunction &MF, EdgeBundles *FunctionBundles) {
+ Bundles = FunctionBundles;
TII = MF.getSubtarget().getInstrInfo();
// Prepare cross-MBB liveness.
@@ -1812,3 +1825,29 @@ void FPS::setKillFlags(MachineBasicBlock &MBB) const {
LPR.stepBackward(MI);
}
}
+
+bool X86FPStackifierLegacy::runOnMachineFunction(MachineFunction &MF) {
+ FPS Impl;
+ if (!Impl.shouldRun(MF))
+ return false;
+
+ EdgeBundles *Bundles =
+ &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
+ return FPS().run(MF, Bundles);
+}
+
+PreservedAnalyses
+X86FPStackifierPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ FPS Impl;
+ if (!Impl.shouldRun(MF))
+ return PreservedAnalyses::all();
+
+ EdgeBundles *Bundles = &MFAM.getResult<EdgeBundlesAnalysis>(MF);
+ bool Changed = Impl.run(MF, Bundles);
+ if (!Changed)
+ return PreservedAnalyses::all();
+ PreservedAnalyses PA = PreservedAnalyses::none();
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
+}
diff --git a/llvm/lib/Target/X86/X86PassRegistry.def b/llvm/lib/Target/X86/X86PassRegistry.def
index 0d7095b18daa8..b80ad38c146df 100644
--- a/llvm/lib/Target/X86/X86PassRegistry.def
+++ b/llvm/lib/Target/X86/X86PassRegistry.def
@@ -31,6 +31,7 @@ DUMMY_FUNCTION_PASS("x86-winehstate", WinEHStatePass())
#endif
MACHINE_FUNCTION_PASS("x86-avoid-trailing-call", X86AvoidTrailingCallPass())
MACHINE_FUNCTION_PASS("x86-dyn-alloca-expander", X86DynAllocaExpanderPass())
+MACHINE_FUNCTION_PASS("x86-fp-stackifier", X86FPStackifierPass())
MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
#undef MACHINE_FUNCTION_PASS
@@ -40,7 +41,6 @@ MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
DUMMY_MACHINE_FUNCTION_PASS("x86-avoid-SFB", X86AvoidSFBPass())
DUMMY_MACHINE_FUNCTION_PASS("x86-cf-opt", X86CallFrameOptimization())
DUMMY_MACHINE_FUNCTION_PASS("x86-cmov-conversion", X86CmovConverterPass())
-DUMMY_MACHINE_FUNCTION_PASS("x86-codege", FPS())
DUMMY_MACHINE_FUNCTION_PASS("x86-compress-evex", CompressEVEXPass())
DUMMY_MACHINE_FUNCTION_PASS("x86-domain-reassignment", X86DomainReassignment())
DUMMY_MACHINE_FUNCTION_PASS("x86-execution-domain-fix", X86ExecutionDomainFix())
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index c1214149dfa1d..543220b2fd3b9 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -76,7 +76,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
initializeFixupBWInstPassPass(PR);
initializeCompressEVEXPassPass(PR);
initializeFixupLEAPassPass(PR);
- initializeFPSPass(PR);
+ initializeX86FPStackifierLegacyPass(PR);
initializeX86FixupSetCCPassPass(PR);
initializeX86CallFrameOptimizationPass(PR);
initializeX86CmovConverterPassPass(PR);
@@ -531,7 +531,7 @@ void X86PassConfig::addMachineSSAOptimization() {
void X86PassConfig::addPostRegAlloc() {
addPass(createX86LowerTileCopyPass());
- addPass(createX86FloatingPointStackifierPass());
+ addPass(createX86FPStackifierLegacyPass());
// When -O0 is enabled, the Load Value Injection Hardening pass will fall back
// to using the Speculative Execution Side Effect Suppression pass for
// mitigation. This is to prevent slow downs due to
diff --git a/llvm/test/CodeGen/X86/x87-stack-pop.mir b/llvm/test/CodeGen/X86/x87-stack-pop.mir
index 1c4ffa54b150f..73144fd484521 100644
--- a/llvm/test/CodeGen/X86/x87-stack-pop.mir
+++ b/llvm/test/CodeGen/X86/x87-stack-pop.mir
@@ -1,5 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
-# RUN: llc -mtriple=i686-- -run-pass x86-codegen -O2 -o - %s | FileCheck %s
+# RUN: llc -mtriple=i686-- -run-pass=x86-fp-stackifier -O2 -o - %s | FileCheck %s
+# RUN: llc -mtriple=i686-- -passes=x86-fp-stackifier -O2 -o - %s | FileCheck %s
---
name: func_fxam
diff --git a/llvm/test/DebugInfo/MIR/InstrRef/x86-fp-stackifier-drop-locations.mir b/llvm/test/DebugInfo/MIR/InstrRef/x86-fp-stackifier-drop-locations.mir
index be12082c45b9a..ed7a41cc7fc1d 100644
--- a/llvm/test/DebugInfo/MIR/InstrRef/x86-fp-stackifier-drop-locations.mir
+++ b/llvm/test/DebugInfo/MIR/InstrRef/x86-fp-stackifier-drop-locations.mir
@@ -1,4 +1,5 @@
-# RUN: llc %s -run-pass=x86-codegen -o - -experimental-debug-variable-locations | FileCheck %s --implicit-check-not=debug-instr-number
+# RUN: llc %s -run-pass=x86-fp-stackifier -o - -experimental-debug-variable-locations | FileCheck %s --implicit-check-not=debug-instr-number
+# RUN: llc %s -passes=x86-fp-stackifier -o - -experimental-debug-variable-locations | FileCheck %s --implicit-check-not=debug-instr-number
#
# The x87 FP instructions below have debug instr numbers attached -- but the
# operands get rewritten when it's converted to stack-form. Rather than trying
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 77b2f491f6a72..3f2b9112e5c76 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -869,7 +869,7 @@ constexpr MCPhysReg kDefaultLoopCounterReg = X86::R8;
void ExegesisX86Target::addTargetSpecificPasses(PassManagerBase &PM) const {
// Lowers FP pseudo-instructions, e.g. ABS_Fp32 -> ABS_F.
- PM.add(createX86FloatingPointStackifierPass());
+ PM.add(createX86FPStackifierLegacyPass());
}
MCRegister ExegesisX86Target::getScratchMemoryRegister(const Triple &TT) const {
|
boomanaiden154
added a commit
to boomanaiden154/llvm-project
that referenced
this pull request
Nov 13, 2025
Created using spr 1.3.7 [skip ci]
arsenm
approved these changes
Nov 13, 2025
boomanaiden154
added a commit
to boomanaiden154/llvm-project
that referenced
this pull request
Nov 13, 2025
RKSimon
approved these changes
Nov 13, 2025
Collaborator
RKSimon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Nov 13, 2025
Reviewers: arsenm, RKSimon, paperchalice, phoebewang Reviewed By: arsenm, RKSimon Pull Request: llvm/llvm-project#167911
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.