[llvm] 2ea5495 - [InstCombine][SVE] Fix InstCombiner::visitAllocaInst for scalable vector.
Huihui Zhang via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 18 20:57:28 PDT 2020
Author: Huihui Zhang
Date: 2020-03-18T20:57:14-07:00
New Revision: 2ea5495759f61d7bcf9c7e0c35451aaf1b5db6d2
URL: https://github.com/llvm/llvm-project/commit/2ea5495759f61d7bcf9c7e0c35451aaf1b5db6d2
DIFF: https://github.com/llvm/llvm-project/commit/2ea5495759f61d7bcf9c7e0c35451aaf1b5db6d2.diff
LOG: [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
Added:
llvm/test/Transforms/InstCombine/vscale_alloca.ll
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 4db482646ab2..b95f3f6a0ecd 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -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;
}
diff --git a/llvm/test/Transforms/InstCombine/vscale_alloca.ll b/llvm/test/Transforms/InstCombine/vscale_alloca.ll
new file mode 100644
index 000000000000..8cfc7b74a77f
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/vscale_alloca.ll
@@ -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
+}
More information about the llvm-commits
mailing list