mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
instcombine: alloca: Remove nesting in simplifyAllocaArraySize(), NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cd67bbf07f
commit
7c93bfa994
@ -174,11 +174,13 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
|
|||||||
return &AI;
|
return &AI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check C != 1
|
||||||
|
if (!AI.isArrayAllocation())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
// Convert: alloca Ty, C - where C is a constant != 1 into: alloca [C x Ty], 1
|
// Convert: alloca Ty, C - where C is a constant != 1 into: alloca [C x Ty], 1
|
||||||
if (AI.isArrayAllocation()) { // Check C != 1
|
|
||||||
if (const ConstantInt *C = dyn_cast<ConstantInt>(AI.getArraySize())) {
|
if (const ConstantInt *C = dyn_cast<ConstantInt>(AI.getArraySize())) {
|
||||||
Type *NewTy =
|
Type *NewTy = ArrayType::get(AI.getAllocatedType(), C->getZExtValue());
|
||||||
ArrayType::get(AI.getAllocatedType(), C->getZExtValue());
|
|
||||||
AllocaInst *New = IC.Builder->CreateAlloca(NewTy, nullptr, AI.getName());
|
AllocaInst *New = IC.Builder->CreateAlloca(NewTy, nullptr, AI.getName());
|
||||||
New->setAlignment(AI.getAlignment());
|
New->setAlignment(AI.getAlignment());
|
||||||
|
|
||||||
@ -186,7 +188,8 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
|
|||||||
// allocas if possible...also skip interleaved debug info
|
// allocas if possible...also skip interleaved debug info
|
||||||
//
|
//
|
||||||
BasicBlock::iterator It = New;
|
BasicBlock::iterator It = New;
|
||||||
while (isa<AllocaInst>(*It) || isa<DbgInfoIntrinsic>(*It)) ++It;
|
while (isa<AllocaInst>(*It) || isa<DbgInfoIntrinsic>(*It))
|
||||||
|
++It;
|
||||||
|
|
||||||
// Now that I is pointing to the first non-allocation-inst in the block,
|
// Now that I is pointing to the first non-allocation-inst in the block,
|
||||||
// insert our getelementptr instruction...
|
// insert our getelementptr instruction...
|
||||||
@ -201,10 +204,10 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
|
|||||||
// Now make everything use the getelementptr instead of the original
|
// Now make everything use the getelementptr instead of the original
|
||||||
// allocation.
|
// allocation.
|
||||||
return IC.ReplaceInstUsesWith(AI, GEP);
|
return IC.ReplaceInstUsesWith(AI, GEP);
|
||||||
} else if (isa<UndefValue>(AI.getArraySize())) {
|
}
|
||||||
|
|
||||||
|
if (isa<UndefValue>(AI.getArraySize()))
|
||||||
return IC.ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
|
return IC.ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user