[llvm-dev] IR question re: constants

Krzysztof Parzyszek via llvm-dev llvm-dev at lists.llvm.org
Wed Sep 2 11:36:52 PDT 2015


On 9/2/2015 1:24 PM, Krzysztof Parzyszek via llvm-dev wrote:
>
> The LLVM IR doesn't have registers.  The computations are values and a
> constant represents itself.

On that note, you can hoist any constant yourself:

Define:
   %blah = llvm.my.own.intrinsic C
Then have:
	... = %blah
And lower the intrinsic to the value of its argument.

Alternatively, define
   %blah = select i1 true, C, 0.
The instruction selection happens on a basic-block basis, so if that 
"select" is in its own block, it will not be propagated into other 
blocks at that time.

There are limitations to each such approach though. In the above cases, 
the intrinsic won't be "understood" by the optimizer, but it can be 
considered expensive.  The select will be folded back into the constant 
if you do it too early, but this will allow further simplifications.

-Krzysztof

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation


More information about the llvm-dev mailing list