This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Fix nsw handling for negated scales (PR63266)
ClosedPublic

Authored by nikic on Jun 19 2023, 5:48 AM.

Details

Summary

We currently preserve the nsw flag when negating scales, which is incorrect for INT_MIN.

However, just dropping the NSW flag in this case makes BasicAA behavior unreliable and asymmetric, because we may or may not drop the NSW flag depending on which side gets subtracted.

Instead, leave the Scale alone and add an additional IsNegated flag, which indicates that the who VarIndex should be interpreted as a subtraction. This allows us to retain the NSW flag.

When accumulating the offset range, we need to use subtraction instead of adding for IsNegated indices. Everything else works on the absolute value of the scale, so the negation does not matter there.

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

Diff Detail

Event Timeline

nikic created this revision.Jun 19 2023, 5:48 AM
nikic requested review of this revision.Jun 19 2023, 5:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2023, 5:48 AM
fhahn accepted this revision.Jun 26 2023, 1:05 PM

LGTM, thanks!

This revision is now accepted and ready to land.Jun 26 2023, 1:05 PM
This revision was landed with ongoing or failed builds.Jun 27 2023, 12:40 AM
This revision was automatically updated to reflect the committed changes.