[all-commits] [llvm/llvm-project] 1301a8: [BasicAA] Don't unnecessarily extend pointer size

Nikita Popov via All-commits all-commits at lists.llvm.org
Wed Oct 6 09:40:42 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1301a8b473c614f99171728d928b424b56e7ed27
      https://github.com/llvm/llvm-project/commit/1301a8b473c614f99171728d928b424b56e7ed27
  Author: Nikita Popov <nikita.ppv at gmail.com>
  Date:   2021-10-06 (Wed, 06 Oct 2021)

  Changed paths:
    M llvm/lib/Analysis/BasicAliasAnalysis.cpp
    M llvm/test/Analysis/BasicAA/gep-and-alias.ll
    M llvm/test/Analysis/BasicAA/gep-implicit-trunc-32-bit-pointers.ll

  Log Message:
  -----------
  [BasicAA] Don't unnecessarily extend pointer size

BasicAA GEP decomposition currently performs all calculation on the
maximum pointer size, but at least 64-bit, with an option to double
the size. The code comment claims that this improves analysis power
when working with uint64_t indices on 32-bit systems. However, I don't
see how this can be, at least while maintaining correctness:

When working on canonical code, the GEP indices will have GEP index
size. If the original code worked on uint64_t with a 32-bit size_t,
then there will be truncs inserted before use as a GEP index. Linear
expression decomposition does not look through truncs, so this will
be an opaque value as far as GEP decomposition is concerned. Working
on a wider pointer size does not help here (or have any effect at all).

When working on non-canonical code (before first InstCombine), the
GEP indices are implicitly truncated to GEP index size. The BasicAA
code currently just ignores this fact completely, and pretends that
this truncation doesn't happen. This is incorrect and will be
addressed by D110977.

I believe that for correctness reasons, it is important to work on
the actual GEP index size to properly model potential overflow.
BasicAA tries to patch over the fact that it uses the wrong size
(see adjustToPointerSize), but it only does that in limited cases
(only for constant values, and not all of them either). I'd like to
move this code towards always working on the correct size, and
dropping these artificial pointer size adjustments is the first step
towards that.

Differential Revision: https://reviews.llvm.org/D110657




More information about the All-commits mailing list