[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
This commit is contained in:
Huihui Zhang 2020-03-18 20:46:15 -07:00
parent 79a7ed92a9
commit 2ea5495759
2 changed files with 40 additions and 2 deletions

View File

@ -348,7 +348,7 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
// Move all alloca's of zero byte objects to the entry block and merge them
// together. Note that we only do this for alloca's, because malloc should
// allocate and return a unique pointer, even for a zero byte allocation.
if (DL.getTypeAllocSize(AI.getAllocatedType()) == 0) {
if (DL.getTypeAllocSize(AI.getAllocatedType()).getKnownMinSize() == 0) {
// For a zero sized alloca there is no point in doing an array allocation.
// This is helpful if the array size is a complicated expression not used
// elsewhere.
@ -365,7 +365,8 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
// dominance as the array size was forced to a constant earlier already.
AllocaInst *EntryAI = dyn_cast<AllocaInst>(FirstInst);
if (!EntryAI || !EntryAI->getAllocatedType()->isSized() ||
DL.getTypeAllocSize(EntryAI->getAllocatedType()) != 0) {
DL.getTypeAllocSize(EntryAI->getAllocatedType())
.getKnownMinSize() != 0) {
AI.moveBefore(FirstInst);
return &AI;
}

View File

@ -0,0 +1,37 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instcombine -verify < %s | FileCheck %s
define <vscale x 4 x i32> @alloca(<vscale x 4 x i32> %z) {
; CHECK-LABEL: @alloca(
; CHECK-NEXT: ret <vscale x 4 x i32> [[Z:%.*]]
;
%a = alloca <vscale x 4 x i32>
store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
%load = load <vscale x 4 x i32>, <vscale x 4 x i32>* %a
ret <vscale x 4 x i32> %load
}
define void @alloca_dead_store(<vscale x 4 x i32> %z) {
; CHECK-LABEL: @alloca_dead_store(
; CHECK-NEXT: ret void
;
%a = alloca <vscale x 4 x i32>
store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
ret void
}
declare void @use(...)
define void @alloca_zero_byte_move_first_inst() {
; CHECK-LABEL: @alloca_zero_byte_move_first_inst(
; CHECK-NEXT: [[B:%.*]] = alloca {}, align 8
; CHECK-NEXT: [[A:%.*]] = alloca <vscale x 16 x i8>, align 16
; CHECK-NEXT: call void (...) @use(<vscale x 16 x i8>* nonnull [[A]])
; CHECK-NEXT: call void (...) @use({}* nonnull [[B]])
; CHECK-NEXT: ret void
;
%a = alloca <vscale x 16 x i8>
call void (...) @use( <vscale x 16 x i8>* %a )
%b = alloca { }
call void (...) @use( { }* %b )
ret void
}