This is an archive of the discontinued LLVM Phabricator instance.

[LSR] Return nullptr from getExpr if the result isn't invertible.
ClosedPublic

Authored by fhahn on Jun 17 2023, 9:48 AM.

Details

Summary

getExpr is missing a check to make sure the result is invertible.
This can lead to incorrect results, so return nullptr in those cases
like in other places in IVUsers.

Fixes #62660.

Diff Detail

Event Timeline

fhahn created this revision.Jun 17 2023, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2023, 9:48 AM
fhahn requested review of this revision.Jun 17 2023, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2023, 9:48 AM
qcolombet accepted this revision.Jun 19 2023, 12:17 AM

I was wondering if we should have a separate isInvertible API and keep getExpr as is, but a glance at how getExpr is used everywhere tells me that's probably overkill.

LGTM

This revision is now accepted and ready to land.Jun 19 2023, 12:17 AM
nikic added a comment.Jun 19 2023, 1:26 AM

Can we change normalizeForPostIncUse() to return nullptr if it does not round trip, so that all users are forced to handle this? Pretty sure this is still going to leave holes behind.

fhahn added a comment.Jun 19 2023, 4:06 AM

Can we change normalizeForPostIncUse() to return nullptr if it does not round trip, so that all users are forced to handle this? Pretty sure this is still going to leave holes behind.

This is something I tried, but the fallout seemed quite big (in terms of test changes) so I think it would be better to incrementally make things stricter.

fhahn updated this revision to Diff 533603.Jun 22 2023, 7:48 AM

Rebased on top of current main, I am planning on landing this shortly as first step