This is an archive of the discontinued LLVM Phabricator instance.

Don't look through addrspacecast in GetPointerBaseWithConstantOffset
ClosedPublic

Authored by apilipenko on Sep 19 2016, 8:44 AM.

Details

Summary

This is similar to D13008

Pointers in different addrspaces can have different sizes, so it's not valid to look through addrspace cast calculating base and offset for a value.

Diff Detail

Repository
rL LLVM

Event Timeline

apilipenko updated this revision to Diff 71832.Sep 19 2016, 8:44 AM
apilipenko retitled this revision from to Don't look through addrspacecast in GetPointerBaseWithConstantOffset.
apilipenko updated this object.
apilipenko added reviewers: reames, simoncook.
apilipenko added a subscriber: llvm-commits.
reames added inline comments.Sep 19 2016, 9:38 AM
lib/Analysis/ValueTracking.cpp
2845 ↗(On Diff #71832)

For consistency, you should also change getUnderlyingObject at the same time.

test/Transforms/GVN/PRE/rle.ll
321 ↗(On Diff #71832)

Hm, loosing this optimization seems unfortunate. Any chance we can peak through addrspace casts only when the two pointer sizes are equal?

apilipenko added inline comments.Sep 22 2016, 6:44 AM
lib/Analysis/ValueTracking.cpp
2845 ↗(On Diff #71832)

I don't think that we should. According to the description GetUnderlyingObject "strips off any GEP address adjustments and pointer casts from the specified value, returning the original object being addressed".

GetPointerBaseWithConstantOffset:
"Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset. Return the base and offset to the caller."

GetUnderlyingObject is just more powerful at looking through casts, because some casts can hinder a base plus an offset representation. The same thing happens to Value::stripPointerCasts and Value::stripAndAccumulateInBoundsConstantOffsets.

test/Transforms/GVN/PRE/rle.ll
321 ↗(On Diff #71832)

Because addrspaces don't have clearly defined semantic in langref I think we can do this. Although, in this case I'd also go and change Value::stripAndAccumulateInBoundsConstantOffsets to do the same (currently it doesn't look through addrspace casts at all).

apilipenko updated this revision to Diff 72166.Sep 22 2016, 7:14 AM

Let GetPointerBaseWithConstantOffset look through addrspace casts which doesn't change pointer size

apilipenko added inline comments.Sep 22 2016, 7:15 AM
test/Transforms/GVN/PRE/rle-addrspace-cast.ll
3 ↗(On Diff #72166)

I had to move this test because original rle.ll test is run with datalayout with different pointer sizes in different address spaces.

reames accepted this revision.Sep 23 2016, 2:56 PM
reames edited edge metadata.

LGTM w/comment addressed.

test/Transforms/GVN/PRE/rle-addrspace-cast.ll
1 ↗(On Diff #72166)

You should add a data layout specifier here. I think that we otherwise pick up the default for a given host which might cause this test to spurious fail.

This revision is now accepted and ready to land.Sep 23 2016, 2:56 PM
This revision was automatically updated to reflect the committed changes.