<div dir="ltr"><div>Thanks I got this to work in the end since the instruction set is now changing to handle immedites.<br><br></div>--Phil<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 January 2017 at 00:43, Philip Herron <span dir="ltr"><<a href="mailto:herron.philip@googlemail.com" target="_blank">herron.philip@googlemail.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>This looks to be exactly what i need. Though this instruction set i am working with does not support immedites. It has a load constant to register instruction is the only way to load immedites. So i am not sure if this pattern will pick that up correctly. Will give it a test.<br><br></div><div>Thanks</div><br></div>--Phil<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 25 January 2017 at 21:23, Matt Arsenault <span dir="ltr"><<a href="mailto:Matthew.Arsenault@amd.com" target="_blank">Matthew.Arsenault@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_6404957087850248361HOEnZb"><div class="m_6404957087850248361h5">On 01/25/2017 01:05 PM, Philip Herron via llvm-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
I am writing a custom backend. Doing more testing i notice that for some reason something like:<br>
<br>
int test(int x) { return x - 1; }<br>
<br>
is being turned into this IR:<br>
<br>
; Function Attrs: nounwind<br>
define i32 @test(i32 %n) #0 {<br>
entry:<br>
%n.addr = alloca i32, align 4<br>
store i32 %n, i32* %n.addr, align 4<br>
%0 = load i32* %n.addr, align 4<br>
%sub = sub nsw i32 %0, 1<br>
ret i32 %sub<br>
}<br>
<br>
But finally in code generation i am getting:<br>
<br>
ldc r2, #-1<br>
add r0, r2, r0<br>
<br>
Should this not be doing:<br>
<br>
ldc r2 #1<br>
sub r0 r2 r0<br>
<br>
I have defined both my add and sub instructions:<br>
<br>
def ADD : ALUInst<0b0001, (outs GRRegs:$dst),<br>
(ins GRRegs:$src1, GRRegs:$src2),<br>
"add $src1, $src2, $dst",<br>
[(set i32:$dst, (add i32:$src1, i32:$src2))]>;<br>
<br>
def SUB : ALUInst<0b0010, (outs GRRegs:$dst),<br>
(ins GRRegs:$src1, GRRegs:$src2),<br>
"sub $src1, $src2, $dst",<br>
[(set i32:$dst, (sub i32:$src1, i32:$src2))]>;<br>
<br>
Is there a way to override this behaviour?<br>
</blockquote>
<br></div></div>
You can add an optimization pattern for this. I have a patch to do this for AMDGPU since it costs code size in some cases as an example: <a href="https://reviews.llvm.org/D28043" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2804<wbr>3</a><span class="m_6404957087850248361HOEnZb"><font color="#888888"><br>
<br>
-Matt<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>