Skip to content

Commit

Permalink
[InstCombine] Preserve inalloca tag when transforming alloca
Browse files Browse the repository at this point in the history
This is not meaningful in any practical sense, and just makes sure
we don't cause verifier failures.
  • Loading branch information
nikic committed Dec 11, 2023
1 parent 0474a92 commit 97efd8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/alloca.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 97efd8a

Please sign in to comment.