[llvm] [Attributor] Propagate alignment through ptrmask (PR #150158)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 30 04:12:05 PDT 2025
================
@@ -5188,6 +5188,83 @@ struct AADereferenceableCallSiteReturned final
// ------------------------ Align Argument Attribute ------------------------
namespace {
+
+static std::optional<uint64_t>
+getKnownAlignForIntrinsic(Attributor &A, AAAlign &QueryingAA,
+ const IntrinsicInst *II) {
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::ptrmask: {
+ auto *ConstVals = A.getAAFor<AAPotentialConstantValues>(
+ QueryingAA, IRPosition::value(*(II->getOperand(1))), DepClassTy::NONE);
+ const AAAlign *AlignAA = A.getAAFor<AAAlign>(
+ QueryingAA, IRPosition::value(*(II)), DepClassTy::NONE);
+ if (ConstVals && ConstVals->isValidState()) {
+ if (ConstVals->isAtFixpoint()) {
+ const DataLayout &DL = A.getDataLayout();
+ unsigned Size =
+ DL.getPointerTypeSizeInBits(II->getOperand(0)->getType());
+ uint64_t TrailingZeros = Size;
+ for (const auto &It : ConstVals->getAssumedSet())
+ if (It.countTrailingZeros() < TrailingZeros)
+ TrailingZeros = It.countTrailingZeros();
+ if (TrailingZeros < Size) {
+ uint64_t Mask = 1 << TrailingZeros;
+ if (Mask >= AlignAA->getKnownAlign().value()) {
+ return 0;
+ }
+ }
+ return AlignAA->getKnownAlign().value();
+ }
+ } else if (AlignAA) {
+ return AlignAA->getKnownAlign().value();
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ return std::nullopt;
+}
+
+static std::optional<uint64_t>
----------------
arsenm wrote:
Keep values in Align
https://github.com/llvm/llvm-project/pull/150158
More information about the llvm-commits
mailing list