[AssumeBundles] ValueTracking cannot use alignment assumptions?

Hello,

As I can see, recently LLVM switched to using assume bundles to encode alignment information: rG78de7297abe2

However, it seems that the ValueTracking cannot understand the new format. As an example, consider compilation of the following reproducer with clang-11 (old assume format) and clang-trunk (assume bundles):

  #include <stdint.h>
  int foo(int *p) {
    __builtin_assume_aligned(p, 32);
    return ((intptr_t) p) & 4;
  }

clang-11 (Compiler Explorer) computes the returned value statically:

  ret i32 0

clang-trunk (Compiler Explorer) fails to optimize the code:

  %3 = ptrtoint i32* %0 to i64
  %4 = trunc i64 %3 to i32
  %5 = and i32 %4, 4
  ret i32 %5

As one can see, after switching to operand bundles, clang-trunk lost its ability to reason about low bits in aligned pointers.

So, I wonder if there are any plans to teach ValueTracking how to use alignment information from assume bundles? And if not, should we revert to the old format for alignment assumptions until ValueTracking is improved?

Thanks,
Nikolai

That sounds like a bug, yes.
Please file a bug? :slight_smile:

Roman

Sure. Submitted https://bugs.llvm.org/show_bug.cgi?id=48224

-Nikolai