> let me say that in general doing this is pointless. Due to SSA form, > if %x is > set to 5 you can't set it to something else later. Thus everywhere > that you > use %x you might as well just directly use 5 there instead.But the cost of doing that might be greater than the costs of keeping it in a register. Suppose the code was ORing a value with 5 and the target only had OR-register and not OR-immediate. You would expect local code generation to handle OR-immediate by locally materialising the constant into a spare register. But if the usage was in a loop it would be better (at the cost of register pressure) to materialise 5 into a register outside of the loop and use the register repeatedly in the loop. Al -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Hi Alasdair,> But the cost of doing that might be greater than the costs > of keeping it in a register. Suppose the code was ORing a value > with 5 and the target only had OR-register and not OR-immediate. > You would expect local code generation to handle OR-immediate by > locally materialising the constant into a spare register. > But if the usage was in a loop it would be better (at the cost of > register pressure) to materialise 5 into a register outside of the > loop and use the register repeatedly in the loop.it is up to the code generators to take care of this kind of thing. I don't see how having (at the IR level) a register called %x which contains the value 5 makes it easier for the code generators to perform this optimization than if you directly use 5 everywhere %x would occur. Ciao, Duncan.
hi, Well, there is no "Register" at the level of LLVM IR, %x = add i32 %y, %z means you define a value "x" by adding value "y" and value "z" together. best regards ether
Arnaud Allard de Grandmaison
2010-Oct-19 07:19 UTC
[LLVMdev] How to assign a constant to a register?
> But if the usage was in a loop it would be better (at the cost of > register pressure) to materialise 5 into a register outside of the > loop and use the register repeatedly in the loop.Bouncing on this subject: you can not know before isel is over if the constants have to materialize into registers or not, as this is really dependent on the target's instruction set. Do we have any pass hoisting the constant loading out of the (inner) loops after isel ? I guess this could be beneficial for most targets --- assuming the pass does not increase the register pressure to some unreasonnable level. -- Arnaud de Grandmaison
On Tue, Oct 19, 2010 at 12:19 AM, Arnaud Allard de Grandmaison <Arnaud.AllardDeGrandMaison at dibcom.com> wrote:>> But if the usage was in a loop it would be better (at the cost of >> register pressure) to materialise 5 into a register outside of the >> loop and use the register repeatedly in the loop. > > Bouncing on this subject: you can not know before isel is over if the constants have to materialize into registers or not, as this is really dependent on the target's instruction set. Do we have any pass hoisting the constant loading out of the (inner) loops after isel ? I guess this could be beneficial for most targets --- assuming the pass does not increase the register pressure to some unreasonnable level.Yes; see lib/CodeGen/MachineLICM.cpp. -Eli
Possibly Parallel Threads
- [LLVMdev] How to assign a constant to a register?
- [LLVMdev] How to assign a constant to a register?
- [LLVMdev] Re : How to assign a constant to a register?
- [LLVMdev] Re : How to assign a constant to a register?
- [LLVMdev] Re : How to assign a constant to a register?