[LLVMdev] Multi-class register allocatable only in one class

Carlos Sánchez de La Lama carlos.delalama at urjc.es
Mon Sep 13 06:59:20 PDT 2010

Hi people,

the LinearScan register allocator tries to use same register for both  
live intervals, if the new interval is defined by a register copy  
whose destination reg is compatible with the source register. This is  
ok. However, this "check for compatibility" is wrongly done IMHO.

Say I have regclass1 with reg A, and regclass2 with regs {A, B}, but  
regclass2 defines only "B" as allocatable by RA.

A copy instruction:
<regclass2 dst> = <regclass1 src>
where src was allocated to register A will make dst be allocated also  
to A, even when it was defined as not allocatable in .td files.

This is due to the checking in RegAllocLinearScan:1004

           if (Reg && allocatableRegs_[Reg] && RC->contains(Reg))
             mri_->setRegAllocationHint(cur->reg, 0, Reg);

where "allocatableRegs_" is calculated during pass init, and ignores  
register class. I think this should be changed to:

           if (Reg && (tri_->getAllocatableSet(*mf_, RC))[Reg] && RC- 
             mri_->setRegAllocationHint(cur->reg, 0, Reg);

or, if compilation speed discourages calling "getAllocatableSet" so  
often, create "allocatableRegs_" array per register-class, instead of  
just one.

If it is ok I can create a patch (I would go to call every time and  
optimize for speed later if needed, but I can do either version, no  
problem) and send it to the list.



More information about the llvm-dev mailing list