Other than: %x = add i32 5,0 ; suppose I want to assign 5 to %x is there any other way? Something like x86's mov instruction -- View this message in context: http://old.nabble.com/How-to-assign-a-constant-to-a-register--tp29987387p29987387.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
hi, On Mon, Oct 18, 2010 at 12:39 PM, leledumbo <leledumbo_cool at yahoo.co.id> wrote:> > Other than: > %x = add i32 5,0 ; suppose I want to assign 5 to %xyou do not need to do this at the level of LLVM IR, or do you mind to tell us the reason for this? best regards ether> > is there any other way? Something like x86's mov instruction > > -- > View this message in context: http://old.nabble.com/How-to-assign-a-constant-to-a-register--tp29987387p29987387.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Hi,> Other than: > %x = add i32 5,0 ; suppose I want to assign 5 to %x > > is there any other way? Something like x86's mov instructionlet 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. A common situation is that you have a register %x, and due to performing optimizations you discover that in fact %x will always have the value 5. You can use RAUW (aka the replaceAllUsesWith method) to replace %x with 5 everywhere. Ciao, Duncan.
> 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.