[PATCH] D153308: Analysis: Fix assertion when load alignment exceeds address space size

Guillaume Chatelet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 20 04:52:39 PDT 2023


gchatelet added inline comments.


================
Comment at: llvm/lib/Analysis/Loads.cpp:45
+  return !(Offset & (APAlign - 1));
 }
 
----------------
How about the following code:
```
static bool isAligned(const Value *Base, const APInt &Offset, Align Alignment,
                      const DataLayout &DL) {
  Align BA = Base->getPointerAlignment(DL);
  if (BA < Alignment)
    return false;
  const unsigned OffsetTrailingZeroes = Offset.countr_zero();
  const unsigned MinimumTrailingZeroes = Log2(Alignment);
  return OffsetTrailingZeroes >= MinimumTrailingZeroes;
}
```

FYI `Log2(Alignment)` [is free](https://github.com/llvm/llvm-project/blob/6bea8331f9e09ba94a225c65becd4224a1a473af/llvm/include/llvm/Support/Alignment.h#L208).


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

https://reviews.llvm.org/D153308



More information about the llvm-commits mailing list