I'm curious. Is there a specific technical reason that the high-level IR doesn't have an instruction to simply set a register to a constant? This limitation means we cannot hoist an "expensive" constant out of a loop until we lower the IR to MachineInstrs. Or more to the point, it forces backends to undo any such hoisting done by frontends. Or am I not understanding something? -David
Krzysztof Parzyszek via llvm-dev
2015-Sep-02 18:24 UTC
[llvm-dev] IR question re: constants
On 9/2/2015 1:16 PM, via llvm-dev wrote:> I'm curious. Is there a specific technical reason that the high-level > IR doesn't have an instruction to simply set a register to a constant? > This limitation means we cannot hoist an "expensive" constant out of a > loop until we lower the IR to MachineInstrs. Or more to the point, it > forces backends to undo any such hoisting done by frontends. > > Or am I not understanding something?The LLVM IR doesn't have registers. The computations are values and a constant represents itself. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof Parzyszek via llvm-dev
2015-Sep-02 18:36 UTC
[llvm-dev] IR question re: constants
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