--===============6202935915348566273== Content-Type: multipart/alternative; boundary=20cf307ac7ab45d6f3051b9179a4 --20cf307ac7ab45d6f3051b9179a4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 23, 2015 at 11:42 AM, Piotr Padlewski wrote= : > HI, > Yep, our proposal doesn't cover it, because this load ; icmp ; assume; > will land global initilizer function, and main will not see it. > At least if foo would be called multiple times, then we would only have > one load from vtable, but unfortunatelly we will not be able to inline, o= r > make direct call to it with this approach. > I think that this case is rare enough to solve it right now. > > Piotr > > On Thu, Jul 23, 2015 at 10:30 AM, Geoff Berry > wrote: > >> Hi Piotr, >> >> >> >> You may be interested in a recent patch I posted: >> http://reviews.llvm.org/D11043 >> >> >> This patch addresses a de-virtualization case that I=E2=80=99m not sure = would be >> handled by your current proposal, namely that of a virtual call where th= e >> =E2=80=98this=E2=80=99 object is a global variable. >> >> For example: >> >> >> >> struct A { >> >> A(); >> >> virtual void foo(); >> >> }; >> >> void g(A * a) { >> >> a->foo(); >> >> } >> >> >> >> A a; >> >> int main() { >> >> g(&a); >> > We could in principle emit the load/icmp/assume for a's vptr here, but I'm concerned that this is not actually sound in general. Consider: struct A; extern A a; void *p =3D &a; // emit load/icmp/assume here? struct A { virtual void f(); }; A a; If we emit an assume on the vptr at the point where the address of a is taken, we get: @a =3D global %A zeroinitializer void @global_init() { load @a %x =3D icmp @a, @A.vtable call @llvm.assume(%x) store @a, @p call @A::A(@a) } ... where the assume call can be folded to "call @llvm.assume(i1 false)", which (presumably) can be reduced further to "unreachable" (oops). (In Geoff's example, this is sound only because we're guaranteed that 'a' is initialized before we enter 'main', but an optimization that only fires for code within 'main' doesn't sound very useful.) We could support this with something weaker than the current load/icmp/assume pattern: we could imagine an instruction/intrinsic that says "any later load of pointer %p with !invariant.group !g will load the value %q", but that does not imply that the value %q is currently stored in %p. It's not clear to me whether that has sufficient value to be worthwhile= . } >> >> >> >> It might be worth considering if your approach could be extended to >> handle this case. >> >> >> >> -- >> >> Geoff Berry >> >> Employee of Qualcomm Innovation Center, Inc. >> >> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a >> Linux Foundation Collaborative Project >> >> >> >> *From:* llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]= *On >> Behalf Of *Piotr Padlewski >> *Sent:* Wednesday, July 22, 2015 5:56 PM >> *To:* cfe-dev@cs.uiuc.edu Developers; llvmdev@cs.uiuc.edu >> *Subject:* [LLVMdev] Clang devirtualization proposal >> >> >> >> Hi folks, >> >> this summer I will work with Richard Smith on clang devirtualization. >> Check out our proposal: >> >> >> >> >> https://docs.google.com/document/d/1f2SGa4TIPuBGm6y6YO768GrQsA8awNfGEJSB= FukLhYA/edit?usp=3Dsharing >> >> >> >> >> And modified LangRef >> >> http://reviews.llvm.org/D11399 >> >> >> >> >> You can also check out previous disscussion that was started before our >> proposal was ready - >> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-July/044052.html >> >> >> >> Regards >> >> Piotr Padlewski >> > > > _______________________________________________ > cfe-dev mailing list > cfe-dev@cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev > > --20cf307ac7ab45d6f3051b9179a4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On T= hu, Jul 23, 2015 at 11:42 AM, Piotr Padlewski <prazek@google.com> wrote:
HI,
Yep= , our proposal doesn't cover it, because this load ; icmp ; assume; wil= l land global initilizer function, and main will not see it.=C2=A0
At least if foo would be called multiple times, then we would only have o= ne load from vtable, but unfortunatelly we will not be able to inline, or m= ake direct call to it with this approach.
I think that this case = is rare enough to solve it right now.

Piotr
<= /div>

On Thu, Jul 23, 2015 at 10:30 AM, Geoff Berry <<= a href=3D"mailto:gberry@codeaurora.org" target=3D"_blank">gberry@codeaurora= .org> wrote:

Hi Piotr,

=C2=A0

You may be interested in a recent patch I posted: = http://reviews.llvm.org/D11043

This patch addresses a de-vir= tualization case that I=E2=80=99m not sure would be handled by your current= proposal, namely that of a virtual call where the =E2=80=98this=E2=80=99 o= bject is a global variable.

= For example:

= =C2=A0

struct A {

=C2=A0 A();

=C2=A0 virtual void foo();

};

void g(A * a) {

=C2=A0 a->foo();

}

=C2=A0

A a;

int = main() {

=C2= =A0 g(&a);

<= /blockquote>

We could in principle emit the load/icmp/as= sume for a's vptr here, but I'm concerned that this is not actually= sound in general. Consider:

struct A;
e= xtern A a;
void *p =3D &a; // emit load/icmp/assume here?
struct A { virtual void f(); };
A a;

<= div>If we emit an assume on the vptr at the point where the address of a is= taken, we get:

@a =3D global %A zeroinitializer
void @global_init() {
=C2=A0 load @a
=C2=A0 %x= =3D icmp @a, @A.vtable
=C2=A0 call @llvm.assume(%x)
= =C2=A0 store @a, @p
=C2=A0 call @A::A(@a)
}
<= br>
... where the assume call can be folded to "call @llvm.a= ssume(i1 false)", which (presumably) can be reduced further to "u= nreachable" (oops). (In Geoff's example, this is sound only becaus= e we're guaranteed that 'a' is initialized before we enter '= ;main', but an optimization that only fires for code within 'main&#= 39; doesn't sound very useful.)

We could suppo= rt this with something weaker than the current load/icmp/assume pattern: we= could imagine an instruction/intrinsic that says "any later load of p= ointer %p with !invariant.group !g will load the value %q", but that d= oes not imply that the value %q is currently stored in %p. It's not cle= ar to me whether that has sufficient value to be worthwhile.

=

=

}

= =C2=A0

It might be w= orth considering if your approach could be extended to handle this case.=

=C2=A0

-= -

Geoff Berry=

Employee of Qualco= mm Innovation Center, Inc.

Qualcomm Innovation Center, Inc. is a member of Code Aurora For= um, a Linux Foundation Collaborative Project

=

=C2=A0

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@= cs.uiuc.edu] On Behalf Of Piotr Padlewski
Sent: Wednes= day, July 22, 2015 5:56 PM
To: cfe-dev@cs.uiuc.edu Developers; llvmdev@cs.uiuc.edu
Subj= ect: [LLVMdev] Clang devirtualization proposal

=

=C2=A0

Hi folks,

thi= s summer I will work with Richard Smith on clang devirtualization. Check ou= t our proposal:

= =C2=A0

https://= docs.google.com/document/d/1f2SGa4TIPuBGm6y6YO768GrQsA8awNfGEJSBFukLhYA/edi= t?usp=3Dsharing

=C2= =A0

And modified LangRef=

=C2=A0

You can als= o check out previous disscussion that was started before our proposal was r= eady -=C2=A0http://lists.cs.uiuc.edu/pipermail/cfe-dev/= 2015-July/044052.html

=C2=A0

Regards<= u>

Piotr Padlewski



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


--20cf307ac7ab45d6f3051b9179a4-- --===============6202935915348566273== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cfe-dev mailing list cfe-dev@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev --===============6202935915348566273==--