[llvm] 70bd0e2 - [X86][NewPM] Port x86-fixup-vector-constants (#175622)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 12 12:49:34 PST 2026


Author: Aiden Grossman
Date: 2026-01-12T12:49:29-08:00
New Revision: 70bd0e227393b1f4fb31dc4976126bcfdddc4537

URL: https://github.com/llvm/llvm-project/commit/70bd0e227393b1f4fb31dc4976126bcfdddc4537
DIFF: https://github.com/llvm/llvm-project/commit/70bd0e227393b1f4fb31dc4976126bcfdddc4537.diff

LOG: [X86][NewPM] Port x86-fixup-vector-constants (#175622)

Similar to other portings. No new test coverage because there are no
passes that even start/stop at this pass, much less capture only a
MIR->MIR transformation.

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86.h
    llvm/lib/Target/X86/X86FixupVectorConstants.cpp
    llvm/lib/Target/X86/X86PassRegistry.def
    llvm/lib/Target/X86/X86TargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index 09ceee791da62..9d965ade0b041 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -87,7 +87,14 @@ class X86FixupInstTuningPass : public PassInfoMixin<X86FixupInstTuningPass> {
 FunctionPass *createX86FixupInstTuningLegacyPass();
 
 /// Return a pass that reduces the size of vector constant pool loads.
-FunctionPass *createX86FixupVectorConstants();
+class X86FixupVectorConstantsPass
+    : public PassInfoMixin<X86FixupInstTuningPass> {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+                        MachineFunctionAnalysisManager &MFAM);
+};
+
+FunctionPass *createX86FixupVectorConstantsLegacyPass();
 
 /// Return a pass that removes redundant LEA instructions and redundant address
 /// recalculations.
@@ -340,7 +347,7 @@ void initializeFixupLEAsLegacyPass(PassRegistry &);
 void initializeX86ArgumentStackSlotPassPass(PassRegistry &);
 void initializeX86AsmPrinterPass(PassRegistry &);
 void initializeX86FixupInstTuningLegacyPass(PassRegistry &);
-void initializeX86FixupVectorConstantsPassPass(PassRegistry &);
+void initializeX86FixupVectorConstantsLegacyPass(PassRegistry &);
 void initializeWinEHStatePassPass(PassRegistry &);
 void initializeX86AvoidSFBLegacyPass(PassRegistry &);
 void initializeX86AvoidTrailingCallLegacyPassPass(PassRegistry &);

diff  --git a/llvm/lib/Target/X86/X86FixupVectorConstants.cpp b/llvm/lib/Target/X86/X86FixupVectorConstants.cpp
index 6fe39c6789737..2985a883a1481 100644
--- a/llvm/lib/Target/X86/X86FixupVectorConstants.cpp
+++ b/llvm/lib/Target/X86/X86FixupVectorConstants.cpp
@@ -29,38 +29,45 @@ using namespace llvm;
 STATISTIC(NumInstChanges, "Number of instructions changes");
 
 namespace {
-class X86FixupVectorConstantsPass : public MachineFunctionPass {
+class X86FixupVectorConstantsImpl {
+public:
+  bool runOnMachineFunction(MachineFunction &MF);
+
+private:
+  bool processInstruction(MachineFunction &MF, MachineBasicBlock &MBB,
+                          MachineInstr &MI);
+
+  const X86InstrInfo *TII = nullptr;
+  const X86Subtarget *ST = nullptr;
+  const MCSchedModel *SM = nullptr;
+};
+
+class X86FixupVectorConstantsLegacy : public MachineFunctionPass {
 public:
   static char ID;
 
-  X86FixupVectorConstantsPass() : MachineFunctionPass(ID) {}
+  X86FixupVectorConstantsLegacy() : MachineFunctionPass(ID) {}
 
   StringRef getPassName() const override {
     return "X86 Fixup Vector Constants";
   }
 
   bool runOnMachineFunction(MachineFunction &MF) override;
-  bool processInstruction(MachineFunction &MF, MachineBasicBlock &MBB,
-                          MachineInstr &MI);
 
   // This pass runs after regalloc and doesn't support VReg operands.
   MachineFunctionProperties getRequiredProperties() const override {
     return MachineFunctionProperties().setNoVRegs();
   }
-
-private:
-  const X86InstrInfo *TII = nullptr;
-  const X86Subtarget *ST = nullptr;
-  const MCSchedModel *SM = nullptr;
 };
 } // end anonymous namespace
 
-char X86FixupVectorConstantsPass::ID = 0;
+char X86FixupVectorConstantsLegacy::ID = 0;
 
-INITIALIZE_PASS(X86FixupVectorConstantsPass, DEBUG_TYPE, DEBUG_TYPE, false, false)
+INITIALIZE_PASS(X86FixupVectorConstantsLegacy, DEBUG_TYPE, DEBUG_TYPE, false,
+                false)
 
-FunctionPass *llvm::createX86FixupVectorConstants() {
-  return new X86FixupVectorConstantsPass();
+FunctionPass *llvm::createX86FixupVectorConstantsLegacyPass() {
+  return new X86FixupVectorConstantsLegacy();
 }
 
 /// Normally, we only allow poison in vector splats. However, as this is part
@@ -335,7 +342,7 @@ static Constant *rebuildZExtCst(const Constant *C, unsigned NumBits,
   return rebuildExtCst(C, false, NumBits, NumElts, SrcEltBitWidth);
 }
 
-bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
+bool X86FixupVectorConstantsImpl::processInstruction(MachineFunction &MF,
                                                      MachineBasicBlock &MBB,
                                                      MachineInstr &MI) {
   unsigned Opc = MI.getOpcode();
@@ -775,7 +782,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
   return false;
 }
 
-bool X86FixupVectorConstantsPass::runOnMachineFunction(MachineFunction &MF) {
+bool X86FixupVectorConstantsImpl::runOnMachineFunction(MachineFunction &MF) {
   LLVM_DEBUG(dbgs() << "Start X86FixupVectorConstants\n";);
   bool Changed = false;
   ST = &MF.getSubtarget<X86Subtarget>();
@@ -793,3 +800,18 @@ bool X86FixupVectorConstantsPass::runOnMachineFunction(MachineFunction &MF) {
   LLVM_DEBUG(dbgs() << "End X86FixupVectorConstants\n";);
   return Changed;
 }
+
+bool X86FixupVectorConstantsLegacy::runOnMachineFunction(MachineFunction &MF) {
+  X86FixupVectorConstantsImpl Impl;
+  return Impl.runOnMachineFunction(MF);
+}
+
+PreservedAnalyses
+X86FixupVectorConstantsPass::run(MachineFunction &MF,
+                                 MachineFunctionAnalysisManager &MFAM) {
+  X86FixupVectorConstantsImpl Impl;
+  return Impl.runOnMachineFunction(MF)
+             ? getMachineFunctionPassPreservedAnalyses()
+                   .preserveSet<CFGAnalyses>()
+             : PreservedAnalyses::all();
+}

diff  --git a/llvm/lib/Target/X86/X86PassRegistry.def b/llvm/lib/Target/X86/X86PassRegistry.def
index a383836527a94..75dc64bf8f63e 100644
--- a/llvm/lib/Target/X86/X86PassRegistry.def
+++ b/llvm/lib/Target/X86/X86PassRegistry.def
@@ -43,6 +43,7 @@ MACHINE_FUNCTION_PASS("x86-fixup-bw-insts", X86FixupBWInstsPass())
 MACHINE_FUNCTION_PASS("x86-fixup-inst-tuning", X86FixupInstTuningPass())
 MACHINE_FUNCTION_PASS("x86-fixup-leas", X86FixupLEAsPass())
 MACHINE_FUNCTION_PASS("x86-fixup-setcc", X86FixupSetCCPass())
+MACHINE_FUNCTION_PASS("x86-fixup-vector-constants", X86FixupVectorConstantsPass())
 MACHINE_FUNCTION_PASS("x86-flags-copy-lowering", X86FlagsCopyLoweringPass())
 MACHINE_FUNCTION_PASS("x86-fp-stackifier", X86FPStackifierPass())
 MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
@@ -55,7 +56,6 @@ MACHINE_FUNCTION_PASS("x86-suppress-apx-for-relocation", X86SuppressAPXForReloca
 #define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME)
 #endif
 DUMMY_MACHINE_FUNCTION_PASS("x86-execution-domain-fix", X86ExecutionDomainFix())
-DUMMY_MACHINE_FUNCTION_PASS("x86-fixup-vector-constants", X86FixupVectorConstantsPass())
 DUMMY_MACHINE_FUNCTION_PASS("x86-lvi-load", X86LoadValueInjectionLoadHardeningPass())
 DUMMY_MACHINE_FUNCTION_PASS("x86-lvi-ret", X86LoadValueInjectionRetHardeningPass())
 DUMMY_MACHINE_FUNCTION_PASS("x86-return-thunks", X86ReturnThunks())

diff  --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index da4e599130096..b913dd93d641c 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -103,7 +103,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
   initializeX86ArgumentStackSlotPassPass(PR);
   initializeX86AsmPrinterPass(PR);
   initializeX86FixupInstTuningLegacyPass(PR);
-  initializeX86FixupVectorConstantsPassPass(PR);
+  initializeX86FixupVectorConstantsLegacyPass(PR);
   initializeX86DynAllocaExpanderLegacyPass(PR);
   initializeX86SuppressAPXForRelocationLegacyPass(PR);
   initializeX86WinEHUnwindV2Pass(PR);
@@ -568,7 +568,7 @@ void X86PassConfig::addPreEmitPass() {
     addPass(createX86PadShortFunctions());
     addPass(createX86FixupLEAsLegacyPass());
     addPass(createX86FixupInstTuningLegacyPass());
-    addPass(createX86FixupVectorConstants());
+    addPass(createX86FixupVectorConstantsLegacyPass());
   }
   addPass(createX86CompressEVEXLegacyPass());
   addPass(createX86InsertX87waitPass());


        


More information about the llvm-commits mailing list