Skip to content

Commit b0edc1c

Browse files
authored
[Loads] Fix crash in isSafeToLoadUnconditionally with scalable accessed type (#82650)
This fixes #82606 by updating isSafeToLoadUnconditionally to handle fixed sized loads from a scalable accessed type.
1 parent 6599c02 commit b0edc1c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size,
364364

365365
if (Size.getBitWidth() > 64)
366366
return false;
367-
const uint64_t LoadSize = Size.getZExtValue();
367+
const TypeSize LoadSize = TypeSize::getFixed(Size.getZExtValue());
368368

369369
// Otherwise, be a little bit aggressive by scanning the local block where we
370370
// want to check to see if the pointer is already being loaded or stored
@@ -414,11 +414,11 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, APInt &Size,
414414

415415
// Handle trivial cases.
416416
if (AccessedPtr == V &&
417-
LoadSize <= DL.getTypeStoreSize(AccessedTy))
417+
TypeSize::isKnownLE(LoadSize, DL.getTypeStoreSize(AccessedTy)))
418418
return true;
419419

420420
if (AreEquivalentAddressValues(AccessedPtr->stripPointerCasts(), V) &&
421-
LoadSize <= DL.getTypeStoreSize(AccessedTy))
421+
TypeSize::isKnownLE(LoadSize, DL.getTypeStoreSize(AccessedTy)))
422422
return true;
423423
}
424424
return false;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt < %s -passes=vector-combine -S -mtriple=riscv32 -mattr=+v | FileCheck %s
3+
; RUN: opt < %s -passes=vector-combine -S -mtriple=riscv64 -mattr=+v | FileCheck %s
4+
5+
define void @fixed_load_scalable_src(ptr %p) {
6+
; CHECK-LABEL: define void @fixed_load_scalable_src(
7+
; CHECK-SAME: ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: store <vscale x 4 x i16> zeroinitializer, ptr [[P]], align 8
10+
; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i16>, ptr [[P]], align 8
11+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i16> [[TMP0]], <4 x i16> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
12+
; CHECK-NEXT: ret void
13+
;
14+
entry:
15+
store <vscale x 4 x i16> zeroinitializer, ptr %p
16+
%0 = load <4 x i16>, ptr %p
17+
%1 = shufflevector <4 x i16> %0, <4 x i16> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
18+
ret void
19+
}

0 commit comments

Comments
 (0)