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.
Details
Diff Detail
Event Timeline
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?).
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? | |
458 | 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. | |
458 | 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. |
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 |
correct -> precise. Very different in this context.