[PATCH] D110977: [BasicAA] Model implicit trunc of GEP indices

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 1 14:48:35 PDT 2021


nikic created this revision.
nikic added reviewers: fhahn, asbirlea, jdoerfert, reames.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

GEP indices larger than the GEP index size are implicitly truncated to the index size. BasicAA currently doesn't model this, resulting in incorrect alias analysis results.

Fix this by explicitly modelling truncation in ExtendedValue in the same way we do zext and sext. Additionally we need to disable a number of optimizations for truncated values, in particular "non-zero" and "non-equal" may no longer hold after truncation. I believe the constant offset heuristic is also not necessarily correct for truncated values, but wasn't able to come up with a test for that one.

A possible followup here would be to use the new mechanism to model explicit `trunc` as well (which should be much more common, as it is the canonical form). This is straightforward, but omitted here to separate the correctness fix from the analysis improvement.

(Side note: While I say "index size" above, BasicAA currently uses the pointer size instead. Something for another day...)


https://reviews.llvm.org/D110977

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110977.376640.patch
Type: text/x-patch
Size: 9841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211001/4cff821b/attachment.bin>


More information about the llvm-commits mailing list