This is an archive of the discontinued LLVM Phabricator instance.

[SCEVExpander] Simplify pointer overflow check
ClosedPublic

Authored by nikic on Sep 1 2021, 2:24 PM.

Details

Summary

This is a followup to D104662 to generate slightly nicer code for pointer overflow checks. Bypass expandAddToGEP and instead explicitly generate i8 GEPs. This saves some bitcasts and negates the value in a more obvious way. In particular, this prevents SCEV from looking through the umul.with.overflow, same as in the integer case.

The wrapping-pointer-ni.ll test deserves a comment: Previously, this generated a typed GEP which used the umul argument rather then the multiplication result. This results in more compact IR in that case, but effectively does the multiplication twice, the second one is just hidden in the GEP. Reusing the umulo result seems pretty reasonable to me.

Diff Detail

Event Timeline

nikic created this revision.Sep 1 2021, 2:24 PM
nikic requested review of this revision.Sep 1 2021, 2:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2021, 2:24 PM
mkazantsev accepted this revision.Sep 1 2021, 9:56 PM

Looks fine!

This revision is now accepted and ready to land.Sep 1 2021, 9:56 PM
This revision was landed with ongoing or failed builds.Sep 2 2021, 11:16 AM
This revision was automatically updated to reflect the committed changes.