diff options
| author | Shengchen Kan <shengchen.kan@intel.com> | 2023-11-02 00:12:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-02 00:12:05 +0800 |
| commit | 860f9e5170767c08a879b592c9121d35e90a320e (patch) | |
| tree | 0ce5865bccc294671d7483a7579652bf823d3b5a /llvm/lib/CodeGen/LiveVariables.cpp | |
| parent | e2550b7aa072130230baa9dba0feff808ffe907d (diff) | |
[NFC][X86] Reorder the registers to reduce unnecessary iterations (#70222)
* Introduce field `PositionOrder` for class `Register` and
`RegisterTuples`
* If register A's `PositionOrder` < register B's `PositionOrder`, then A
is placed before B in the enum in X86GenRegisterInfo.inc
* The new order of registers in the enum for X86 will be
1. Registers before AVX512,
2. AVX512 registers (X/YMM16-31, ZMM0-31, K registers)
3. AMX registers (TMM)
4. APX registers (R16-R31)
* Add a new target hook `getNumSupportedRegs()` to return the number of
registers for the function (may overestimate).
* Replace `getNumRegs()` with `getNumSupportedRegs()` in LiveVariables
to eliminate iterations on unsupported registers
This patch can reduce 0.3% instruction count regression for sqlite3
during compile-stage (O3) by not iterating on APX registers
for #67702
Diffstat (limited to 'llvm/lib/CodeGen/LiveVariables.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/LiveVariables.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp index 6b983b6320c7..b85526cfb380 100644 --- a/llvm/lib/CodeGen/LiveVariables.cpp +++ b/llvm/lib/CodeGen/LiveVariables.cpp @@ -406,11 +406,11 @@ bool LiveVariables::HandlePhysRegKill(Register Reg, MachineInstr *MI) { return true; } -void LiveVariables::HandleRegMask(const MachineOperand &MO) { +void LiveVariables::HandleRegMask(const MachineOperand &MO, unsigned NumRegs) { // Call HandlePhysRegKill() for all live registers clobbered by Mask. // Clobbered registers are always dead, sp there is no need to use // HandlePhysRegDef(). - for (unsigned Reg = 1, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg) { + for (unsigned Reg = 1; Reg != NumRegs; ++Reg) { // Skip dead regs. if (!PhysRegDef[Reg] && !PhysRegUse[Reg]) continue; @@ -421,7 +421,8 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO) { // This avoids needless implicit operands. unsigned Super = Reg; for (MCPhysReg SR : TRI->superregs(Reg)) - if ((PhysRegDef[SR] || PhysRegUse[SR]) && MO.clobbersPhysReg(SR)) + if (SR < NumRegs && (PhysRegDef[SR] || PhysRegUse[SR]) && + MO.clobbersPhysReg(SR)) Super = SR; HandlePhysRegKill(Super, nullptr); } @@ -478,7 +479,8 @@ void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI, } void LiveVariables::runOnInstr(MachineInstr &MI, - SmallVectorImpl<unsigned> &Defs) { + SmallVectorImpl<unsigned> &Defs, + unsigned NumRegs) { assert(!MI.isDebugOrPseudoInstr()); // Process all of the operands of the instruction... unsigned NumOperandsToProcess = MI.getNumOperands(); @@ -527,7 +529,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI, // Process all masked registers. (Call clobbers). for (unsigned Mask : RegMasks) - HandleRegMask(MI.getOperand(Mask)); + HandleRegMask(MI.getOperand(Mask), NumRegs); // Process all defs. for (unsigned MOReg : DefRegs) { @@ -539,7 +541,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI, UpdatePhysRegDefs(MI, Defs); } -void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) { +void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) { // Mark live-in registers as live-in. SmallVector<unsigned, 4> Defs; for (const auto &LI : MBB->liveins()) { @@ -556,7 +558,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, const unsigned NumRegs) { continue; DistanceMap.insert(std::make_pair(&MI, Dist++)); - runOnInstr(MI, Defs); + runOnInstr(MI, Defs, NumRegs); } // Handle any virtual assignments from PHI nodes which might be at the @@ -597,7 +599,7 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) { MRI = &mf.getRegInfo(); TRI = MF->getSubtarget().getRegisterInfo(); - const unsigned NumRegs = TRI->getNumRegs(); + const unsigned NumRegs = TRI->getNumSupportedRegs(mf); PhysRegDef.assign(NumRegs, nullptr); PhysRegUse.assign(NumRegs, nullptr); PHIVarInfo.resize(MF->getNumBlockIDs()); |
