[PATCH] D153270: [BasicAA] Fix nsw handling for negated scales (PR63266)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 05:48:08 PDT 2023


nikic created this revision.
nikic added reviewers: fhahn, asbirlea.
Herald added subscribers: jeroen.dobbelaere, StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D153270

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Analysis/BasicAA/range.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153270.532619.patch
Type: text/x-patch
Size: 4209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230619/e3cdbba1/attachment.bin>


More information about the llvm-commits mailing list