This is an archive of the discontinued LLVM Phabricator instance.

[GMR] isNonEscapingGlobalNoAlias() should look through Bitcasts/GEPs when looking at loads.
ClosedPublic

Authored by mkuper on Aug 16 2015, 4:55 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

mkuper updated this revision to Diff 32240.Aug 16 2015, 4:55 AM
mkuper retitled this revision from to [GMR] isNonEscapingGlobalNoAlias() should look through Bitcasts/GEPs when looking at loads..
mkuper updated this object.
mkuper added a reviewer: chandlerc.
mkuper added a subscriber: llvm-commits.
hfinkel added inline comments.
lib/Analysis/IPA/GlobalsModRef.cpp
654 ↗(On Diff #32240)

It seems like we could make this more general is two ways:

  1. Call GetUnderlyingObjects, and checking that all of the results are GlobalValues
  2. Also checking that the underlying objects are not arguments or call/invoke return values.

If I'm reading this code correctly, one possible way of handling this, is just to do this:

push.Inputs(LI->getPointerOperand());
continue;

which seems to accomplish both things, and keeps an integrated Depth constraint.

chandlerc added inline comments.Aug 16 2015, 3:38 PM
lib/Analysis/IPA/GlobalsModRef.cpp
654 ↗(On Diff #32240)

You're saying a pointer loaded from an escaping pointer is itself escaping?

I think I agree, but it makes this surprisingly more powerful. This will chase a chain of loads until it hits control flow or a known underlying object. Nifty, but maybe surprising.

However, unless I'm mistaken, we still need to call GetUnderlyingObject? The worklist doesn't do that.

I'm a bit scared about using GetUnderlyingObjects making this significantly more slow...

hfinkel added inline comments.Aug 16 2015, 4:24 PM
lib/Analysis/IPA/GlobalsModRef.cpp
654 ↗(On Diff #32240)

Responses below, but actually, it seems that we can do even better than this:

A non-addr-taken global does not have its address stored anywhere, ever. Thus, if we get a pointer from a load, it cannot be a non-addr-taken global (except for those in AllocsForIndirectGlobals). No?

You're saying a pointer loaded from an escaping pointer is itself escaping?

Yes, I think that's correct.

I think I agree, but it makes this surprisingly more powerful. This will chase a chain of loads until it hits control flow or a known underlying object. Nifty, but maybe surprising.

With a depth limit of 4, it is not going to do very *much* chasing ;) - but, yes, that's the idea.

However, unless I'm mistaken, we still need to call GetUnderlyingObject? The worklist doesn't do that.

Ah, yes, correct. The existing worklist does not look though GEPs. Should it?

I'm a bit scared about using GetUnderlyingObjects making this significantly more slow...

Indeed; this was my motivation for suggesting using the existing worklist (to get the unified depth limit).

Thanks for the idea, Hal.
But, unless I'm missing something, this doesn't quite work, because the base condition is different.

Let's say you have:
%v = load i32, i32* @g1

isNonEscapingGlobalNoAlias(@g1, @g1) should return false, but isNonEscapingGlobalNoAlias(@g1, %v) should return true.
So we can't just push @g1 onto the worklist.

chandlerc accepted this revision.Aug 17 2015, 1:30 AM
chandlerc edited edge metadata.

Let's start with the patch as-is. I'm sure that this at least is correct and unlikely to be problematic for compile time, while it is sufficient to solve real world performance problems.

We can revisit other designs as follow-up patches.

Michael, feel free to submit, and we can keep poking at what the exact right model here is.

This revision is now accepted and ready to land.Aug 17 2015, 1:30 AM

Thanks for the idea, Hal.
But, unless I'm missing something, this doesn't quite work, because the base condition is different.

Let's say you have:
%v = load i32, i32* @g1

isNonEscapingGlobalNoAlias(@g1, @g1) should return false, but isNonEscapingGlobalNoAlias(@g1, %v) should return true.
So we can't just push @g1 onto the worklist.

Good point.

This revision was automatically updated to reflect the committed changes.