This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fix inbounds preservation when swapping GEPs (PR44206)
ClosedPublic

Authored by nikic on May 31 2022, 2:39 AM.

Details

Summary

When reassociating GEPs, we can only keep inbounds if both original GEPs were inbounds, and their offsets have the same sign. For the sake of simplicity I only handle the case where both offsets are non-negative here.

It would probably be fine to just not preserve inbounds at all here, but as I don't see a compile-time impact for adding the isKnownNonNegative() calls I went with this more conservative approach.

Fixes https://github.com/llvm/llvm-project/issues/44206.

Diff Detail

Event Timeline

nikic created this revision.May 31 2022, 2:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 2:39 AM
nikic requested review of this revision.May 31 2022, 2:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 2:39 AM
nlopes accepted this revision.May 31 2022, 5:59 AM

LGTM, sounds like the right approach. Negative indexes are not that common anyway.

This revision is now accepted and ready to land.May 31 2022, 5:59 AM
This revision was landed with ongoing or failed builds.May 31 2022, 6:48 AM
This revision was automatically updated to reflect the committed changes.