[PATCH] D99424: [BasicAA] Be more careful with modulo ops on VariableGEPIndex.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 03:06:01 PDT 2021


fhahn added a comment.

In D99424#2849458 <https://reviews.llvm.org/D99424#2849458>, @mstorsjo wrote:

> The problem appears with https://martin.st/temp/pixlet-preproc.c, compiled with “clang -target aarch64-w64-mingw32 -c -O3 pixlet-preproc.c”. I haven’t pinpointed exactly what changes and whether that’s wrong or if the source itself relies on something undefined though, or if there’s some strict aliasing violation.

Thanks for the heads-up!

I suspect that setting `Scale = APInt::getOneBitSet(Scale.getBitWidth(),` may be at fault here. With the change below, which makes BasicAA more conservative for that case, I don't get any differences with your reproducer. Could you try if that fixes the end-to-end miscomputation?

  diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
  index da489b8d457f..81823b7ea778 100644
  --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
  +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
  @@ -1149,8 +1149,7 @@ AliasResult BasicAAResult::aliasGEP(
       for (unsigned i = 0, e = DecompGEP1.VarIndices.size(); i != e; ++i) {
         APInt Scale = DecompGEP1.VarIndices[i].Scale;
         if (!DecompGEP1.VarIndices[i].IsNSW)
  -        Scale = APInt::getOneBitSet(Scale.getBitWidth(),
  -                                    Scale.countTrailingZeros());
  +        GCD = APInt(Scale.getBitWidth(), 1);
  
         if (i == 0)
           GCD = Scale.abs();


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99424



More information about the llvm-commits mailing list