[llvm-commits] [llvm] r98043 - in /llvm/trunk/lib/CodeGen: LLVMTargetMachine.cpp MachineCSE.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon Mar 8 19:41:25 PST 2010
On Mar 8, 2010, at 7:21 PM, Evan Cheng wrote:
> @@ -91,14 +92,17 @@
> unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
> if (TII->isMoveInstr(*DefMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
> TargetRegisterInfo::isVirtualRegister(SrcReg) &&
> - MRI->getRegClass(SrcReg) == MRI->getRegClass(Reg) &&
> !SrcSubIdx && !DstSubIdx) {
> - DEBUG(dbgs() << "Coalescing: " << *DefMI);
> - DEBUG(dbgs() << "*** to: " << *MI);
> - MO.setReg(SrcReg);
> - DefMI->eraseFromParent();
> - ++NumCoalesces;
> - Changed = true;
> + const TargetRegisterClass *SRC = MRI->getRegClass(SrcReg);
> + const TargetRegisterClass *RC = MRI->getRegClass(Reg);
> + if (SRC == RC || SRC->hasSubClass(RC) || RC->hasSubClass(SRC)) {
> + DEBUG(dbgs() << "Coalescing: " << *DefMI);
> + DEBUG(dbgs() << "*** to: " << *MI);
> + MO.setReg(SrcReg);
> + DefMI->eraseFromParent();
> + ++NumCoalesces;
> + Changed = true;
> + }
> }
> }
The case "SRC->hasSubClass(RC)" is not valid. MO requires an RC operand, and SRC is a larger register class. It may contain registers that are illegal for MO.
If you don't want to change the register class of SrcReg, you have to make do with:
> + if (SRC == RC || RC->hasSubClass(SRC)) {
If you are not afraid of switching register classes, you can go:
> + const TargetRegisterClass *SRC = MRI->getRegClass(SrcReg);
> + const TargetRegisterClass *RC = MRI->getRegClass(Reg);
> + const TargetRegisterClass *NewRC = getCommonSubClass(SRC, RC);
> + if (NewRC) {
> + DEBUG(dbgs() << "Coalescing: " << *DefMI);
> + DEBUG(dbgs() << "*** to: " << *MI);
> + MO.setReg(SrcReg);
> + if (SRC != NewRC)
> + MRI->setRegClass(SrcReg, NewRC);
The problem with both approaches is that you are producing a longer live range of a smaller register class: Higher register pressure.
/jakob
More information about the llvm-commits
mailing list