diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index f8fae773e476d..bb2a77daa60a7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -213,6 +213,7 @@ static Instruction *simplifyAllocaArraySize(InstCombinerImpl &IC, AllocaInst *New = IC.Builder.CreateAlloca(NewTy, AI.getAddressSpace(), nullptr, AI.getName()); New->setAlignment(AI.getAlign()); + New->setUsedWithInAlloca(AI.isUsedWithInAlloca()); replaceAllDbgUsesWith(AI, *New, *New, DT); return IC.replaceInstUsesWith(AI, New); diff --git a/llvm/test/Transforms/InstCombine/alloca.ll b/llvm/test/Transforms/InstCombine/alloca.ll index a64de28ee8397..4247d6a301931 100644 --- a/llvm/test/Transforms/InstCombine/alloca.ll +++ b/llvm/test/Transforms/InstCombine/alloca.ll @@ -248,3 +248,14 @@ entry: call void (...) @use(ptr nonnull @int) [ "blah"(ptr %y) ] ret void } + +define void @test_inalloca_with_element_count(ptr %a) { +; ALL-LABEL: @test_inalloca_with_element_count( +; ALL-NEXT: [[ALLOCA1:%.*]] = alloca inalloca [10 x %struct_type], align 4 +; ALL-NEXT: call void @test9_aux(ptr nonnull inalloca([[STRUCT_TYPE:%.*]]) [[ALLOCA1]]) +; ALL-NEXT: ret void +; + %alloca = alloca inalloca %struct_type, i32 10, align 4 + call void @test9_aux(ptr inalloca(%struct_type) %alloca) + ret void +}