Skip to content

Commit 4f04db4

Browse files
committed
AllocaInst should store Align instead of MaybeAlign.
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
1 parent 135b877 commit 4f04db4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+353
-397
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,19 @@ class AllocaInst : public UnaryInstruction {
6666
AllocaInst *cloneImpl() const;
6767

6868
public:
69-
explicit AllocaInst(Type *Ty, unsigned AddrSpace,
70-
Value *ArraySize = nullptr,
71-
const Twine &Name = "",
72-
Instruction *InsertBefore = nullptr);
69+
explicit AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
70+
const Twine &Name, Instruction *InsertBefore);
7371
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
7472
const Twine &Name, BasicBlock *InsertAtEnd);
7573

76-
AllocaInst(Type *Ty, unsigned AddrSpace,
77-
const Twine &Name, Instruction *InsertBefore = nullptr);
74+
AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
75+
Instruction *InsertBefore);
7876
AllocaInst(Type *Ty, unsigned AddrSpace,
7977
const Twine &Name, BasicBlock *InsertAtEnd);
8078

81-
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, MaybeAlign Align,
79+
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
8280
const Twine &Name = "", Instruction *InsertBefore = nullptr);
83-
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, MaybeAlign Align,
81+
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
8482
const Twine &Name, BasicBlock *InsertAtEnd);
8583

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

110108
/// Return the alignment of the memory that is being allocated by the
111109
/// instruction.
112-
MaybeAlign getAlign() const {
113-
return decodeMaybeAlign(getSubclassDataFromInstruction() & 31);
110+
Align getAlign() const {
111+
return *decodeMaybeAlign(getSubclassDataFromInstruction() & 31);
114112
}
115113
// FIXME: Remove this one transition to Align is over.
116-
unsigned getAlignment() const {
117-
if (const auto MA = getAlign())
118-
return MA->value();
119-
return 0;
120-
}
121-
void setAlignment(MaybeAlign Align);
114+
unsigned getAlignment() const { return getAlign().value(); }
115+
void setAlignment(Align Align);
122116

123117
/// Return true if this alloca is in the entry block of the function and is a
124118
/// constant size. If so, the code generator will fold it into the

llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MemCpyOptPass : public PassInfoMixin<MemCpyOptPass> {
6161
bool processMemCpy(MemCpyInst *M);
6262
bool processMemMove(MemMoveInst *M);
6363
bool performCallSlotOptzn(Instruction *cpy, Value *cpyDst, Value *cpySrc,
64-
uint64_t cpyLen, unsigned cpyAlign, CallInst *C);
64+
uint64_t cpyLen, Align cpyAlign, CallInst *C);
6565
bool processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep);
6666
bool processMemSetMemCpyDependence(MemCpyInst *M, MemSetInst *MDep);
6767
bool performMemCpyToMemSetOptzn(MemCpyInst *M, MemSetInst *MDep);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7007,7 +7007,12 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
70077007
if (Size && !Size->getType()->isIntegerTy())
70087008
return Error(SizeLoc, "element count must have integer type");
70097009

7010-
AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, Alignment);
7010+
SmallPtrSet<Type *, 4> Visited;
7011+
if (!Alignment && !Ty->isSized(&Visited))
7012+
return Error(TyLoc, "Cannot allocate unsized type");
7013+
if (!Alignment)
7014+
Alignment = M->getDataLayout().getPrefTypeAlign(Ty);
7015+
AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, *Alignment);
70117016
AI->setUsedWithInAlloca(IsInAlloca);
70127017
AI->setSwiftError(IsSwiftError);
70137018
Inst = AI;

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4826,7 +4826,13 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48264826
const DataLayout &DL = TheModule->getDataLayout();
48274827
unsigned AS = DL.getAllocaAddrSpace();
48284828

4829-
AllocaInst *AI = new AllocaInst(Ty, AS, Size, Align);
4829+
SmallPtrSet<Type *, 4> Visited;
4830+
if (!Align && !Ty->isSized(&Visited))
4831+
return error("alloca of unsized type");
4832+
if (!Align)
4833+
Align = DL.getPrefTypeAlign(Ty);
4834+
4835+
AllocaInst *AI = new AllocaInst(Ty, AS, Size, *Align);
48304836
AI->setUsedWithInAlloca(InAlloca);
48314837
AI->setSwiftError(SwiftError);
48324838
I = AI;

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
19591959
AllocaInst *AI;
19601960
if ((AI = dyn_cast<AllocaInst>(Val)) && AI->getAlignment() < PrefAlign &&
19611961
DL->getTypeAllocSize(AI->getAllocatedType()) >= MinSize + Offset2)
1962-
AI->setAlignment(MaybeAlign(PrefAlign));
1962+
AI->setAlignment(Align(PrefAlign));
19631963
// Global variables can only be aligned if they are defined in this
19641964
// object (i.e. they are uniquely initialized in this object), and
19651965
// over-aligning global variables that have an explicit section is

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ bool IRTranslator::translateAlloca(const User &U,
18751875
MIRBuilder.buildConstant(IntPtrTy, ~(uint64_t)(StackAlign.value() - 1));
18761876
auto AlignedAlloc = MIRBuilder.buildAnd(IntPtrTy, AllocAdd, AlignCst);
18771877

1878-
Align Alignment = max(AI.getAlign(), DL->getPrefTypeAlign(Ty));
1878+
Align Alignment = std::max(AI.getAlign(), DL->getPrefTypeAlign(Ty));
18791879
if (Alignment <= StackAlign)
18801880
Alignment = Align(1);
18811881
MIRBuilder.buildDynStackAlloc(getOrCreateVReg(AI), AlignedAlloc, Alignment);

llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
139139
// or the preferred alignment of the type if none is specified.
140140
//
141141
// (Unspecified alignment on allocas will be going away soon.)
142-
Align SpecifiedAlign = AI->getAlign() ? *AI->getAlign() : TyPrefAlign;
142+
Align SpecifiedAlign = AI->getAlign();
143143

144144
// If the preferred alignment of the type is higher than the specified
145145
// alignment of the alloca, promote the alignment, as long as it doesn't

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,7 +3890,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
38903890
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
38913891
auto &DL = DAG.getDataLayout();
38923892
uint64_t TySize = DL.getTypeAllocSize(Ty);
3893-
MaybeAlign Alignment = max(DL.getPrefTypeAlign(Ty), I.getAlign());
3893+
MaybeAlign Alignment = std::max(DL.getPrefTypeAlign(Ty), I.getAlign());
38943894

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

@@ -9507,8 +9507,7 @@ static void tryToElideArgumentCopy(
95079507
"object size\n");
95089508
return;
95099509
}
9510-
Align RequiredAlignment = AI->getAlign().getValueOr(
9511-
FuncInfo.MF->getDataLayout().getABITypeAlign(AI->getAllocatedType()));
9510+
Align RequiredAlignment = AI->getAlign();
95129511
if (MFI.getObjectAlign(FixedIndex) < RequiredAlignment) {
95139512
LLVM_DEBUG(dbgs() << " argument copy elision failed: alignment of alloca "
95149513
"greater than stack argument alignment ("

llvm/lib/IR/Core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
20212021
if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
20222022
GV->setAlignment(MaybeAlign(Bytes));
20232023
else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
2024-
AI->setAlignment(MaybeAlign(Bytes));
2024+
AI->setAlignment(Align(Bytes));
20252025
else if (LoadInst *LI = dyn_cast<LoadInst>(P))
20262026
LI->setAlignment(Align(Bytes));
20272027
else if (StoreInst *SI = dyn_cast<StoreInst>(P))

llvm/lib/IR/Instructions.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,15 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
12461246
return Amt;
12471247
}
12481248

1249+
Align computeAllocaDefaultAlign(Type *Ty, BasicBlock *BB) {
1250+
const DataLayout &DL = BB->getModule()->getDataLayout();
1251+
return DL.getPrefTypeAlign(Ty);
1252+
}
1253+
1254+
Align computeAllocaDefaultAlign(Type *Ty, Instruction *I) {
1255+
return computeAllocaDefaultAlign(Ty, I->getParent());
1256+
}
1257+
12491258
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
12501259
Instruction *InsertBefore)
12511260
: AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
@@ -1256,27 +1265,29 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
12561265

12571266
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
12581267
const Twine &Name, Instruction *InsertBefore)
1259-
: AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertBefore) {
1260-
}
1268+
: AllocaInst(Ty, AddrSpace, ArraySize,
1269+
computeAllocaDefaultAlign(Ty, InsertBefore), Name,
1270+
InsertBefore) {}
12611271

12621272
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
12631273
const Twine &Name, BasicBlock *InsertAtEnd)
1264-
: AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertAtEnd) {}
1274+
: AllocaInst(Ty, AddrSpace, ArraySize,
1275+
computeAllocaDefaultAlign(Ty, InsertAtEnd), Name,
1276+
InsertAtEnd) {}
12651277

12661278
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1267-
MaybeAlign Align, const Twine &Name,
1279+
Align Align, const Twine &Name,
12681280
Instruction *InsertBefore)
12691281
: UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
12701282
getAISize(Ty->getContext(), ArraySize), InsertBefore),
12711283
AllocatedType(Ty) {
1272-
setAlignment(MaybeAlign(Align));
1284+
setAlignment(Align);
12731285
assert(!Ty->isVoidTy() && "Cannot allocate void!");
12741286
setName(Name);
12751287
}
12761288

12771289
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
1278-
MaybeAlign Align, const Twine &Name,
1279-
BasicBlock *InsertAtEnd)
1290+
Align Align, const Twine &Name, BasicBlock *InsertAtEnd)
12801291
: UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
12811292
getAISize(Ty->getContext(), ArraySize), InsertAtEnd),
12821293
AllocatedType(Ty) {
@@ -1285,16 +1296,12 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
12851296
setName(Name);
12861297
}
12871298

1288-
void AllocaInst::setAlignment(MaybeAlign Align) {
1289-
assert((!Align || *Align <= MaximumAlignment) &&
1299+
void AllocaInst::setAlignment(Align Align) {
1300+
assert(Align <= MaximumAlignment &&
12901301
"Alignment is greater than MaximumAlignment!");
12911302
setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) |
12921303
encode(Align));
1293-
if (Align)
1294-
assert(getAlignment() == Align->value() &&
1295-
"Alignment representation error!");
1296-
else
1297-
assert(getAlignment() == 0 && "Alignment representation error!");
1304+
assert(getAlignment() == Align.value() && "Alignment representation error!");
12981305
}
12991306

13001307
bool AllocaInst::isArrayAllocation() const {
@@ -4240,7 +4247,7 @@ InsertValueInst *InsertValueInst::cloneImpl() const {
42404247
AllocaInst *AllocaInst::cloneImpl() const {
42414248
AllocaInst *Result =
42424249
new AllocaInst(getAllocatedType(), getType()->getAddressSpace(),
4243-
(Value *)getOperand(0), MaybeAlign(getAlignment()));
4250+
getOperand(0), getAlign());
42444251
Result->setUsedWithInAlloca(isUsedWithInAlloca());
42454252
Result->setSwiftError(isSwiftError());
42464253
return Result;

llvm/lib/Target/AArch64/AArch64StackTagging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void AArch64StackTagging::alignAndPadAlloca(AllocaInfo &Info) {
484484
auto *NewAI = new AllocaInst(
485485
TypeWithPadding, Info.AI->getType()->getAddressSpace(), nullptr, "", Info.AI);
486486
NewAI->takeName(Info.AI);
487-
NewAI->setAlignment(MaybeAlign(Info.AI->getAlignment()));
487+
NewAI->setAlignment(Info.AI->getAlign());
488488
NewAI->setUsedWithInAlloca(Info.AI->isUsedWithInAlloca());
489489
NewAI->setSwiftError(Info.AI->isSwiftError());
490490
NewAI->copyMetadata(*Info.AI);

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ AllocaInst* AMDGPULibCalls::insertAlloca(CallInst *UI, IRBuilder<> &B,
14161416
B.SetInsertPoint(&*ItNew);
14171417
AllocaInst *Alloc = B.CreateAlloca(RetType, 0,
14181418
std::string(prefix) + UI->getName());
1419-
Alloc->setAlignment(MaybeAlign(
1420-
UCallee->getParent()->getDataLayout().getTypeAllocSize(RetType)));
1419+
Alloc->setAlignment(
1420+
Align(UCallee->getParent()->getDataLayout().getTypeAllocSize(RetType)));
14211421
return Alloc;
14221422
}
14231423

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ void NVPTXLowerArgs::handleByValParam(Argument *Arg) {
159159
assert(PType && "Expecting pointer type in handleByValParam");
160160

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

170172
Value *ArgInParam = new AddrSpaceCastInst(

llvm/lib/Transforms/Coroutines/CoroElide.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ struct Lowerer : coro::LowererBase {
3434

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

37-
void elideHeapAllocations(Function *F, uint64_t FrameSize,
38-
MaybeAlign FrameAlign, AAResults &AA);
37+
void elideHeapAllocations(Function *F, uint64_t FrameSize, Align FrameAlign,
38+
AAResults &AA);
3939
bool shouldElide(Function *F, DominatorTree &DT) const;
4040
void collectPostSplitCoroIds(Function *F);
4141
bool processCoroId(CoroIdInst *, AAResults &AA, DominatorTree &DT);
@@ -95,7 +95,7 @@ static void removeTailCallAttribute(AllocaInst *Frame, AAResults &AA) {
9595

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

112-
return std::make_pair(Size, Align);
112+
return std::make_pair(Size, *Align);
113113
}
114114

115115
// Finds first non alloca instruction in the entry block of a function.
@@ -123,7 +123,7 @@ static Instruction *getFirstNonAllocaInTheEntryBlock(Function *F) {
123123
// To elide heap allocations we need to suppress code blocks guarded by
124124
// llvm.coro.alloc and llvm.coro.free instructions.
125125
void Lowerer::elideHeapAllocations(Function *F, uint64_t FrameSize,
126-
MaybeAlign FrameAlign, AAResults &AA) {
126+
Align FrameAlign, AAResults &AA) {
127127
LLVMContext &C = F->getContext();
128128
auto *InsertPt =
129129
getFirstNonAllocaInTheEntryBlock(CoroIds.front()->getFunction());

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst*> LocalAllocas,
12661266

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

12711271
for (auto U : AI->users()) {
12721272
// Replace gets with the allocation.

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,10 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
385385

386386
// Just add all the struct element types.
387387
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
388-
Value *TheAlloca =
389-
new AllocaInst(AgTy, DL.getAllocaAddrSpace(), nullptr,
390-
MaybeAlign(I->getParamAlignment()), "", InsertPt);
388+
Value *TheAlloca = new AllocaInst(
389+
AgTy, DL.getAllocaAddrSpace(), nullptr,
390+
I->getParamAlign().getValueOr(DL.getPrefTypeAlign(AgTy)), "",
391+
InsertPt);
391392
StructType *STy = cast<StructType>(AgTy);
392393
Value *Idxs[2] = {ConstantInt::get(Type::getInt32Ty(F->getContext()), 0),
393394
nullptr};

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,7 @@ struct AAHeapToStackImpl : public AAHeapToStack {
47244724
LLVM_DEBUG(dbgs() << "H2S: Removing malloc call: " << *MallocCall
47254725
<< "\n");
47264726

4727-
MaybeAlign Alignment;
4727+
Align Alignment;
47284728
Constant *Size;
47294729
if (isCallocLikeFn(MallocCall, TLI)) {
47304730
auto *Num = cast<ConstantInt>(MallocCall->getOperand(0));
@@ -4736,7 +4736,8 @@ struct AAHeapToStackImpl : public AAHeapToStack {
47364736
Size = cast<ConstantInt>(MallocCall->getOperand(1));
47374737
Alignment = MaybeAlign(cast<ConstantInt>(MallocCall->getOperand(0))
47384738
->getValue()
4739-
.getZExtValue());
4739+
.getZExtValue())
4740+
.valueOrOne();
47404741
} else {
47414742
Size = cast<ConstantInt>(MallocCall->getOperand(0));
47424743
}

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static void mergeInlinedArrayAllocas(Function *Caller, InlineFunctionInfo &IFI,
229229
}
230230

231231
if (Align1 > Align2)
232-
AvailableAlloca->setAlignment(MaybeAlign(AI->getAlignment()));
232+
AvailableAlloca->setAlignment(AI->getAlign());
233233
}
234234

235235
AI->eraseFromParent();

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
141141
}
142142

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

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
181181
if (C->getValue().getActiveBits() <= 64) {
182182
Type *NewTy = ArrayType::get(AI.getAllocatedType(), C->getZExtValue());
183183
AllocaInst *New = IC.Builder.CreateAlloca(NewTy, nullptr, AI.getName());
184-
New->setAlignment(MaybeAlign(AI.getAlignment()));
184+
New->setAlignment(AI.getAlign());
185185

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

329329
if (AI.getAllocatedType()->isSized()) {
330-
// If the alignment is 0 (unspecified), assign it the preferred alignment.
331-
if (AI.getAlignment() == 0)
332-
AI.setAlignment(
333-
MaybeAlign(DL.getPrefTypeAlignment(AI.getAllocatedType())));
334-
335330
// Move all alloca's of zero byte objects to the entry block and merge them
336331
// together. Note that we only do this for alloca's, because malloc should
337332
// allocate and return a unique pointer, even for a zero byte allocation.
@@ -358,16 +353,10 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
358353
return &AI;
359354
}
360355

361-
// If the alignment of the entry block alloca is 0 (unspecified),
362-
// assign it the preferred alignment.
363-
if (EntryAI->getAlignment() == 0)
364-
EntryAI->setAlignment(
365-
MaybeAlign(DL.getPrefTypeAlignment(EntryAI->getAllocatedType())));
366356
// Replace this zero-sized alloca with the one at the start of the entry
367357
// block after ensuring that the address will be aligned enough for both
368358
// types.
369-
const MaybeAlign MaxAlign(
370-
std::max(EntryAI->getAlignment(), AI.getAlignment()));
359+
const Align MaxAlign = std::max(EntryAI->getAlign(), AI.getAlign());
371360
EntryAI->setAlignment(MaxAlign);
372361
if (AI.getType() != EntryAI->getType())
373362
return new BitCastInst(EntryAI, AI.getType());

0 commit comments

Comments
 (0)