[llvm-dev] Aliasing and forwarding optimization

Venkataramanan Kumar via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 18 22:16:35 PDT 2020


----Snip--
struct st1{
  int a;
};
struct st2{
  int b;
};
struct st {
  struct st1 obj1;
  struct st2 obj2;
}Obj;

int test1(struct st1 * ptr1 , struct st2 * ptr2, struct st2 *ptr3) {
  ptr1->a = 10;
  *ptr3 = *ptr2;
  return ptr1->a;
}
--Snip---

For the above case GCC is able to store forward the value 10 to the return
place.
LLVM is not doing this.
GCC
https://godbolt.org/z/FCjCXy
LLVM
https://godbolt.org/z/TFgnig

My understanding is that under strict aliasing rules accessing objects of
different types don't alias.
In this case we are accessing  "struct st2" object and "int" type
object. so aliasing should not prevent the forwarding of store 10 to the
return place .

Can someone please clarify this?


regards,
Venkat.

:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200619/f907614a/attachment.html>


More information about the llvm-dev mailing list