[llvm-dev] [AssumeBundles] ValueTracking cannot use alignment assumptions?

Bozhenov, Nikolai via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 17 19:26:51 PST 2020


Hello,

As I can see, recently LLVM switched to using assume bundles to encode alignment information: https://reviews.llvm.org/rG78de7297abe2e8fa782682168989c70e3cb34a5c

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 (https://godbolt.org/z/xGh1e4) computes the returned value statically:

  ret i32 0

clang-trunk (https://godbolt.org/z/1jWe5j) 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


More information about the llvm-dev mailing list