diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -348,7 +348,7 @@ // 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 @@ // dominance as the array size was forced to a constant earlier already. AllocaInst *EntryAI = dyn_cast(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 --- /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 @alloca( %z) { +; CHECK-LABEL: @alloca( +; CHECK-NEXT: ret [[Z:%.*]] +; + %a = alloca + store %z, * %a + %load = load , * %a + ret %load +} + +define void @alloca_dead_store( %z) { +; CHECK-LABEL: @alloca_dead_store( +; CHECK-NEXT: ret void +; + %a = alloca + store %z, * %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 , align 16 +; CHECK-NEXT: call void (...) @use(* nonnull [[A]]) +; CHECK-NEXT: call void (...) @use({}* nonnull [[B]]) +; CHECK-NEXT: ret void +; + %a = alloca + call void (...) @use( * %a ) + %b = alloca { } + call void (...) @use( { }* %b ) + ret void +}