Skip to content

Commit 1738022

Browse files
committedSep 30, 2019
[Alignment][NFC] Remove LoadInst::setAlignment(unsigned)
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68142 llvm-svn: 373195
1 parent 5a039d5 commit 1738022

18 files changed

+30
-38
lines changed
 

‎clang/lib/CodeGen/CGCleanup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void createStoreInstBefore(llvm::Value *value, Address addr,
310310
static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
311311
llvm::Instruction *beforeInst) {
312312
auto load = new llvm::LoadInst(addr.getPointer(), name, beforeInst);
313-
load->setAlignment(addr.getAlignment().getQuantity());
313+
load->setAlignment(llvm::MaybeAlign(addr.getAlignment().getQuantity()));
314314
return load;
315315
}
316316

‎llvm/include/llvm/IR/IRBuilder.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1612,19 +1612,19 @@ class IRBuilder : public IRBuilderBase, public Inserter {
16121612
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
16131613
const char *Name) {
16141614
LoadInst *LI = CreateLoad(Ty, Ptr, Name);
1615-
LI->setAlignment(Align);
1615+
LI->setAlignment(MaybeAlign(Align));
16161616
return LI;
16171617
}
16181618
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
16191619
const Twine &Name = "") {
16201620
LoadInst *LI = CreateLoad(Ty, Ptr, Name);
1621-
LI->setAlignment(Align);
1621+
LI->setAlignment(MaybeAlign(Align));
16221622
return LI;
16231623
}
16241624
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
16251625
bool isVolatile, const Twine &Name = "") {
16261626
LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name);
1627-
LI->setAlignment(Align);
1627+
LI->setAlignment(MaybeAlign(Align));
16281628
return LI;
16291629
}
16301630

‎llvm/include/llvm/IR/Instructions.h

-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ class LoadInst : public UnaryInstruction {
248248
return 0;
249249
}
250250

251-
// FIXME: Remove once migration to Align is over.
252-
void setAlignment(unsigned Align);
253251
void setAlignment(MaybeAlign Align);
254252

255253
/// Returns the ordering constraint of this load instruction.

‎llvm/lib/CodeGen/AtomicExpandPass.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ LoadInst *AtomicExpand::convertAtomicLoadToIntegerType(LoadInst *LI) {
382382
Value *NewAddr = Builder.CreateBitCast(Addr, PT);
383383

384384
auto *NewLI = Builder.CreateLoad(NewTy, NewAddr);
385-
NewLI->setAlignment(LI->getAlignment());
385+
NewLI->setAlignment(MaybeAlign(LI->getAlignment()));
386386
NewLI->setVolatile(LI->isVolatile());
387387
NewLI->setAtomic(LI->getOrdering(), LI->getSyncScopeID());
388388
LLVM_DEBUG(dbgs() << "Replaced " << *LI << " with " << *NewLI << "\n");
@@ -1376,7 +1376,7 @@ Value *AtomicExpand::insertRMWCmpXchgLoop(
13761376
Builder.SetInsertPoint(BB);
13771377
LoadInst *InitLoaded = Builder.CreateLoad(ResultTy, Addr);
13781378
// Atomics require at least natural alignment.
1379-
InitLoaded->setAlignment(ResultTy->getPrimitiveSizeInBits() / 8);
1379+
InitLoaded->setAlignment(MaybeAlign(ResultTy->getPrimitiveSizeInBits() / 8));
13801380
Builder.CreateBr(LoopBB);
13811381

13821382
// Start the main loop block now that we've taken care of the preliminaries.

‎llvm/lib/IR/Core.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
20122012
else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
20132013
AI->setAlignment(Bytes);
20142014
else if (LoadInst *LI = dyn_cast<LoadInst>(P))
2015-
LI->setAlignment(Bytes);
2015+
LI->setAlignment(MaybeAlign(Bytes));
20162016
else if (StoreInst *SI = dyn_cast<StoreInst>(P))
20172017
SI->setAlignment(Bytes);
20182018
else

‎llvm/lib/IR/Instructions.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
13211321
: UnaryInstruction(Ty, Load, Ptr, InsertBef) {
13221322
assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
13231323
setVolatile(isVolatile);
1324-
setAlignment(Align);
1324+
setAlignment(MaybeAlign(Align));
13251325
setAtomic(Order, SSID);
13261326
AssertOK();
13271327
setName(Name);
@@ -1333,16 +1333,12 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
13331333
: UnaryInstruction(Ty, Load, Ptr, InsertAE) {
13341334
assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
13351335
setVolatile(isVolatile);
1336-
setAlignment(Align);
1336+
setAlignment(MaybeAlign(Align));
13371337
setAtomic(Order, SSID);
13381338
AssertOK();
13391339
setName(Name);
13401340
}
13411341

1342-
void LoadInst::setAlignment(unsigned Align) {
1343-
setAlignment(llvm::MaybeAlign(Align));
1344-
}
1345-
13461342
void LoadInst::setAlignment(MaybeAlign Align) {
13471343
assert((!Align || *Align <= MaximumAlignment) &&
13481344
"Alignment is greater than MaximumAlignment!");

‎llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
304304
// of the previous load.
305305
LoadInst *newLoad =
306306
IRB.CreateLoad(OrigLoad->getType(), V, V->getName() + ".val");
307-
newLoad->setAlignment(OrigLoad->getAlignment());
307+
newLoad->setAlignment(MaybeAlign(OrigLoad->getAlignment()));
308308
// Transfer the AA info too.
309309
AAMDNodes AAInfo;
310310
OrigLoad->getAAMetadata(AAInfo);

‎llvm/lib/Transforms/IPO/Attributor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ struct AAAlignImpl : AAAlign {
24732473
} else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
24742474
if (LI->getPointerOperand() == &AnchorVal)
24752475
if (LI->getAlignment() < getAssumedAlign()) {
2476-
LI->setAlignment(getAssumedAlign());
2476+
LI->setAlignment(Align(getAssumedAlign()));
24772477
STATS_DECLTRACK(AAAlign, Load,
24782478
"Number of times alignemnt added to a load");
24792479
Changed = ChangeStatus::CHANGED;

‎llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ Instruction *InstCombiner::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
154154

155155
LoadInst *Load = new LoadInst(RMWI.getType(), RMWI.getPointerOperand());
156156
Load->setAtomic(Ordering, RMWI.getSyncScopeID());
157-
Load->setAlignment(DL.getABITypeAlignment(RMWI.getType()));
157+
Load->setAlignment(MaybeAlign(DL.getABITypeAlignment(RMWI.getType())));
158158
return Load;
159159
}

‎llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Instruction *InstCombiner::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
185185
Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
186186
LoadInst *L = Builder.CreateLoad(IntType, Src);
187187
// Alignment from the mem intrinsic will be better, so use it.
188-
L->setAlignment(CopySrcAlign);
188+
L->setAlignment(MaybeAlign(CopySrcAlign));
189189
if (CopyMD)
190190
L->setMetadata(LLVMContext::MD_tbaa, CopyMD);
191191
MDNode *LoopMemParallelMD =

‎llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
960960
LoadAlign != 0 ? LoadAlign : DL.getABITypeAlignment(LI.getType());
961961

962962
if (KnownAlign > EffectiveLoadAlign)
963-
LI.setAlignment(KnownAlign);
963+
LI.setAlignment(MaybeAlign(KnownAlign));
964964
else if (LoadAlign == 0)
965-
LI.setAlignment(EffectiveLoadAlign);
965+
LI.setAlignment(MaybeAlign(EffectiveLoadAlign));
966966

967967
// Replace GEP indices if possible.
968968
if (Instruction *NewGEPI = replaceGEPIdxWithZero(*this, Op, LI)) {
@@ -1031,9 +1031,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
10311031
Builder.CreateLoad(LI.getType(), SI->getOperand(2),
10321032
SI->getOperand(2)->getName() + ".val");
10331033
assert(LI.isUnordered() && "implied by above");
1034-
V1->setAlignment(Align);
1034+
V1->setAlignment(MaybeAlign(Align));
10351035
V1->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
1036-
V2->setAlignment(Align);
1036+
V2->setAlignment(MaybeAlign(Align));
10371037
V2->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
10381038
return SelectInst::Create(SI->getCondition(), V1, V2);
10391039
}

‎llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ Value *DFSanFunction::loadShadow(Value *Addr, uint64_t Size, uint64_t Align,
12121212
return DFS.ZeroShadow;
12131213
case 1: {
12141214
LoadInst *LI = new LoadInst(DFS.ShadowTy, ShadowAddr, "", Pos);
1215-
LI->setAlignment(ShadowAlign);
1215+
LI->setAlignment(MaybeAlign(ShadowAlign));
12161216
return LI;
12171217
}
12181218
case 2: {

‎llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
321321
LI->getPointerOperand(), SE);
322322

323323
if (NewAlignment > LI->getAlignment()) {
324-
LI->setAlignment(NewAlignment);
324+
LI->setAlignment(MaybeAlign(NewAlignment));
325325
++NumLoadAlignChanged;
326326
}
327327
} else if (StoreInst *SI = dyn_cast<StoreInst>(J)) {

‎llvm/lib/Transforms/Scalar/GVNHoist.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,8 @@ class GVNHoist {
889889

890890
void updateAlignment(Instruction *I, Instruction *Repl) {
891891
if (auto *ReplacementLoad = dyn_cast<LoadInst>(Repl)) {
892-
ReplacementLoad->setAlignment(
893-
std::min(ReplacementLoad->getAlignment(),
894-
cast<LoadInst>(I)->getAlignment()));
892+
ReplacementLoad->setAlignment(MaybeAlign(std::min(
893+
ReplacementLoad->getAlignment(), cast<LoadInst>(I)->getAlignment())));
895894
++NumLoadsRemoved;
896895
} else if (auto *ReplacementStore = dyn_cast<StoreInst>(Repl)) {
897896
ReplacementStore->setAlignment(

‎llvm/lib/Transforms/Scalar/LICM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ bool llvm::promoteLoopAccessesToScalars(
21092109
SomePtr->getName() + ".promoted", Preheader->getTerminator());
21102110
if (SawUnorderedAtomic)
21112111
PreheaderLoad->setOrdering(AtomicOrdering::Unordered);
2112-
PreheaderLoad->setAlignment(Alignment);
2112+
PreheaderLoad->setAlignment(MaybeAlign(Alignment));
21132113
PreheaderLoad->setDebugLoc(DL);
21142114
if (AATags)
21152115
PreheaderLoad->setAAMetadata(AATags);

‎llvm/lib/Transforms/Scalar/SROA.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ static void speculatePHINodeLoads(PHINode &PN) {
12701270
// matter which one we get and if any differ.
12711271
AAMDNodes AATags;
12721272
SomeLoad->getAAMetadata(AATags);
1273-
unsigned Align = SomeLoad->getAlignment();
1273+
const MaybeAlign Align = MaybeAlign(SomeLoad->getAlignment());
12741274

12751275
// Rewrite all loads of the PN to use the new PHI.
12761276
while (!PN.use_empty()) {
@@ -1368,8 +1368,8 @@ static void speculateSelectInstLoads(SelectInst &SI) {
13681368
NumLoadsSpeculated += 2;
13691369

13701370
// Transfer alignment and AA info if present.
1371-
TL->setAlignment(LI->getAlignment());
1372-
FL->setAlignment(LI->getAlignment());
1371+
TL->setAlignment(MaybeAlign(LI->getAlignment()));
1372+
FL->setAlignment(MaybeAlign(LI->getAlignment()));
13731373

13741374
AAMDNodes Tags;
13751375
LI->getAAMetadata(Tags);
@@ -3118,7 +3118,7 @@ class llvm::sroa::AllocaSliceRewriter
31183118
unsigned LoadAlign = LI->getAlignment();
31193119
if (!LoadAlign)
31203120
LoadAlign = DL.getABITypeAlignment(LI->getType());
3121-
LI->setAlignment(std::min(LoadAlign, getSliceAlign()));
3121+
LI->setAlignment(MaybeAlign(std::min(LoadAlign, getSliceAlign())));
31223122
continue;
31233123
}
31243124
if (StoreInst *SI = dyn_cast<StoreInst>(I)) {

‎llvm/lib/Transforms/Utils/VNCoercion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ Value *getLoadValueForLoad(LoadInst *SrcVal, unsigned Offset, Type *LoadTy,
431431
PtrVal = Builder.CreateBitCast(PtrVal, DestPTy);
432432
LoadInst *NewLoad = Builder.CreateLoad(DestTy, PtrVal);
433433
NewLoad->takeName(SrcVal);
434-
NewLoad->setAlignment(SrcVal->getAlignment());
434+
NewLoad->setAlignment(MaybeAlign(SrcVal->getAlignment()));
435435

436436
LLVM_DEBUG(dbgs() << "GVN WIDENED LOAD: " << *SrcVal << "\n");
437437
LLVM_DEBUG(dbgs() << "TO: " << *NewLoad << "\n");

‎llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -3982,11 +3982,10 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
39823982
if (getTreeEntry(PO))
39833983
ExternalUses.push_back(ExternalUser(PO, cast<User>(VecPtr), 0));
39843984

3985-
unsigned Alignment = LI->getAlignment();
3985+
MaybeAlign Alignment = MaybeAlign(LI->getAlignment());
39863986
LI = Builder.CreateLoad(VecTy, VecPtr);
3987-
if (!Alignment) {
3988-
Alignment = DL->getABITypeAlignment(ScalarLoadTy);
3989-
}
3987+
if (!Alignment)
3988+
Alignment = MaybeAlign(DL->getABITypeAlignment(ScalarLoadTy));
39903989
LI->setAlignment(Alignment);
39913990
Value *V = propagateMetadata(LI, E->Scalars);
39923991
if (IsReorder) {

0 commit comments

Comments
 (0)