Skip to content

Commit 97efd8a

Browse files
committed
[InstCombine] Preserve inalloca tag when transforming alloca
This is not meaningful in any practical sense, and just makes sure we don't cause verifier failures.
1 parent 0474a92 commit 97efd8a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static Instruction *simplifyAllocaArraySize(InstCombinerImpl &IC,
213213
AllocaInst *New = IC.Builder.CreateAlloca(NewTy, AI.getAddressSpace(),
214214
nullptr, AI.getName());
215215
New->setAlignment(AI.getAlign());
216+
New->setUsedWithInAlloca(AI.isUsedWithInAlloca());
216217

217218
replaceAllDbgUsesWith(AI, *New, *New, DT);
218219
return IC.replaceInstUsesWith(AI, New);

llvm/test/Transforms/InstCombine/alloca.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,14 @@ entry:
248248
call void (...) @use(ptr nonnull @int) [ "blah"(ptr %y) ]
249249
ret void
250250
}
251+
252+
define void @test_inalloca_with_element_count(ptr %a) {
253+
; ALL-LABEL: @test_inalloca_with_element_count(
254+
; ALL-NEXT: [[ALLOCA1:%.*]] = alloca inalloca [10 x %struct_type], align 4
255+
; ALL-NEXT: call void @test9_aux(ptr nonnull inalloca([[STRUCT_TYPE:%.*]]) [[ALLOCA1]])
256+
; ALL-NEXT: ret void
257+
;
258+
%alloca = alloca inalloca %struct_type, i32 10, align 4
259+
call void @test9_aux(ptr inalloca(%struct_type) %alloca)
260+
ret void
261+
}

0 commit comments

Comments
 (0)