<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></blockquote><div><br></div><div>You can use trivial bitcasts if you want to avoid load/store/alloca and you want SSA variables for your constants:</div><div> %val = bitcast i32 1 to i32</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Regards,</div><div>Paul</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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>