[PATCH] D91027: [BasicAA] Generalize base offset modulus handling

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 8 01:49:17 PST 2020


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

The GEP aliasing implementation currently has two pieces of code that solve two different subsets of the same basic problem: If you have GEPs with offsets `4*x + 0` and `4*y + 1` (assuming access size 1), then they do not alias regardless of whether x and y are the same.

One implementation is in aliasSameBasePointerGEPs(), which looks at this in a limited structural way. It requires both GEP base pointers to be exactly the same, then (optionally) a number of equal indexes, then an unknown index, then a non-equal index into a struct. This set of limitations works, but it's overly restrictive and hides the core property we're trying to exploit.

The second implementation is part of aliasGEP() itself and tries to find a common modulus in the scales, so it can then check that the constant offset doesn't overlap under modular arithmetic. The second implementation has the right idea of what the general problem is, but effectively only considers power of two factors in the scales (while aliasSameBasePointerGEPs also works with non-pow2 struct sizes.)

What this patch does is to adjust the aliasGEP() implementation to instead find the largest common factor in all the scales (i.e. the GCD) and use that as the modulus.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91027

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Analysis/BasicAA/struct-geps.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91027.303699.patch
Type: text/x-patch
Size: 6189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201108/6c4edf45/attachment.bin>


More information about the llvm-commits mailing list