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

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 11:06:13 PDT 2021


nikic added a comment.

In D110977#3067292 <https://reviews.llvm.org/D110977#3067292>, @reames wrote:

> Quick scan only.  I don't have a lot of context on this code.
>
> Approach wise, it would seem lower risk to model explicit truncates before adding the implicit trunc on gep operands.  (i.e. easier to write test cases, less likelihood of wide spread miscompiles if we got it slightly wrong, less interaction w/e.g. "pointer size" piece)  Can I ask why you approached it this was instead?

We already model explicit truncs correctly, simply by dint of treating them as opaque values. I'm interested in implicit truncs here because they're currently being miscompiled.



================
Comment at: llvm/lib/Analysis/BasicAliasAnalysis.cpp:292
                         NewV->getType()->getPrimitiveSizeInBits();
+    if (ExtendBy <= TruncBits)
+      return ExtendedValue(NewV, ZExtBits, SExtBits, TruncBits - ExtendBy);
----------------
reames wrote:
> I don't believe this is correct.  What if we trunced off non-zero bits and are no zero extending?
This method replaces `V` with `zext(NewV)`. So we now have something like `trunc(zext(NewV))`. If we extend less than we truncate, then we'll be left with just a `trunc(NewV)` (this case). If we truncate less than we extend, we're left with just `zext(NewV)`, which gets folded into the outer zext/sext (the existing case below).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110977/new/

https://reviews.llvm.org/D110977



More information about the llvm-commits mailing list