Skip to content

Commit 4d78801

Browse files
authored
[InferAlignment] Fix updating alignment when larger than i32 (#160109)
Summary: The changes made in #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.
1 parent b7a848e commit 4d78801

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/Scalar/InferAlignment.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static bool tryToImproveAlign(
5757
cast<ConstantInt>(II->getArgOperand(AlignOpIdx))->getAlignValue();
5858
Align PrefAlign = DL.getPrefTypeAlign(Type);
5959
Align NewAlign = Fn(PtrOp, OldAlign, PrefAlign);
60-
if (NewAlign <= OldAlign)
60+
if (NewAlign <= OldAlign ||
61+
NewAlign.value() > std::numeric_limits<uint32_t>().max())
6162
return false;
6263

6364
Value *V =

llvm/test/Transforms/InferAlignment/masked.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ entry:
2929
ret void
3030
}
3131

32+
define <2 x i32> @null(<2 x i1> %mask, <2 x i32> %val) {
33+
; CHECK-LABEL: define <2 x i32> @null(
34+
; CHECK-SAME: <2 x i1> [[MASK:%.*]], <2 x i32> [[VAL:%.*]]) {
35+
; CHECK-NEXT: [[ENTRY:.*:]]
36+
; 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]])
37+
; CHECK-NEXT: ret <2 x i32> [[MASKED_LOAD]]
38+
;
39+
entry:
40+
%masked_load = tail call <2 x i32> @llvm.masked.load.v2f64.p0(ptr null, i32 1, <2 x i1> %mask, <2 x i32> %val)
41+
ret <2 x i32> %masked_load
42+
}
43+
3244
declare void @llvm.assume(i1)
3345
declare <2 x i32> @llvm.masked.load.v2i32.p0(ptr, i32, <2 x i1>, <2 x i32>)
3446
declare void @llvm.masked.store.v2i32.p0(<2 x i32>, ptr, i32, <2 x i1>)

0 commit comments

Comments
 (0)