[LLVMdev] Loading of immediates into registers

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Feb 24 16:47:11 PST 2011


On Feb 24, 2011, at 4:24 AM, Jonas Paulsson wrote:

> I have some constants that get loaded into a register, and then the register is copied to another register, and then used. I suspect this stems from PHI nodes lowering.I cannot avoid this right now, as the MI PHI's will only hold registers, and not constants. Therefore this gets complicated, having to handle the introduced copies from the Eliminate PHIs pass, while the IR is not on SSA-form anymore.
> 
> Is there a simple way to handle this that I have missed?

It depends on what you mean by 'loaded'. If you have a cheap instruction that puts an immediate in a register, mark it as rematerializable and 'as cheap as a move'. Then the register allocator will replace all copies with rematerialized copies of the original instruction.

See MOV8ri and friends in X86InstrInfo.td.

If you mean a constant pool load, copies are preferred unless the value needs to be spilled. You should mark your load instructions as rematerializable as well.

/jakob





More information about the llvm-dev mailing list