Skip to content

Commit 734c74b

Browse files
committedOct 22, 2019
[Alignment][NFC] Convert LoadInst to MaybeAlign
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 Subscribers: hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69302 llvm-svn: 375498
1 parent f2c8f3b commit 734c74b

File tree

10 files changed

+37
-38
lines changed

10 files changed

+37
-38
lines changed
 

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ class LoadInst : public UnaryInstruction {
184184
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
185185
BasicBlock *InsertAtEnd);
186186
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
187-
unsigned Align, Instruction *InsertBefore = nullptr);
187+
MaybeAlign Align, Instruction *InsertBefore = nullptr);
188188
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
189-
unsigned Align, BasicBlock *InsertAtEnd);
189+
MaybeAlign Align, BasicBlock *InsertAtEnd);
190190
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
191-
unsigned Align, AtomicOrdering Order,
191+
MaybeAlign Align, AtomicOrdering Order,
192192
SyncScope::ID SSID = SyncScope::System,
193193
Instruction *InsertBefore = nullptr);
194194
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
195-
unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
195+
MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
196196
BasicBlock *InsertAtEnd);
197197

198198
// Deprecated [opaque pointer types]
@@ -211,20 +211,20 @@ class LoadInst : public UnaryInstruction {
211211
BasicBlock *InsertAtEnd)
212212
: LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
213213
isVolatile, InsertAtEnd) {}
214-
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
214+
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
215215
Instruction *InsertBefore = nullptr)
216216
: LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
217217
isVolatile, Align, InsertBefore) {}
218-
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
218+
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
219219
BasicBlock *InsertAtEnd)
220220
: LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
221221
isVolatile, Align, InsertAtEnd) {}
222-
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
222+
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
223223
AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
224224
Instruction *InsertBefore = nullptr)
225225
: LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
226226
isVolatile, Align, Order, SSID, InsertBefore) {}
227-
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
227+
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
228228
AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd)
229229
: LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
230230
isVolatile, Align, Order, SSID, InsertAtEnd) {}

‎llvm/lib/AsmParser/LLParser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6969,8 +6969,7 @@ int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
69696969
return Error(ExplicitTypeLoc,
69706970
"explicit pointee type doesn't match operand's pointee type");
69716971

6972-
Inst = new LoadInst(Ty, Val, "", isVolatile,
6973-
Alignment ? Alignment->value() : 0, Ordering, SSID);
6972+
Inst = new LoadInst(Ty, Val, "", isVolatile, Alignment, Ordering, SSID);
69746973
return AteExtraComma ? InstExtraComma : InstNormal;
69756974
}
69766975

‎llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4792,8 +4792,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
47924792
MaybeAlign Align;
47934793
if (Error Err = parseAlignmentValue(Record[OpNum], Align))
47944794
return Err;
4795-
I = new LoadInst(Ty, Op, "", Record[OpNum + 1],
4796-
Align ? Align->value() : 0);
4795+
I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align);
47974796
InstructionList.push_back(I);
47984797
break;
47994798
}
@@ -4830,8 +4829,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48304829
MaybeAlign Align;
48314830
if (Error Err = parseAlignmentValue(Record[OpNum], Align))
48324831
return Err;
4833-
I = new LoadInst(Ty, Op, "", Record[OpNum + 1],
4834-
Align ? Align->value() : 0, Ordering, SSID);
4832+
I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align, Ordering, SSID);
48354833
InstructionList.push_back(I);
48364834
break;
48374835
}

‎llvm/lib/IR/Instructions.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -1296,25 +1296,25 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
12961296

12971297
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
12981298
Instruction *InsertBef)
1299-
: LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {}
1299+
: LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertBef) {}
13001300

13011301
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
13021302
BasicBlock *InsertAE)
1303-
: LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {}
1303+
: LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertAE) {}
13041304

13051305
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1306-
unsigned Align, Instruction *InsertBef)
1306+
MaybeAlign Align, Instruction *InsertBef)
13071307
: LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
13081308
SyncScope::System, InsertBef) {}
13091309

13101310
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1311-
unsigned Align, BasicBlock *InsertAE)
1311+
MaybeAlign Align, BasicBlock *InsertAE)
13121312
: LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
13131313
SyncScope::System, InsertAE) {}
13141314

13151315
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1316-
unsigned Align, AtomicOrdering Order,
1317-
SyncScope::ID SSID, Instruction *InsertBef)
1316+
MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
1317+
Instruction *InsertBef)
13181318
: UnaryInstruction(Ty, Load, Ptr, InsertBef) {
13191319
assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
13201320
setVolatile(isVolatile);
@@ -1325,12 +1325,12 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
13251325
}
13261326

13271327
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1328-
unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
1328+
MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
13291329
BasicBlock *InsertAE)
13301330
: UnaryInstruction(Ty, Load, Ptr, InsertAE) {
13311331
assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());
13321332
setVolatile(isVolatile);
1333-
setAlignment(MaybeAlign(Align));
1333+
setAlignment(Align);
13341334
setAtomic(Order, SSID);
13351335
AssertOK();
13361336
setName(Name);
@@ -4140,7 +4140,8 @@ AllocaInst *AllocaInst::cloneImpl() const {
41404140

41414141
LoadInst *LoadInst::cloneImpl() const {
41424142
return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(),
4143-
getAlignment(), getOrdering(), getSyncScopeID());
4143+
MaybeAlign(getAlignment()), getOrdering(),
4144+
getSyncScopeID());
41444145
}
41454146

41464147
StoreInst *StoreInst::cloneImpl() const {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, CallInst *CI, Type *AllocTy,
909909
// Replace the cmp X, 0 with a use of the bool value.
910910
// Sink the load to where the compare was, if atomic rules allow us to.
911911
Value *LV = new LoadInst(InitBool->getValueType(), InitBool,
912-
InitBool->getName() + ".val", false, 0,
912+
InitBool->getName() + ".val", false, None,
913913
LI->getOrdering(), LI->getSyncScopeID(),
914914
LI->isUnordered() ? (Instruction *)ICI : LI);
915915
InitBoolUsed = true;
@@ -1716,7 +1716,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
17161716
assert(LI->getOperand(0) == GV && "Not a copy!");
17171717
// Insert a new load, to preserve the saved value.
17181718
StoreVal = new LoadInst(NewGV->getValueType(), NewGV,
1719-
LI->getName() + ".b", false, 0,
1719+
LI->getName() + ".b", false, None,
17201720
LI->getOrdering(), LI->getSyncScopeID(), LI);
17211721
} else {
17221722
assert((isa<CastInst>(StoredVal) || isa<SelectInst>(StoredVal)) &&
@@ -1732,9 +1732,9 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
17321732
} else {
17331733
// Change the load into a load of bool then a select.
17341734
LoadInst *LI = cast<LoadInst>(UI);
1735-
LoadInst *NLI =
1736-
new LoadInst(NewGV->getValueType(), NewGV, LI->getName() + ".b",
1737-
false, 0, LI->getOrdering(), LI->getSyncScopeID(), LI);
1735+
LoadInst *NLI = new LoadInst(NewGV->getValueType(), NewGV,
1736+
LI->getName() + ".b", false, None,
1737+
LI->getOrdering(), LI->getSyncScopeID(), LI);
17381738
Instruction *NSI;
17391739
if (IsOneZero)
17401740
NSI = new ZExtInst(NLI, LI->getType(), "", LI);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
23422342
// Turn PPC VSX loads into normal loads.
23432343
Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23442344
PointerType::getUnqual(II->getType()));
2345-
return new LoadInst(II->getType(), Ptr, Twine(""), false, 1);
2345+
return new LoadInst(II->getType(), Ptr, Twine(""), false, Align::None());
23462346
}
23472347
case Intrinsic::ppc_altivec_stvx:
23482348
case Intrinsic::ppc_altivec_stvxl:

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ Instruction *InstCombiner::FoldPHIArgLoadIntoPHI(PHINode &PN) {
542542
// visitLoadInst will propagate an alignment onto the load when TD is around,
543543
// and if TD isn't around, we can't handle the mixed case.
544544
bool isVolatile = FirstLI->isVolatile();
545-
unsigned LoadAlignment = FirstLI->getAlignment();
545+
MaybeAlign LoadAlignment(FirstLI->getAlignment());
546546
unsigned LoadAddrSpace = FirstLI->getPointerAddressSpace();
547547

548548
// We can't sink the load if the loaded value could be modified between the
@@ -574,10 +574,10 @@ Instruction *InstCombiner::FoldPHIArgLoadIntoPHI(PHINode &PN) {
574574

575575
// If some of the loads have an alignment specified but not all of them,
576576
// we can't do the transformation.
577-
if ((LoadAlignment != 0) != (LI->getAlignment() != 0))
577+
if ((LoadAlignment.hasValue()) != (LI->getAlignment() != 0))
578578
return nullptr;
579579

580-
LoadAlignment = std::min(LoadAlignment, LI->getAlignment());
580+
LoadAlignment = std::min(LoadAlignment, MaybeAlign(LI->getAlignment()));
581581

582582
// If the PHI is of volatile loads and the load block has multiple
583583
// successors, sinking it would remove a load of the volatile value from

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1241,10 +1241,10 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock,
12411241
BasicBlock *UnavailablePred = PredLoad.first;
12421242
Value *LoadPtr = PredLoad.second;
12431243

1244-
auto *NewLoad =
1245-
new LoadInst(LI->getType(), LoadPtr, LI->getName() + ".pre",
1246-
LI->isVolatile(), LI->getAlignment(), LI->getOrdering(),
1247-
LI->getSyncScopeID(), UnavailablePred->getTerminator());
1244+
auto *NewLoad = new LoadInst(
1245+
LI->getType(), LoadPtr, LI->getName() + ".pre", LI->isVolatile(),
1246+
MaybeAlign(LI->getAlignment()), LI->getOrdering(), LI->getSyncScopeID(),
1247+
UnavailablePred->getTerminator());
12481248
NewLoad->setDebugLoc(LI->getDebugLoc());
12491249

12501250
// Transfer the old load's AA tags to the new load.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LoadI) {
14711471
"Can't handle critical edge here!");
14721472
LoadInst *NewVal = new LoadInst(
14731473
LoadI->getType(), LoadedPtr->DoPHITranslation(LoadBB, UnavailablePred),
1474-
LoadI->getName() + ".pr", false, LoadI->getAlignment(),
1474+
LoadI->getName() + ".pr", false, MaybeAlign(LoadI->getAlignment()),
14751475
LoadI->getOrdering(), LoadI->getSyncScopeID(),
14761476
UnavailablePred->getTerminator());
14771477
NewVal->setDebugLoc(LoadI->getDebugLoc());

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ class LoadEliminationForLoop {
435435
PH->getTerminator());
436436
Value *Initial = new LoadInst(
437437
Cand.Load->getType(), InitialPtr, "load_initial",
438-
/* isVolatile */ false, Cand.Load->getAlignment(), PH->getTerminator());
438+
/* isVolatile */ false, MaybeAlign(Cand.Load->getAlignment()),
439+
PH->getTerminator());
439440

440441
PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded",
441442
&L->getHeader()->front());

0 commit comments

Comments
 (0)
Please sign in to comment.