Skip to content

Commit 1edc51b

Browse files
committed
[InstCombine] Explicitly check for scalable TypeSize.
Instead of assuming it is a fixed size. Reviewed By: peterwaller-arm Differential Revision: https://reviews.llvm.org/D136517
1 parent 006bf8d commit 1edc51b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,13 @@ static bool isObjectSizeLessThanOrEq(Value *V, uint64_t MaxSize,
769769
if (!CS)
770770
return false;
771771

772-
uint64_t TypeSize = DL.getTypeAllocSize(AI->getAllocatedType());
772+
TypeSize TS = DL.getTypeAllocSize(AI->getAllocatedType());
773+
if (TS.isScalable())
774+
return false;
773775
// Make sure that, even if the multiplication below would wrap as an
774776
// uint64_t, we still do the right thing.
775-
if ((CS->getValue().zext(128) * APInt(128, TypeSize)).ugt(MaxSize))
777+
if ((CS->getValue().zext(128) * APInt(128, TS.getFixedSize()))
778+
.ugt(MaxSize))
776779
return false;
777780
continue;
778781
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -instcombine -S %s | FileCheck %s
3+
4+
define i8 @foo(<vscale x 1 x i8> %x, i64 %idx) {
5+
; CHECK-LABEL: @foo(
6+
; CHECK-NEXT: [[A:%.*]] = alloca <vscale x 1 x i8>, align 1
7+
; CHECK-NEXT: store <vscale x 1 x i8> [[X:%.*]], ptr [[A]], align 1
8+
; CHECK-NEXT: [[B:%.*]] = getelementptr i8, ptr [[A]], i64 [[IDX:%.*]]
9+
; CHECK-NEXT: [[C:%.*]] = load i8, ptr [[B]], align 1
10+
; CHECK-NEXT: ret i8 [[C]]
11+
;
12+
%a = alloca <vscale x 1 x i8>
13+
store <vscale x 1 x i8> %x, ptr %a
14+
%b = getelementptr i8, ptr %a, i64 %idx
15+
%c = load i8, ptr %b
16+
ret i8 %c
17+
}

0 commit comments

Comments
 (0)