Skip to content

Commit

Permalink
AllocaInst should store Align instead of MaybeAlign.
Browse files Browse the repository at this point in the history
Along the lines of D77454 and D79968.  Unlike loads and stores, the
default alignment is getPrefTypeAlign, to match the existing handling in
various places, including SelectionDAG and InstCombine.

Differential Revision: https://reviews.llvm.org/D80044
  • Loading branch information
efriedma-quic committed May 16, 2020
1 parent 135b877 commit 4f04db4
Show file tree
Hide file tree
Showing 53 changed files with 353 additions and 397 deletions.
26 changes: 10 additions & 16 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,19 @@ class AllocaInst : public UnaryInstruction {
AllocaInst *cloneImpl() const;

public:
explicit AllocaInst(Type *Ty, unsigned AddrSpace,
Value *ArraySize = nullptr,
const Twine &Name = "",
Instruction *InsertBefore = nullptr);
explicit AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
const Twine &Name, Instruction *InsertBefore);
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
const Twine &Name, BasicBlock *InsertAtEnd);

AllocaInst(Type *Ty, unsigned AddrSpace,
const Twine &Name, Instruction *InsertBefore = nullptr);
AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
Instruction *InsertBefore);
AllocaInst(Type *Ty, unsigned AddrSpace,
const Twine &Name, BasicBlock *InsertAtEnd);

AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, MaybeAlign Align,
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
const Twine &Name = "", Instruction *InsertBefore = nullptr);
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, MaybeAlign Align,
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
const Twine &Name, BasicBlock *InsertAtEnd);

/// Return true if there is an allocation size parameter to the allocation
Expand Down Expand Up @@ -109,16 +107,12 @@ class AllocaInst : public UnaryInstruction {

/// Return the alignment of the memory that is being allocated by the
/// instruction.
MaybeAlign getAlign() const {
return decodeMaybeAlign(getSubclassDataFromInstruction() & 31);
Align getAlign() const {
return *decodeMaybeAlign(getSubclassDataFromInstruction() & 31);
}
// FIXME: Remove this one transition to Align is over.
unsigned getAlignment() const {
if (const auto MA = getAlign())
return MA->value();
return 0;
}
void setAlignment(MaybeAlign Align);
unsigned getAlignment() const { return getAlign().value(); }
void setAlignment(Align Align);

/// Return true if this alloca is in the entry block of the function and is a
/// constant size. If so, the code generator will fold it into the
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
bool processMemCpy(MemCpyInst *M);
bool processMemMove(MemMoveInst *M);
bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
uint64_t cpyLen, Align cpyAlign, CallInst *C);
bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7007,7 +7007,12 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
if (Size && !Size->getType()->isIntegerTy())
return Error(SizeLoc, "element count must have integer type");

AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, Alignment);
SmallPtrSet<Type *, 4> Visited;
if (!Alignment && !Ty->isSized(&Visited))
return Error(TyLoc, "Cannot allocate unsized type");
if (!Alignment)
Alignment = M->getDataLayout().getPrefTypeAlign(Ty);
AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, *Alignment);
AI->setUsedWithInAlloca(IsInAlloca);
AI->setSwiftError(IsSwiftError);
Inst = AI;
Expand Down
8 changes: 7 additions & 1 deletion llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4826,7 +4826,13 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
const DataLayout &DL = TheModule->getDataLayout();
unsigned AS = DL.getAllocaAddrSpace();

AllocaInst *AI = new AllocaInst(Ty, AS, Size, Align);
SmallPtrSet<Type *, 4> Visited;
if (!Align && !Ty->isSized(&Visited))
return error("alloca of unsized type");
if (!Align)
Align = DL.getPrefTypeAlign(Ty);

AllocaInst *AI = new AllocaInst(Ty, AS, Size, *Align);
AI->setUsedWithInAlloca(InAlloca);
AI->setSwiftError(SwiftError);
I = AI;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
AllocaInst *AI;
if ((AI = dyn_cast<AllocaInst>(Val)) && AI->getAlignment() < PrefAlign &&
DL->getTypeAllocSize(AI->getAllocatedType()) >= MinSize + Offset2)
AI->setAlignment(MaybeAlign(PrefAlign));
AI->setAlignment(Align(PrefAlign));
// Global variables can only be aligned if they are defined in this
// object (i.e. they are uniquely initialized in this object), and
// over-aligning global variables that have an explicit section is
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ bool IRTranslator::translateAlloca(const User &U,
MIRBuilder.buildConstant(IntPtrTy, ~(uint64_t)(StackAlign.value() - 1));
auto AlignedAlloc = MIRBuilder.buildAnd(IntPtrTy, AllocAdd, AlignCst);

Align Alignment = max(AI.getAlign(), DL->getPrefTypeAlign(Ty));
Align Alignment = std::max(AI.getAlign(), DL->getPrefTypeAlign(Ty));
if (Alignment <= StackAlign)
Alignment = Align(1);
MIRBuilder.buildDynStackAlloc(getOrCreateVReg(AI), AlignedAlloc, Alignment);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
// or the preferred alignment of the type if none is specified.
//
// (Unspecified alignment on allocas will be going away soon.)
Align SpecifiedAlign = AI->getAlign() ? *AI->getAlign() : TyPrefAlign;
Align SpecifiedAlign = AI->getAlign();

// If the preferred alignment of the type is higher than the specified
// alignment of the alloca, promote the alignment, as long as it doesn't
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
auto &DL = DAG.getDataLayout();
uint64_t TySize = DL.getTypeAllocSize(Ty);
MaybeAlign Alignment = max(DL.getPrefTypeAlign(Ty), I.getAlign());
MaybeAlign Alignment = std::max(DL.getPrefTypeAlign(Ty), I.getAlign());

SDValue AllocSize = getValue(I.getArraySize());

Expand Down Expand Up @@ -9507,8 +9507,7 @@ static void tryToElideArgumentCopy(
"object size\n");
return;
}
Align RequiredAlignment = AI->getAlign().getValueOr(
FuncInfo.MF->getDataLayout().getABITypeAlign(AI->getAllocatedType()));
Align RequiredAlignment = AI->getAlign();
if (MFI.getObjectAlign(FixedIndex) < RequiredAlignment) {
LLVM_DEBUG(dbgs() << " argument copy elision failed: alignment of alloca "
"greater than stack argument alignment ("
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
GV->setAlignment(MaybeAlign(Bytes));
else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
AI->setAlignment(MaybeAlign(Bytes));
AI->setAlignment(Align(Bytes));
else if (LoadInst *LI = dyn_cast<LoadInst>(P))
LI->setAlignment(Align(Bytes));
else if (StoreInst *SI = dyn_cast<StoreInst>(P))
Expand Down
37 changes: 22 additions & 15 deletions llvm/lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,15 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
return Amt;
}

Align computeAllocaDefaultAlign(Type *Ty, BasicBlock *BB) {
const DataLayout &DL = BB->getModule()->getDataLayout();
return DL.getPrefTypeAlign(Ty);
}

Align computeAllocaDefaultAlign(Type *Ty, Instruction *I) {
return computeAllocaDefaultAlign(Ty, I->getParent());
}

AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
Instruction *InsertBefore)
: AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
Expand All @@ -1256,27 +1265,29 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,

AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
const Twine &Name, Instruction *InsertBefore)
: AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertBefore) {
}
: AllocaInst(Ty, AddrSpace, ArraySize,
computeAllocaDefaultAlign(Ty, InsertBefore), Name,
InsertBefore) {}

AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
const Twine &Name, BasicBlock *InsertAtEnd)
: AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertAtEnd) {}
: AllocaInst(Ty, AddrSpace, ArraySize,
computeAllocaDefaultAlign(Ty, InsertAtEnd), Name,
InsertAtEnd) {}

AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
MaybeAlign Align, const Twine &Name,
Align Align, const Twine &Name,
Instruction *InsertBefore)
: UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore),
AllocatedType(Ty) {
setAlignment(MaybeAlign(Align));
setAlignment(Align);
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}

AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
MaybeAlign Align, const Twine &Name,
BasicBlock *InsertAtEnd)
Align Align, const Twine &Name, BasicBlock *InsertAtEnd)
: UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd),
AllocatedType(Ty) {
Expand All @@ -1285,16 +1296,12 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
setName(Name);
}

void AllocaInst::setAlignment(MaybeAlign Align) {
assert((!Align || *Align <= MaximumAlignment) &&
void AllocaInst::setAlignment(Align Align) {
assert(Align <= MaximumAlignment &&
"Alignment is greater than MaximumAlignment!");
setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) |
encode(Align));
if (Align)
assert(getAlignment() == Align->value() &&
"Alignment representation error!");
else
assert(getAlignment() == 0 && "Alignment representation error!");
assert(getAlignment() == Align.value() && "Alignment representation error!");
}

bool AllocaInst::isArrayAllocation() const {
Expand Down Expand Up @@ -4240,7 +4247,7 @@ InsertValueInst *InsertValueInst::cloneImpl() const {
AllocaInst *AllocaInst::cloneImpl() const {
AllocaInst *Result =
new AllocaInst(getAllocatedType(), getType()->getAddressSpace(),
(Value *)getOperand(0), MaybeAlign(getAlignment()));
getOperand(0), getAlign());
Result->setUsedWithInAlloca(isUsedWithInAlloca());
Result->setSwiftError(isSwiftError());
return Result;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64StackTagging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void AArch64StackTagging::alignAndPadAlloca(AllocaInfo &Info) {
auto *NewAI = new AllocaInst(
TypeWithPadding, Info.AI->getType()->getAddressSpace(), nullptr, "", Info.AI);
NewAI->takeName(Info.AI);
NewAI->setAlignment(MaybeAlign(Info.AI->getAlignment()));
NewAI->setAlignment(Info.AI->getAlign());
NewAI->setUsedWithInAlloca(Info.AI->isUsedWithInAlloca());
NewAI->setSwiftError(Info.AI->isSwiftError());
NewAI->copyMetadata(*Info.AI);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,8 @@ AllocaInst* AMDGPULibCalls::insertAlloca(CallInst *UI, IRBuilder<> &B,
B.SetInsertPoint(&*ItNew);
AllocaInst *Alloc = B.CreateAlloca(RetType, 0,
std::string(prefix) + UI->getName());
Alloc->setAlignment(MaybeAlign(
UCallee->getParent()->getDataLayout().getTypeAllocSize(RetType)));
Alloc->setAlignment(
Align(UCallee->getParent()->getDataLayout().getTypeAllocSize(RetType)));
return Alloc;
}

Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ void NVPTXLowerArgs::handleByValParam(Argument *Arg) {
assert(PType && "Expecting pointer type in handleByValParam");

Type *StructType = PType->getElementType();
unsigned AS = Func->getParent()->getDataLayout().getAllocaAddrSpace();
const DataLayout &DL = Func->getParent()->getDataLayout();
unsigned AS = DL.getAllocaAddrSpace();
AllocaInst *AllocA = new AllocaInst(StructType, AS, Arg->getName(), FirstInst);
// Set the alignment to alignment of the byval parameter. This is because,
// later load/stores assume that alignment, and we are going to replace
// the use of the byval parameter with this alloca instruction.
AllocA->setAlignment(MaybeAlign(Func->getParamAlignment(Arg->getArgNo())));
AllocA->setAlignment(Func->getParamAlign(Arg->getArgNo())
.getValueOr(DL.getPrefTypeAlign(StructType)));
Arg->replaceAllUsesWith(AllocA);

Value *ArgInParam = new AddrSpaceCastInst(
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Coroutines/CoroElide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct Lowerer : coro::LowererBase {

Lowerer(Module &M) : LowererBase(M) {}

void elideHeapAllocations(Function *F, uint64_t FrameSize,
MaybeAlign FrameAlign, AAResults &AA);
void elideHeapAllocations(Function *F, uint64_t FrameSize, Align FrameAlign,
AAResults &AA);
bool shouldElide(Function *F, DominatorTree &DT) const;
void collectPostSplitCoroIds(Function *F);
bool processCoroId(CoroIdInst *, AAResults &AA, DominatorTree &DT);
Expand Down Expand Up @@ -95,7 +95,7 @@ static void removeTailCallAttribute(AllocaInst *Frame, AAResults &AA) {

// Given a resume function @f.resume(%f.frame* %frame), returns the size
// and expected alignment of %f.frame type.
static std::pair<uint64_t, MaybeAlign> getFrameLayout(Function *Resume) {
static std::pair<uint64_t, Align> getFrameLayout(Function *Resume) {
// Prefer to pull information from the function attributes.
auto Size = Resume->getParamDereferenceableBytes(0);
auto Align = Resume->getParamAlign(0);
Expand All @@ -109,7 +109,7 @@ static std::pair<uint64_t, MaybeAlign> getFrameLayout(Function *Resume) {
if (!Align) Align = DL.getABITypeAlign(FrameTy);
}

return std::make_pair(Size, Align);
return std::make_pair(Size, *Align);
}

// Finds first non alloca instruction in the entry block of a function.
Expand All @@ -123,7 +123,7 @@ static Instruction *getFirstNonAllocaInTheEntryBlock(Function *F) {
// To elide heap allocations we need to suppress code blocks guarded by
// llvm.coro.alloc and llvm.coro.free instructions.
void Lowerer::elideHeapAllocations(Function *F, uint64_t FrameSize,
MaybeAlign FrameAlign, AAResults &AA) {
Align FrameAlign, AAResults &AA) {
LLVMContext &C = F->getContext();
auto *InsertPt =
getFirstNonAllocaInTheEntryBlock(CoroIds.front()->getFunction());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst*> LocalAllocas,

// Allocate memory.
auto Alloca = Builder.CreateAlloca(Builder.getInt8Ty(), AI->getSize());
Alloca->setAlignment(MaybeAlign(AI->getAlignment()));
Alloca->setAlignment(Align(AI->getAlignment()));

for (auto U : AI->users()) {
// Replace gets with the allocation.
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,

// Just add all the struct element types.
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
Value *TheAlloca =
new AllocaInst(AgTy, DL.getAllocaAddrSpace(), nullptr,
MaybeAlign(I->getParamAlignment()), "", InsertPt);
Value *TheAlloca = new AllocaInst(
AgTy, DL.getAllocaAddrSpace(), nullptr,
I->getParamAlign().getValueOr(DL.getPrefTypeAlign(AgTy)), "",
InsertPt);
StructType *STy = cast<StructType>(AgTy);
Value *Idxs[2] = {ConstantInt::get(Type::getInt32Ty(F->getContext()), 0),
nullptr};
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4724,7 +4724,7 @@ struct AAHeapToStackImpl : public AAHeapToStack {
LLVM_DEBUG(dbgs() << "H2S: Removing malloc call: " << *MallocCall
<< "\n");

MaybeAlign Alignment;
Align Alignment;
Constant *Size;
if (isCallocLikeFn(MallocCall, TLI)) {
auto *Num = cast<ConstantInt>(MallocCall->getOperand(0));
Expand All @@ -4736,7 +4736,8 @@ struct AAHeapToStackImpl : public AAHeapToStack {
Size = cast<ConstantInt>(MallocCall->getOperand(1));
Alignment = MaybeAlign(cast<ConstantInt>(MallocCall->getOperand(0))
->getValue()
.getZExtValue());
.getZExtValue())
.valueOrOne();
} else {
Size = cast<ConstantInt>(MallocCall->getOperand(0));
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static void mergeInlinedArrayAllocas(Function *Caller, InlineFunctionInfo &IFI,
}

if (Align1 > Align2)
AvailableAlloca->setAlignment(MaybeAlign(AI->getAlignment()));
AvailableAlloca->setAlignment(AI->getAlign());
}

AI->eraseFromParent();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
}

AllocaInst *New = Builder.CreateAlloca(CastElTy, Amt);
New->setAlignment(MaybeAlign(AI.getAlignment()));
New->setAlignment(AI.getAlign());
New->takeName(&AI);
New->setUsedWithInAlloca(AI.isUsedWithInAlloca());

Expand Down
15 changes: 2 additions & 13 deletions llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
if (C->getValue().getActiveBits() <= 64) {
Type *NewTy = ArrayType::get(AI.getAllocatedType(), C->getZExtValue());
AllocaInst *New = IC.Builder.CreateAlloca(NewTy, nullptr, AI.getName());
New->setAlignment(MaybeAlign(AI.getAlignment()));
New->setAlignment(AI.getAlign());

// Scan to the end of the allocation instructions, to skip over a block of
// allocas if possible...also skip interleaved debug info
Expand Down Expand Up @@ -327,11 +327,6 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
return I;

if (AI.getAllocatedType()->isSized()) {
// If the alignment is 0 (unspecified), assign it the preferred alignment.
if (AI.getAlignment() == 0)
AI.setAlignment(
MaybeAlign(DL.getPrefTypeAlignment(AI.getAllocatedType())));

// Move all alloca's of zero byte objects to the entry block and merge them
// together. Note that we only do this for alloca's, because malloc should
// allocate and return a unique pointer, even for a zero byte allocation.
Expand All @@ -358,16 +353,10 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
return &AI;
}

// If the alignment of the entry block alloca is 0 (unspecified),
// assign it the preferred alignment.
if (EntryAI->getAlignment() == 0)
EntryAI->setAlignment(
MaybeAlign(DL.getPrefTypeAlignment(EntryAI->getAllocatedType())));
// Replace this zero-sized alloca with the one at the start of the entry
// block after ensuring that the address will be aligned enough for both
// types.
const MaybeAlign MaxAlign(
std::max(EntryAI->getAlignment(), AI.getAlignment()));
const Align MaxAlign = std::max(EntryAI->getAlign(), AI.getAlign());
EntryAI->setAlignment(MaxAlign);
if (AI.getType() != EntryAI->getType())
return new BitCastInst(EntryAI, AI.getType());
Expand Down
Loading

0 comments on commit 4f04db4

Please sign in to comment.