This is an archive of the discontinued LLVM Phabricator instance.

[SeparateConstOffsetFromGEP] inbounds zext => sext for better splitting
ClosedPublic

Authored by jingyue on Jun 7 2014, 9:44 PM.

Details

Reviewers
eliben
meheff
Summary

For each array index of GEP in the form of zext(a), convert it to sext(a)
if we can prove zext(a) <= max signed value of typeof(a). The conversion
helps to split zext(x + y) into sext(x) + sext(y).

Depends on D4056

Diff Detail

Event Timeline

jingyue updated this revision to Diff 10215.Jun 7 2014, 9:44 PM
jingyue retitled this revision from to [SeparateConstOffsetFromGEP] inbounds zext => sext for better splitting.
jingyue updated this object.
jingyue edited the test plan for this revision. (Show Details)
jingyue added reviewers: eliben, meheff.
jingyue added a subscriber: Unknown Object (MLST).
meheff accepted this revision.Jun 8 2014, 11:39 AM
meheff edited edge metadata.

LGTM after clarifying and fixing some of the comments.

lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
268

spelling: Verified. Also it would be good to include in this comment why it is advantageous to convert zexts in to sexts. It's not immediately clear because like zext for some values of a and b: sext(a + b) != sext(a) + sext(b). Include the how sext and add with positive result is handled as a special case while no such case exists for zext.

316

Doesn't have to be done in this change, but this function would be easier to follow if every if statement conditionally returned true and then false was returned at the bottom (or vice versa). That is, the if statements should explicitly enumerate the accepted cases. As it is, some return true some return false which implies some dependencies between the ifs which makes the logic more complicated than necessary to follow.

621

This comment is a little confusing. Maybe something like:

For GEP operand a, if a <= max signed value of typeof(a), then the sign bit of a is zero and sext(a) = zext(a). Because the GEP is inbounds, we know a <= ObjectSize, so the necessary condition can be reduced to ObjectSize <= max signed value of typeof(a).

test/Transforms/SeparateConstOffsetFromGEP/NVPTX/split-gep-and-gvn.ll
102

Similar to sum_of_array2

This revision is now accepted and ready to land.Jun 8 2014, 11:39 AM
jingyue updated this revision to Diff 10220.Jun 8 2014, 3:01 PM
jingyue edited edge metadata.

Thanks! Updated the comments.

jingyue added inline comments.Jun 8 2014, 3:03 PM
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
268

done

316

ack'ed

621

done

test/Transforms/SeparateConstOffsetFromGEP/NVPTX/split-gep-and-gvn.ll
102

actually more similar to sum_of_array

jingyue closed this revision.Jun 8 2014, 4:57 PM

Committed in r210444