47#define DEBUG_TYPE "x86-fixup-setcc"
49STATISTIC(NumSubstZexts,
"Number of setcc + zext pairs substituted");
50STATISTIC(NumSubstMovbeZexts,
"Number of movbe + zext pairs substituted");
59 StringRef getPassName()
const override {
return "X86 Fixup SetCC"; }
63 void getAnalysisUsage(AnalysisUsage &AU)
const override {
70char X86FixupSetCCLegacy::ID = 0;
75 return new X86FixupSetCCLegacy();
86 for (
auto &
MBB : MF) {
88 for (
auto &
MI :
MBB) {
90 if (
MI.definesRegister(X86::EFLAGS,
nullptr))
96 if (
MI.getOpcode() != X86::SETCCr &&
MI.getOpcode() != X86::SETZUCCr)
101 for (
auto &
Use :
MRI->use_instructions(Reg0))
102 if (
Use.getOpcode() == X86::MOVZX32rr8)
114 bool UseSetZUCC = ST->hasZU() && !ST->preferLegacySetCC();
127 ST->is64Bit() ? &X86::GR32RegClass : &X86::GR32_ABCDRegClass;
142 MI.setDesc(
TII->get(X86::SETZUCCr));
144 TII->get(TargetOpcode::IMPLICIT_DEF), ZeroReg);
161 {
MI.getDebugInstrNum(), 0});
167 for (
auto &
I : ToErase)
168 I->eraseFromParent();
182 for (
auto &
MBB : MF) {
183 for (
auto &
MI :
MBB) {
184 if (
MI.getOpcode() != X86::MOVZX32rr16)
193 if (!MovbeInstruction ||
194 (MovbeInstruction->
getOpcode() != X86::MOVBE16rm &&
195 MovbeInstruction->
getOpcode() != X86::MOVBE16rm_EVEX))
203 InsertBefore = MovbeInstruction;
210 while (
I != MovbeMBB->
begin()) {
212 if (
I->modifiesRegister(X86::EFLAGS,
TRI)) {
215 if (!
I->readsRegister(X86::EFLAGS,
TRI))
223 Register ZeroReg =
MRI->createVirtualRegister(&X86::GR32RegClass);
228 MI.getOperand(0).getReg())
233 if (
unsigned InstrNum =
MI.peekDebugInstrNum())
238 ++NumSubstMovbeZexts;
242 ZExt->eraseFromParent();
const AArch64InstrInfo & TII
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool fixupSetCC(MachineFunction &MF)
static bool fixupMovbeZExt(MachineFunction &MF)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
LLVM_ABI LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, MCRegister Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before.
MachineInstrBundleIterator< MachineInstr > iterator
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
@ LQR_Dead
Register is known to be fully dead.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void makeDebugValueSubstitution(DebugInstrOperandPair, DebugInstrOperandPair, unsigned SubReg=0)
Create a substitution between one <instr,operand> value to a different, new value.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & setOperandDead(unsigned OpIdx) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
unsigned peekDebugInstrNum() const
Examine the instruction number of this MachineInstr.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI unsigned getDebugInstrNum()
Fetch the instruction number of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A Use represents the edge between a Value definition and its users.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
FunctionPass * createX86FixupSetCCLegacyPass()
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
MCRegisterClass TargetRegisterClass