[llvm] [InferAlignment] Fix updating alignment when larger than i32 (PR #160109)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 06:48:07 PDT 2025
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/160109
Summary:
The changes made in https://github.com/llvm/llvm-project/pull/156057
allows the alignment value to be increased. We assert effectively
infinite alignment when the pointer argument is invalid / null. The
problem is that for whatever reason the masked load / store functions
use i32 for their alignment value which means this gets truncated to
zero.
Add a special check for this, long term we probably want to just remove
this argument entirely.
>From 84e273e464034e2042618e9b991926c65d22425b Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 22 Sep 2025 08:45:47 -0500
Subject: [PATCH] [InferAlignment] Fix updating alignment when larger than i32
Summary:
The changes made in https://github.com/llvm/llvm-project/pull/156057
allows the alignment value to be increased. We assert effectively
infinite alignment when the pointer argument is invalid / null. The
problem is that for whatever reason the masked load / store functions
use i32 for their alignment value which means this gets truncated to
zero.
Add a special check for this, long term we probably want to just remove
this argument entirely.
---
llvm/lib/Transforms/Scalar/InferAlignment.cpp | 3 ++-
llvm/test/Transforms/InferAlignment/masked.ll | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Scalar/InferAlignment.cpp b/llvm/lib/Transforms/Scalar/InferAlignment.cpp
index b60b15b6c3a2b..995b80396b8af 100644
--- a/llvm/lib/Transforms/Scalar/InferAlignment.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAlignment.cpp
@@ -57,7 +57,8 @@ static bool tryToImproveAlign(
cast<ConstantInt>(II->getArgOperand(AlignOpIdx))->getAlignValue();
Align PrefAlign = DL.getPrefTypeAlign(Type);
Align NewAlign = Fn(PtrOp, OldAlign, PrefAlign);
- if (NewAlign <= OldAlign)
+ if (NewAlign <= OldAlign ||
+ NewAlign.value() > std::numeric_limits<uint32_t>().max())
return false;
Value *V =
diff --git a/llvm/test/Transforms/InferAlignment/masked.ll b/llvm/test/Transforms/InferAlignment/masked.ll
index 1b8d26417d75e..13acf9b50e7e8 100644
--- a/llvm/test/Transforms/InferAlignment/masked.ll
+++ b/llvm/test/Transforms/InferAlignment/masked.ll
@@ -29,6 +29,18 @@ entry:
ret void
}
+define <2 x i32> @null(<2 x i1> %mask, <2 x i32> %val) {
+; CHECK-LABEL: define <2 x i32> @null(
+; CHECK-SAME: <2 x i1> [[MASK:%.*]], <2 x i32> [[VAL:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[MASKED_LOAD:%.*]] = tail call <2 x i32> @llvm.masked.load.v2i32.p0(ptr null, i32 1, <2 x i1> [[MASK]], <2 x i32> [[VAL]])
+; CHECK-NEXT: ret <2 x i32> [[MASKED_LOAD]]
+;
+entry:
+ %masked_load = tail call <2 x i32> @llvm.masked.load.v2f64.p0(ptr null, i32 1, <2 x i1> %mask, <2 x i32> %val)
+ ret <2 x i32> %masked_load
+}
+
declare void @llvm.assume(i1)
declare <2 x i32> @llvm.masked.load.v2i32.p0(ptr, i32, <2 x i1>, <2 x i32>)
declare void @llvm.masked.store.v2i32.p0(<2 x i32>, ptr, i32, <2 x i1>)
More information about the llvm-commits
mailing list