Skip to content

Commit 604f449

Browse files
committed
[InstCombine] Clean up alignment handling (NFC)
Now that load/store alignment is required, we can simplify code in some places.
1 parent 2123bb8 commit 604f449

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,8 @@ LoadInst *InstCombiner::combineLoadToNewType(LoadInst &LI, Type *NewTy,
447447
NewPtr->getType()->getPointerAddressSpace() == AS))
448448
NewPtr = Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
449449

450-
// If old load did not have an explicit alignment specified,
451-
// manually preserve the implied (ABI) alignment of the load.
452-
// Else we may inadvertently incorrectly over-promise alignment.
453-
const auto Align =
454-
getDataLayout().getValueOrABITypeAlignment(LI.getAlign(), LI.getType());
455-
456450
LoadInst *NewLoad = Builder.CreateAlignedLoad(
457-
NewTy, NewPtr, Align, LI.isVolatile(), LI.getName() + Suffix);
451+
NewTy, NewPtr, LI.getAlign(), LI.isVolatile(), LI.getName() + Suffix);
458452
NewLoad->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
459453
copyMetadataForLoad(*NewLoad, LI);
460454
return NewLoad;
@@ -656,8 +650,7 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) {
656650
if (SL->hasPadding())
657651
return nullptr;
658652

659-
const auto Align = DL.getValueOrABITypeAlignment(LI.getAlign(), ST);
660-
653+
const auto Align = LI.getAlign();
661654
auto *Addr = LI.getPointerOperand();
662655
auto *IdxType = Type::getInt32Ty(T->getContext());
663656
auto *Zero = ConstantInt::get(IdxType, 0);
@@ -705,7 +698,7 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) {
705698

706699
const DataLayout &DL = IC.getDataLayout();
707700
auto EltSize = DL.getTypeAllocSize(ET);
708-
const auto Align = DL.getValueOrABITypeAlignment(LI.getAlign(), T);
701+
const auto Align = LI.getAlign();
709702

710703
auto *Addr = LI.getPointerOperand();
711704
auto *IdxType = Type::getInt64Ty(T->getContext());
@@ -945,14 +938,8 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
945938
// Attempt to improve the alignment.
946939
Align KnownAlign = getOrEnforceKnownAlignment(
947940
Op, DL.getPrefTypeAlign(LI.getType()), DL, &LI, &AC, &DT);
948-
MaybeAlign LoadAlign = LI.getAlign();
949-
Align EffectiveLoadAlign =
950-
LoadAlign ? *LoadAlign : DL.getABITypeAlign(LI.getType());
951-
952-
if (KnownAlign > EffectiveLoadAlign)
941+
if (KnownAlign > LI.getAlign())
953942
LI.setAlignment(KnownAlign);
954-
else if (LoadAlign == 0)
955-
LI.setAlignment(EffectiveLoadAlign);
956943

957944
// Replace GEP indices if possible.
958945
if (Instruction *NewGEPI = replaceGEPIdxWithZero(*this, Op, LI)) {
@@ -1179,7 +1166,7 @@ static bool unpackStoreToAggregate(InstCombiner &IC, StoreInst &SI) {
11791166
if (SL->hasPadding())
11801167
return false;
11811168

1182-
const auto Align = DL.getValueOrABITypeAlignment(SI.getAlign(), ST);
1169+
const auto Align = SI.getAlign();
11831170

11841171
SmallString<16> EltName = V->getName();
11851172
EltName += ".elt";
@@ -1225,7 +1212,7 @@ static bool unpackStoreToAggregate(InstCombiner &IC, StoreInst &SI) {
12251212

12261213
const DataLayout &DL = IC.getDataLayout();
12271214
auto EltSize = DL.getTypeAllocSize(AT->getElementType());
1228-
const auto Align = DL.getValueOrABITypeAlignment(SI.getAlign(), T);
1215+
const auto Align = SI.getAlign();
12291216

12301217
SmallString<16> EltName = V->getName();
12311218
EltName += ".elt";
@@ -1350,14 +1337,8 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
13501337
// Attempt to improve the alignment.
13511338
const Align KnownAlign = getOrEnforceKnownAlignment(
13521339
Ptr, DL.getPrefTypeAlign(Val->getType()), DL, &SI, &AC, &DT);
1353-
const MaybeAlign StoreAlign = SI.getAlign();
1354-
const Align EffectiveStoreAlign =
1355-
StoreAlign ? *StoreAlign : DL.getABITypeAlign(Val->getType());
1356-
1357-
if (KnownAlign > EffectiveStoreAlign)
1340+
if (KnownAlign > SI.getAlign())
13581341
SI.setAlignment(KnownAlign);
1359-
else if (!StoreAlign)
1360-
SI.setAlignment(EffectiveStoreAlign);
13611342

13621343
// Try to canonicalize the stored type.
13631344
if (unpackStoreToAggregate(*this, SI))

0 commit comments

Comments
 (0)