Skip to content

Commit 9f0d0bb

Browse files
[X86][NewPM] Port x86-fixup-setcc (#175609)
Similar to other portings, except this time we do not refactor to an impl since there is a single runOnMachineFunction definition that can easily be made static. Test coverage added.
1 parent acf82c1 commit 9f0d0bb

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

llvm/lib/Target/X86/X86.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ class X86OptimizeLEAsPass : public PassInfoMixin<X86OptimizeLEAsPass> {
100100
FunctionPass *createX86OptimizeLEAsLegacyPass();
101101

102102
/// Return a pass that transforms setcc + movzx pairs into xor + setcc.
103-
FunctionPass *createX86FixupSetCC();
103+
class X86FixupSetCCPass : public PassInfoMixin<X86FixupSetCCPass> {
104+
public:
105+
PreservedAnalyses run(MachineFunction &MF,
106+
MachineFunctionAnalysisManager &MFAM);
107+
};
108+
109+
FunctionPass *createX86FixupSetCCLegacyPass();
104110

105111
/// Return a pass that avoids creating store forward block issues in the
106112
/// hardware.
@@ -333,7 +339,7 @@ void initializeX86ExpandPseudoLegacyPass(PassRegistry &);
333339
void initializeX86FPStackifierLegacyPass(PassRegistry &);
334340
void initializeX86FastPreTileConfigLegacyPass(PassRegistry &);
335341
void initializeX86FastTileConfigLegacyPass(PassRegistry &);
336-
void initializeX86FixupSetCCPassPass(PassRegistry &);
342+
void initializeX86FixupSetCCLegacyPass(PassRegistry &);
337343
void initializeX86FlagsCopyLoweringLegacyPass(PassRegistry &);
338344
void initializeX86LoadValueInjectionLoadHardeningPassPass(PassRegistry &);
339345
void initializeX86LoadValueInjectionRetHardeningPassPass(PassRegistry &);

llvm/lib/Target/X86/X86FixupSetCC.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,31 @@ using namespace llvm;
3939
STATISTIC(NumSubstZexts, "Number of setcc + zext pairs substituted");
4040

4141
namespace {
42-
class X86FixupSetCCPass : public MachineFunctionPass {
42+
class X86FixupSetCCLegacy : public MachineFunctionPass {
4343
public:
4444
static char ID;
4545

46-
X86FixupSetCCPass() : MachineFunctionPass(ID) {}
46+
X86FixupSetCCLegacy() : MachineFunctionPass(ID) {}
4747

4848
StringRef getPassName() const override { return "X86 Fixup SetCC"; }
4949

5050
bool runOnMachineFunction(MachineFunction &MF) override;
51-
52-
private:
53-
MachineRegisterInfo *MRI = nullptr;
54-
const X86Subtarget *ST = nullptr;
55-
const X86InstrInfo *TII = nullptr;
56-
57-
enum { SearchBound = 16 };
5851
};
5952
} // end anonymous namespace
6053

61-
char X86FixupSetCCPass::ID = 0;
54+
char X86FixupSetCCLegacy::ID = 0;
6255

63-
INITIALIZE_PASS(X86FixupSetCCPass, DEBUG_TYPE, DEBUG_TYPE, false, false)
56+
INITIALIZE_PASS(X86FixupSetCCLegacy, DEBUG_TYPE, DEBUG_TYPE, false, false)
6457

65-
FunctionPass *llvm::createX86FixupSetCC() { return new X86FixupSetCCPass(); }
58+
FunctionPass *llvm::createX86FixupSetCCLegacyPass() {
59+
return new X86FixupSetCCLegacy();
60+
}
6661

67-
bool X86FixupSetCCPass::runOnMachineFunction(MachineFunction &MF) {
62+
static bool fixupSetCC(MachineFunction &MF) {
6863
bool Changed = false;
69-
MRI = &MF.getRegInfo();
70-
ST = &MF.getSubtarget<X86Subtarget>();
71-
TII = ST->getInstrInfo();
64+
MachineRegisterInfo *MRI = &MF.getRegInfo();
65+
const X86Subtarget *ST = &MF.getSubtarget<X86Subtarget>();
66+
const X86InstrInfo *TII = ST->getInstrInfo();
7267

7368
SmallVector<MachineInstr*, 4> ToErase;
7469

@@ -155,3 +150,14 @@ bool X86FixupSetCCPass::runOnMachineFunction(MachineFunction &MF) {
155150

156151
return Changed;
157152
}
153+
154+
bool X86FixupSetCCLegacy::runOnMachineFunction(MachineFunction &MF) {
155+
return fixupSetCC(MF);
156+
}
157+
158+
PreservedAnalyses X86FixupSetCCPass::run(MachineFunction &MF,
159+
MachineFunctionAnalysisManager &MFAM) {
160+
return fixupSetCC(MF) ? getMachineFunctionPassPreservedAnalyses()
161+
.preserveSet<CFGAnalyses>()
162+
: PreservedAnalyses::all();
163+
}

llvm/lib/Target/X86/X86PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ MACHINE_FUNCTION_PASS("x86-fast-tile-config", X86FastTileConfigPass())
4242
MACHINE_FUNCTION_PASS("x86-fixup-bw-insts", X86FixupBWInstsPass())
4343
MACHINE_FUNCTION_PASS("x86-fixup-inst-tuning", X86FixupInstTuningPass())
4444
MACHINE_FUNCTION_PASS("x86-fixup-leas", X86FixupLEAsPass())
45+
MACHINE_FUNCTION_PASS("x86-fixup-setcc", X86FixupSetCCPass())
4546
MACHINE_FUNCTION_PASS("x86-flags-copy-lowering", X86FlagsCopyLoweringPass())
4647
MACHINE_FUNCTION_PASS("x86-fp-stackifier", X86FPStackifierPass())
4748
MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
@@ -52,7 +53,6 @@ MACHINE_FUNCTION_PASS("x86-optimize-leas", X86OptimizeLEAsPass())
5253
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME)
5354
#endif
5455
DUMMY_MACHINE_FUNCTION_PASS("x86-execution-domain-fix", X86ExecutionDomainFix())
55-
DUMMY_MACHINE_FUNCTION_PASS("x86-fixup-setcc", X86FixupSetCCPass())
5656
DUMMY_MACHINE_FUNCTION_PASS("x86-fixup-vector-constants", X86FixupVectorConstantsPass())
5757
DUMMY_MACHINE_FUNCTION_PASS("x86-lower-tile-copy", X86LowerTileCopy())
5858
DUMMY_MACHINE_FUNCTION_PASS("x86-lvi-load", X86LoadValueInjectionLoadHardeningPass())

llvm/lib/Target/X86/X86TargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
7777
initializeCompressEVEXLegacyPass(PR);
7878
initializeFixupLEAsLegacyPass(PR);
7979
initializeX86FPStackifierLegacyPass(PR);
80-
initializeX86FixupSetCCPassPass(PR);
80+
initializeX86FixupSetCCLegacyPass(PR);
8181
initializeX86CallFrameOptimizationLegacyPass(PR);
8282
initializeX86CmovConversionLegacyPass(PR);
8383
initializeX86TileConfigPass(PR);
@@ -514,7 +514,7 @@ bool X86PassConfig::addPreISel() {
514514
void X86PassConfig::addPreRegAlloc() {
515515
if (getOptLevel() != CodeGenOptLevel::None) {
516516
addPass(&LiveRangeShrinkID);
517-
addPass(createX86FixupSetCC());
517+
addPass(createX86FixupSetCCLegacyPass());
518518
addPass(createX86OptimizeLEAsLegacyPass());
519519
addPass(createX86CallFrameOptimizationLegacyPass());
520520
addPass(createX86AvoidStoreForwardingBlocksLegacyPass());

llvm/test/DebugInfo/X86/x86fixupsetcc-debug-instr-num.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc %s --run-pass=x86-fixup-setcc -o - | FileCheck %s
2+
# RUN: llc %s -passes=x86-fixup-setcc -o - | FileCheck %s
23

34
## Check the debug-isntr-number transfers from MOVZX32rr8 to the SETCC
45
## after the mov is replaced with an INSERT_SUBREG, updating the substitutions

0 commit comments

Comments
 (0)