Skip to content

Commit 2ea5495

Browse files
committed
[InstCombine][SVE] Fix InstCombiner::visitAllocaInst for scalable vector.
Summary: DataLayout::getTypeAllocSize() return TypeSize. For cases where scalable property doesn't matter (check for zero-sized alloca), we should explicitly call getKnownMinSize() to avoid implicit type conversion to uint64_t, which is invalid for scalable vector type. Reviewers: sdesmalen, efriedma, spatel, apazos Reviewed By: efriedma Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76386
1 parent 79a7ed9 commit 2ea5495

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
348348
// Move all alloca's of zero byte objects to the entry block and merge them
349349
// together. Note that we only do this for alloca's, because malloc should
350350
// allocate and return a unique pointer, even for a zero byte allocation.
351-
if (DL.getTypeAllocSize(AI.getAllocatedType()) == 0) {
351+
if (DL.getTypeAllocSize(AI.getAllocatedType()).getKnownMinSize() == 0) {
352352
// For a zero sized alloca there is no point in doing an array allocation.
353353
// This is helpful if the array size is a complicated expression not used
354354
// elsewhere.
@@ -365,7 +365,8 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
365365
// dominance as the array size was forced to a constant earlier already.
366366
AllocaInst *EntryAI = dyn_cast<AllocaInst>(FirstInst);
367367
if (!EntryAI || !EntryAI->getAllocatedType()->isSized() ||
368-
DL.getTypeAllocSize(EntryAI->getAllocatedType()) != 0) {
368+
DL.getTypeAllocSize(EntryAI->getAllocatedType())
369+
.getKnownMinSize() != 0) {
369370
AI.moveBefore(FirstInst);
370371
return &AI;
371372
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -instcombine -verify < %s | FileCheck %s
3+
4+
define <vscale x 4 x i32> @alloca(<vscale x 4 x i32> %z) {
5+
; CHECK-LABEL: @alloca(
6+
; CHECK-NEXT: ret <vscale x 4 x i32> [[Z:%.*]]
7+
;
8+
%a = alloca <vscale x 4 x i32>
9+
store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
10+
%load = load <vscale x 4 x i32>, <vscale x 4 x i32>* %a
11+
ret <vscale x 4 x i32> %load
12+
}
13+
14+
define void @alloca_dead_store(<vscale x 4 x i32> %z) {
15+
; CHECK-LABEL: @alloca_dead_store(
16+
; CHECK-NEXT: ret void
17+
;
18+
%a = alloca <vscale x 4 x i32>
19+
store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
20+
ret void
21+
}
22+
23+
declare void @use(...)
24+
define void @alloca_zero_byte_move_first_inst() {
25+
; CHECK-LABEL: @alloca_zero_byte_move_first_inst(
26+
; CHECK-NEXT: [[B:%.*]] = alloca {}, align 8
27+
; CHECK-NEXT: [[A:%.*]] = alloca <vscale x 16 x i8>, align 16
28+
; CHECK-NEXT: call void (...) @use(<vscale x 16 x i8>* nonnull [[A]])
29+
; CHECK-NEXT: call void (...) @use({}* nonnull [[B]])
30+
; CHECK-NEXT: ret void
31+
;
32+
%a = alloca <vscale x 16 x i8>
33+
call void (...) @use( <vscale x 16 x i8>* %a )
34+
%b = alloca { }
35+
call void (...) @use( { }* %b )
36+
ret void
37+
}

0 commit comments

Comments
 (0)