[llvm] [Attributor] Propagate alignment through ptrmask (PR #150158)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 20:28:14 PDT 2025
================
@@ -5187,6 +5187,59 @@ struct AADereferenceableCallSiteReturned final
// ------------------------ Align Argument Attribute ------------------------
namespace {
+
+Align getKnownAlignForIntrinsic(Attributor &A, AAAlign &QueryingAA,
+ const IntrinsicInst &II) {
+ switch (II.getIntrinsicID()) {
+ case Intrinsic::ptrmask: {
+ const auto *ConstVals = A.getAAFor<AAPotentialConstantValues>(
+ QueryingAA, IRPosition::value(*(II.getOperand(1))), DepClassTy::NONE);
+ const auto *AlignAA = A.getAAFor<AAAlign>(QueryingAA, IRPosition::value(II),
+ DepClassTy::NONE);
+ if (ConstVals && ConstVals->isValidState() && ConstVals->isAtFixpoint()) {
+ unsigned ShiftValue =
+ std::min(ConstVals->getAssumedMinTrailingZeros(), (unsigned)63);
+ Align ConstAlign(1 << ShiftValue);
+ if (ConstAlign >= AlignAA->getKnownAlign())
+ return Align(1);
----------------
Shoreshen wrote:
Hi @arsenm , assume we have `%p = llvm.ptrmask(%x, %mask)` and `AlignAA` is for `%p`, `ConstAlign` is for `%mask`.
>From the definition of `AAAlign:: Known` we know that `%p` is at least aligned at `AlignAA->getKnownAlign()`. Then if `ConstAlign >= AlignAA->getKnownAlign()` happens, we know that `%mask` is going to cover the alignment requirement of `%p`.
Which actually means that `%x`'s alignment can be lower then `AlignAA->getKnownAlign()`.
In summary, this user of `%x` do not provide any information for the minimum alignment of `%x`
https://github.com/llvm/llvm-project/pull/150158
More information about the llvm-commits
mailing list