From 33222110480c02e82bbad4930c14c4ccdc5784a0 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 5 Nov 2021 06:57:41 -0700 Subject: [PATCH] Avoid emitting bitCast in head block --- IDEHelper/Compiler/BfModule.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 4b3ad345..f9a1d9cd 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -8984,10 +8984,19 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget mBfIRBuilder->ClearDebugLocation(allocaInst); auto allocaBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); - auto typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType); - mBfIRBuilder->ClearDebugLocation_Last(); + + BfTypedValue typedVal; if (!isDynAlloc) - mBfIRBuilder->SetInsertPoint(prevBlock); + { + mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRInitBlock); + typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType); + mBfIRBuilder->ClearDebugLocation_Last(); + mBfIRBuilder->SetInsertPoint(prevBlock); + allocaBlock = mCurMethodState->mIRInitBlock; + } + else + typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType); + if (!noDtorCall) AddStackAlloc(typedVal, BfIRValue(), NULL, scopeData, false, true, allocaBlock); InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue); @@ -20277,7 +20286,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) } if (mCurMethodState->mIRExitBlock) - { + { for (auto preExitBlock : mCurMethodState->mHeadScope.mAtEndBlocks) mBfIRBuilder->MoveBlockToEnd(preExitBlock);