This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Fix for missing must alias information
ClosedPublic

Authored by Gerolf on Jan 19 2016, 7:18 PM.

Details

Reviewers
reames
hfinkel
Summary

BasicAA performs offset computations in 64b mode independent of the
target. For 32b mode this can result in missing must alias information when
the array offsets wrap-around. The fix checks for the target pointersize and
ensures offsets are computed as 32b offsets for 32b targets.

Diff Detail

Event Timeline

Gerolf updated this revision to Diff 45336.Jan 19 2016, 7:18 PM
Gerolf retitled this revision from to [BasicAA] Fix for missing must alias information.
Gerolf updated this object.
Gerolf added a reviewer: hfinkel.
Gerolf added a subscriber: llvm-commits.
reames requested changes to this revision.Jan 25 2016, 1:26 PM
reames added a reviewer: reames.
reames added a subscriber: reames.

This looks like it should be two separate patches. The mustalias logic should be expressible on 64 bit pointers independent of the wrap around. The 32 bit wrap around logic I'm a bit unclear on. I think that it's correct per the lang ref. At minimum, should be using uint32_t types. Preferably, you'd rephrase this in a generic way which worked for other pointer sizes (i.e. 48 bit?).

This revision now requires changes to proceed.Jan 25 2016, 1:26 PM
Gerolf updated this revision to Diff 46111.Jan 27 2016, 12:24 AM
Gerolf edited edge metadata.

Philip, thank you for your initial review. This is the general and simplified
version you hinted at. Please take a look.

Better, but.. why mask on only some updates vs every one or once at end?

lib/Analysis/BasicAliasAnalysis.cpp
328

Isn't shifting into the sign bit undefined behaviour?

I think what you really want to express is Offset % 0xFF..PointerSize..FF. Why not just write it that way?

461

This line is highly likely wrong. It looks like you're converting to a signed type, doing wrapping there, then converting back. That's suspicious at best.

I suspect you may need to change the signage of the existing code, but that should definitely be separate.

Regarding: "Better, but.. why mask on only some updates vs every one or once at end?"

I took the wrap-around out of inner loop and made sure it is done once for each PointerSize. If we can hoist that out of the loop then the BaseOffs wrap can be pushed out of the outer loop also. That requires at least additional checks on the assumption of a constant PointerSize. That needs a separate commit - if any.

lib/Analysis/BasicAliasAnalysis.cpp
328

In C++ (Section 5.8.2) it actually is well defined: The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are zero-filled.
In older C standards I think at one point it was undefined and later implementation defined when the result did not fit.
And no, for we offset we actually need the sign extension. % doesn't do that.
So I think that code is fine. Agreed?

461

It is "correct" since the bits don't change in that cast: "correct" in the sense of being equivalent to the old code. But I agree with you that this should be an independent commit and take it out.

Gerolf updated this revision to Diff 46214.Jan 27 2016, 7:55 PM
Gerolf edited edge metadata.

Philip, I removed the wrap for Scale as you suggested.
Please check if you agree with my comments. Thank you!

Aside from the suspected UB (which I think Philip was right about,
see my comments inline below), this seems pretty obviously correct.

A have a couple of other nitpicks below, but after that LGTM.
Philip, did you have anything else on your side?

I'm happy to defer to Duncan here.

lib/Analysis/BasicAliasAnalysis.cpp
324

correct -> precise. Very different in this context.

Thank you Duncan + Philip! Committed NFC is r259290+r259298, the actual fix is 259299. And you convinced me to finally get rid of my outdated C/C++ standards ... :-)

lib/Analysis/BasicAliasAnalysis.cpp
324

Done: r259300

reames accepted this revision.Mar 9 2016, 12:12 PM
reames edited edge metadata.

per previous comment from author patches have landed.

This revision is now accepted and ready to land.Mar 9 2016, 12:12 PM
reames closed this revision.Mar 9 2016, 12:12 PM