<p dir="ltr">Yes the result goes into memory. But the <b>address</b> of that destination memory location also needs to be loaded first into a register. </p>
<p dir="ltr">Thanks.</p>
<p dir="ltr">Regards,<br>
Alex</p>
<div class="gmail_extra"><br><div class="gmail_quote">On 13 Oct 2016 3:39 a.m., "Friedman, Eli" <<a href="mailto:efriedma@codeaurora.org">efriedma@codeaurora.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10/12/2016 2:22 PM, Alex Bradley wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> You probably want to look at the x86 backend; it has a lot of instructions which involve both computation and memory.  Take the following IR, a variant of your example:<br>
><br>
> define void @foo(i32 *%a, i32 *%b, i32 *%c) {<br>
> entry:<br>
>   %0 = load i32, i32* %a, align 4<br>
>   %1 = load i32, i32* %b, align 4<br>
><br>
>   %add = add nsw i32 %1, %0<br>
>   store i32 %add, i32* %c, align 4<br>
>   ret void<br>
> }<br>
><br>
> The x86 backend generates the following:<br>
><br>
>         movl    (%rsi), %eax<br>
>         addl    (%rdi), %eax<br>
>         movl    %eax, (%rdx)<br>
>         retq<br>
><br>
> Note in particular the memory operand embedded into the addition.<br>
><br>
> The way the LLVM x86 backend models this is just to pattern match it during instruction selection: it matches a pattern like  (add r, (load addr)) to a single instruction.<br>
<br>
Thanks Eli. I will have a look into it. However, the above x86 code loads the content of the memory location into eax register and adds that register with another memory location.<br>
<br>
My target loads the address of the memory locations in the registers for both the operands and then uses add operation on the registers in an indirect way. How do I specify that in .td files so that it matches in ISelDAGToDAG select() function? Any small example?<br>
<br>
</blockquote>
<br>
Oh, you mean the result goes into memory, not a register?  So, something like the following:<br>
<br>
define void @foo(i32 *%a) {<br>
entry:<br>
  %0 = load i32, i32* %a, align 4<br>
  %add = add i32 %0, 3<br>
  store i32 %add, i32* %a, align 4<br>
  ret void<br>
}<br>
<br>
On x86, this gets turned into:<br>
<br>
        addl    $3, (%rdi)<br>
        retq<br>
<br>
>From X86InstrArithmetic.td:<br>
<br>
// BinOpMI8_RMW - Instructions like "add [mem], imm8".<br>
class BinOpMI8_RMW<string mnemonic, X86TypeInfo typeinfo,<br>
                   SDPatternOperator opnode, Format f><br>
  : BinOpMI8<mnemonic, typeinfo, f,<br>
             [(store (opnode (load addr:$dst),<br>
                             typeinfo.Imm8Operator:$src), addr:$dst),<br>
              (implicit EFLAGS)]>;<br>
<br>
-Eli<br>
<br>
-- <br>
Employee of Qualcomm Innovation Center, Inc.<br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br>
<br>
</blockquote></div></div>