<div dir="ltr"><div>> <span style="font-size:12.8px">But since something like that (bitcast constant) is allowed why isn't it possible to simply do this</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The following code</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">%1 = i32 1</span></div><div><span style="font-size:12.8px">%2 = i32 2</span></div><div><span style="font-size:12.8px">%3 = add i32 %1, %2</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">is more or less equivalent to</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">%1 = add i32 1, 2</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Because, in most cases, Instructions don't care if they're given SSA Values or Constants as operands. The second version is more compact, more concise, and has less indirection than the first, so it's presumably better in the vast majority of cases.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Is there something you're trying to work around with the '</span><span style="font-size:12.8px">Initializing registers</span><span style="font-size:12.8px">' bit of your initial example? ISTM that doing so would be entirely unnecessary if you took Jeremy's approach (well, a simplified version of it; you'd only need to do most of step 2 if you're guaranteed to only have a single basic block).</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 5:09 AM, mats petersson <span dir="ltr"><<a href="mailto:mats@planetcatfish.com" target="_blank">mats@planetcatfish.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Is there some particular reason that short IR is better than "follow what others do"?<br><br></div>I have written a (reasonably complete) Pascal compiler, and at first I worried about calling alloca, but I found that the mem2reg does a very good job of getting rid of alloca's, so it's not really a problem [you just need to ensure that all alloca's happen at the start of the function, or weird things happen, from what I've heard].<br><br>--<br></div>Mats<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 8 February 2016 at 11:01, Paul Peet via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I want to keep the translation short and simple (My IR doesn't have control flow so it's basically on basic block) that's why I don't want to rely on alloca/load/store.</div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-08 6:08 GMT+01:00 George Burgess IV <span dir="ltr"><<a href="mailto:george.burgess.iv@gmail.com" target="_blank">george.burgess.iv@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi!</div><div><br></div>I don't know what "the right way" to do this is, but is there any reason you're against just using alloca/load/store? That's what clang emits for most locals/parameters/..., and LLVM tends to do a very good job of SSAifying that where it can. :)<div><br><div>George</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Sun, Feb 7, 2016 at 3:00 PM, Paul Peet via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hello,<div><br></div><div>I am currently trying to translate some custom IR to LLVM-IR and came across and issue.</div><div>The custom IR has several registers and I am basically try to SSAfy it so it can be easily translated/converted to LLVM-IR.</div><div><br></div><div>The problem:</div><div><br></div><div>Since in my custom IR I can reassign every register I have to reassign every new expression with a new llvm Value. But my IR has something like this:</div><div><br></div><div>REG A = VAR C + CONST 2</div><div>REG A = CONST 12</div><div><br></div><div>So my workaround looks like:</div><div><br></div><div>; I am returning the registers in an anonymous struct</div><div><div>define { i32, i32, i32 } @test(i32 %var_c) {</div><div>  ; Initializing registers</div><div>  %reg_a_0 = select i1 true, i32 0, i32 0</div><div>  %reg_b_0 = select i1 true, i32 0, i32 0</div><div>  %reg_c_0 = select i1 true, i32 0, i32 0</div><div><br></div><div>  ; Translated instructions</div><div>  %reg_a_1 = add i32 %var_c, 2</div><div>  %reg_a_2 = select i1 true, i32 12, i32 0</div><div><br></div><div>  ; Prepare return values</div><div>  %ret_0 = insertvalue { i32, i32, i32 } undef, i32 %reg_a_2, 0</div><div>  %ret_1 = insertvalue { i32, i32, i32 } %ret_0, i32 %reg_b_0, 1</div><div>  %ret_2 = insertvalue { i32, i32, i32 } %ret_1, i32 %reg_c_0, 2</div><div>  </div><div>  ret { i32, i32, i32 } %ret_2</div><div>}</div></div><div><br></div><div>I am basically using "select i1 true, i32 1, i32 0" so after optimization it gets:</div><div>%val = i32 1</div><div><br></div><div>But as I said this looks like a hack to me and I can't simply use "%val = i32 1".</div><div>So what's the proper way to do this without actually using alloca/load/store.</div><div><br></div><div>Regards,</div><div>Paul</div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>