<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <br>
    <div class="moz-cite-prefix">On 03/25/2016 08:00 AM, Xiangyang Guo
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAApsxOGK8NWsbQEd6w_NUhKtMNnDvQLerm63ALB1-mR8g2a7HQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">Thanks for your reply, Philip.
        <div><br>
        </div>
        <div>You are right, when I use LLVM-3.8, the '<span
            style="font-size:14px">argmemonly</span>' shows up.
          Previously, I use LLVM-3.7.</div>
        <div><br>
        </div>
        <div>I think <span style="font-size:14px">idempotent is what I
            want. Can you tell me how to add </span><span
            style="font-size:14px">idempotent attribute to the function?
            Thanks.</span></div>
      </div>
    </blockquote>
    We do not have such an attribute today.  If you're interested in
    trying to propose and formalize one, we could talk about that.  You
    should take a close look at readonly as well.  Read the definition
    closely; it does allow functions which write memory provided that
    write is not observable externally.  Depending on what your
    intrinsic does, that can be really useful property.<br>
    <blockquote
cite="mid:CAApsxOGK8NWsbQEd6w_NUhKtMNnDvQLerm63ALB1-mR8g2a7HQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><span style="font-size:14px"><br>
          </span></div>
        <div><span style="font-size:14px">Regards,</span></div>
        <div><span style="font-size:14px"><br>
          </span></div>
        <div><span style="font-size:14px">Xiangyang</span></div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">2016-03-24 14:30 GMT-07:00 Philip
          Reames <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span>:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF"><span class=""> <br>
                <br>
                <div>On 03/24/2016 12:45 PM, Xiangyang Guo via llvm-dev
                  wrote:<br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">Hi, 
                    <div><br>
                    </div>
                    <div>When I define an intrinsic function with memory
                      write permission, my assumption is that we can
                      either attach [IntrReadWriteArgMem] or [] to the
                      intrinsic function. Based on the comment of the
                      source code , "IntrReadWriteArgMem - This
                      intrinsic reads and writes only from memory that
                      one of its arguments points to, but may access an
                      unspecified amount." "If no property is set, the
                      worst case is assumed (it may read and write any
                      memory it can get access to and it may have other
                      side effects)". </div>
                    <div><br>
                    </div>
                    <div>But when I define the intrinsic function with
                      different attributes, there is no difference when
                      I dump the IR. For example, two intrinsic
                      functions are </div>
                    <div><br>
                    </div>
                    <div>
                      <div>def int_foo5 : Intrinsic<[],
                        [llvm_ptr_ty], [IntrReadWriteArgMem]>;</div>
                      <div>def int_foo6 : Intrinsic<[],
                        [llvm_ptr_ty], []>;</div>
                    </div>
                    <div><br>
                    </div>
                    <div>Then I write a very simple module, in each
                      module the intrinsic function is called twice as
                      shown below:</div>
                    <div><br>
                    </div>
                    <div>/******the intrinsic function foo5 is
                      used******/</div>
                    <div>
                      <div>; Function Attrs: nounwind</div>
                      <div>define void @_Z3fooPi(i8* %a) #0 {</div>
                      <div>  call void @llvm.foo5(i8* %a)</div>
                      <div>  call void @llvm.foo5(i8* %a)</div>
                      <div>  ret void</div>
                      <div>}</div>
                      <div>; Function Attrs: nounwind</div>
                      <div>declare void @llvm.foo5(i8*) #0</div>
                      <div>attributes #0 = { nounwind }</div>
                    </div>
                  </div>
                </blockquote>
              </span> This is strange.  I would expect this to introduce
              the argmemonly attribute.  Can you confirm that you're on
              tip-of-tree and not some previous LLVM release version?<span
                class=""><br>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div><br>
                    </div>
                    <div><br>
                    </div>
                    <div>/****** the intrinsic function foo6 is
                      used******/</div>
                    <div>
                      <div>; Function Attrs: nounwind</div>
                      <div>define void @_Z3fooPi(i8* %a) #0 {</div>
                      <div>  call void @llvm.foo6(i8* %a)</div>
                      <div>  call void @llvm.foo6(i8* %a)</div>
                      <div>  ret void</div>
                      <div>}</div>
                      <div>; Function Attrs: nounwind</div>
                      <div>declare void @llvm.foo6(i8*) #0</div>
                      <div>attributes #0 = { nounwind }</div>
                    </div>
                    <div><br>
                    </div>
                    <div>And my when I apply -O3 optimization level for
                      these two bitcode, I hope the second call can be
                      eliminated. But from the result, it doesn't. </div>
                  </div>
                </blockquote>
              </span> Removing the previous call would be an incorrect
              optimization.  Specifically, the intrinsic "foo5" could be
              an increment of the passed memory location.  Removing one
              of the two increments would be incorrect.<br>
              <br>
              I suspect you actually know something stronger about the
              intrinsic.  Is it possible readonly?  Or write only?  Or
              idempotent?  Or something else?<br>
              <blockquote type="cite"><span class="">
                  <div dir="ltr">
                    <div>For intrinsic functio foo5, I don't understand
                      it. I mean, when I apply [IntrReadWriteArgMem] to
                      this intrinsic function, I hope the LLVM can know
                      the second one is redundant because nothing is
                      changed. Can you tell why LLVM cannot optimize it
                      in this case?</div>
                    <div><br>
                    </div>
                    <div>Any input is appreciable.</div>
                    <div><br>
                    </div>
                    <div>Regards,</div>
                    <div><br>
                    </div>
                    <div>Xiangyang</div>
                    <div><br>
                    </div>
                    <div><br>
                    </div>
                  </div>
                  <br>
                  <fieldset></fieldset>
                  <br>
                </span><span class="">
                  <pre>_______________________________________________
LLVM Developers mailing list
<a moz-do-not-send="true" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
                </span></blockquote>
              <br>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>