[Alignment][NFC] Remove StoreInst::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, bollu, jdoerfert

Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68268

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373595 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Guillaume Chatelet 2019-10-03 13:17:21 +00:00
parent f57ee998e4
commit 34ace4c17a
15 changed files with 32 additions and 39 deletions

View File

@ -1649,7 +1649,7 @@ public:
StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align, StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
bool isVolatile = false) { bool isVolatile = false) {
StoreInst *SI = CreateStore(Val, Ptr, isVolatile); StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
SI->setAlignment(Align); SI->setAlignment(MaybeAlign(Align));
return SI; return SI;
} }

View File

@ -374,8 +374,6 @@ public:
return 0; return 0;
} }
// FIXME: Remove once migration to Align is over.
void setAlignment(unsigned Align);
void setAlignment(MaybeAlign Align); void setAlignment(MaybeAlign Align);
/// Returns the ordering constraint of this store instruction. /// Returns the ordering constraint of this store instruction.

View File

@ -469,7 +469,7 @@ StoreInst *AtomicExpand::convertAtomicStoreToIntegerType(StoreInst *SI) {
Value *NewAddr = Builder.CreateBitCast(Addr, PT); Value *NewAddr = Builder.CreateBitCast(Addr, PT);
StoreInst *NewSI = Builder.CreateStore(NewVal, NewAddr); StoreInst *NewSI = Builder.CreateStore(NewVal, NewAddr);
NewSI->setAlignment(SI->getAlignment()); NewSI->setAlignment(MaybeAlign(SI->getAlignment()));
NewSI->setVolatile(SI->isVolatile()); NewSI->setVolatile(SI->isVolatile());
NewSI->setAtomic(SI->getOrdering(), SI->getSyncScopeID()); NewSI->setAtomic(SI->getOrdering(), SI->getSyncScopeID());
LLVM_DEBUG(dbgs() << "Replaced " << *SI << " with " << *NewSI << "\n"); LLVM_DEBUG(dbgs() << "Replaced " << *SI << " with " << *NewSI << "\n");

View File

@ -2014,7 +2014,7 @@ void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
else if (LoadInst *LI = dyn_cast<LoadInst>(P)) else if (LoadInst *LI = dyn_cast<LoadInst>(P))
LI->setAlignment(MaybeAlign(Bytes)); LI->setAlignment(MaybeAlign(Bytes));
else if (StoreInst *SI = dyn_cast<StoreInst>(P)) else if (StoreInst *SI = dyn_cast<StoreInst>(P))
SI->setAlignment(Bytes); SI->setAlignment(MaybeAlign(Bytes));
else else
llvm_unreachable( llvm_unreachable(
"only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment"); "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");

View File

@ -1397,7 +1397,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
Op<0>() = val; Op<0>() = val;
Op<1>() = addr; Op<1>() = addr;
setVolatile(isVolatile); setVolatile(isVolatile);
setAlignment(Align); setAlignment(MaybeAlign(Align));
setAtomic(Order, SSID); setAtomic(Order, SSID);
AssertOK(); AssertOK();
} }
@ -1413,15 +1413,11 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
Op<0>() = val; Op<0>() = val;
Op<1>() = addr; Op<1>() = addr;
setVolatile(isVolatile); setVolatile(isVolatile);
setAlignment(Align); setAlignment(MaybeAlign(Align));
setAtomic(Order, SSID); setAtomic(Order, SSID);
AssertOK(); AssertOK();
} }
void StoreInst::setAlignment(unsigned Align) {
setAlignment(llvm::MaybeAlign(Align));
}
void StoreInst::setAlignment(MaybeAlign Align) { void StoreInst::setAlignment(MaybeAlign Align) {
assert((!Align || *Align <= MaximumAlignment) && assert((!Align || *Align <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!"); "Alignment is greater than MaximumAlignment!");

View File

@ -2467,7 +2467,7 @@ struct AAAlignImpl : AAAlign {
if (SI->getAlignment() < getAssumedAlign()) { if (SI->getAlignment() < getAssumedAlign()) {
STATS_DECLTRACK(AAAlign, Store, STATS_DECLTRACK(AAAlign, Store,
"Number of times alignemnt added to a store"); "Number of times alignemnt added to a store");
SI->setAlignment(getAssumedAlign()); SI->setAlignment(Align(getAssumedAlign()));
Changed = ChangeStatus::CHANGED; Changed = ChangeStatus::CHANGED;
} }
} else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) { } else if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {

View File

@ -124,7 +124,7 @@ Instruction *InstCombiner::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
auto *SI = new StoreInst(RMWI.getValOperand(), auto *SI = new StoreInst(RMWI.getValOperand(),
RMWI.getPointerOperand(), &RMWI); RMWI.getPointerOperand(), &RMWI);
SI->setAtomic(Ordering, RMWI.getSyncScopeID()); SI->setAtomic(Ordering, RMWI.getSyncScopeID());
SI->setAlignment(DL.getABITypeAlignment(RMWI.getType())); SI->setAlignment(MaybeAlign(DL.getABITypeAlignment(RMWI.getType())));
return eraseInstFromFunction(RMWI); return eraseInstFromFunction(RMWI);
} }

View File

@ -185,7 +185,8 @@ Instruction *InstCombiner::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy); Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
LoadInst *L = Builder.CreateLoad(IntType, Src); LoadInst *L = Builder.CreateLoad(IntType, Src);
// Alignment from the mem intrinsic will be better, so use it. // Alignment from the mem intrinsic will be better, so use it.
L->setAlignment(MaybeAlign(CopySrcAlign)); L->setAlignment(
MaybeAlign(CopySrcAlign)); // FIXME: Check if we can use Align instead.
if (CopyMD) if (CopyMD)
L->setMetadata(LLVMContext::MD_tbaa, CopyMD); L->setMetadata(LLVMContext::MD_tbaa, CopyMD);
MDNode *LoopMemParallelMD = MDNode *LoopMemParallelMD =
@ -198,7 +199,8 @@ Instruction *InstCombiner::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
StoreInst *S = Builder.CreateStore(L, Dest); StoreInst *S = Builder.CreateStore(L, Dest);
// Alignment from the mem intrinsic will be better, so use it. // Alignment from the mem intrinsic will be better, so use it.
S->setAlignment(CopyDstAlign); S->setAlignment(
MaybeAlign(CopyDstAlign)); // FIXME: Check if we can use Align instead.
if (CopyMD) if (CopyMD)
S->setMetadata(LLVMContext::MD_tbaa, CopyMD); S->setMetadata(LLVMContext::MD_tbaa, CopyMD);
if (LoopMemParallelMD) if (LoopMemParallelMD)
@ -223,9 +225,10 @@ Instruction *InstCombiner::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
} }
Instruction *InstCombiner::SimplifyAnyMemSet(AnyMemSetInst *MI) { Instruction *InstCombiner::SimplifyAnyMemSet(AnyMemSetInst *MI) {
unsigned Alignment = getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT); const unsigned KnownAlignment =
if (MI->getDestAlignment() < Alignment) { getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT);
MI->setDestAlignment(Alignment); if (MI->getDestAlignment() < KnownAlignment) {
MI->setDestAlignment(KnownAlignment);
return MI; return MI;
} }
@ -243,13 +246,9 @@ Instruction *InstCombiner::SimplifyAnyMemSet(AnyMemSetInst *MI) {
ConstantInt *FillC = dyn_cast<ConstantInt>(MI->getValue()); ConstantInt *FillC = dyn_cast<ConstantInt>(MI->getValue());
if (!LenC || !FillC || !FillC->getType()->isIntegerTy(8)) if (!LenC || !FillC || !FillC->getType()->isIntegerTy(8))
return nullptr; return nullptr;
uint64_t Len = LenC->getLimitedValue(); const uint64_t Len = LenC->getLimitedValue();
Alignment = MI->getDestAlignment();
assert(Len && "0-sized memory setting should be removed already."); assert(Len && "0-sized memory setting should be removed already.");
const Align Alignment = assumeAligned(MI->getDestAlignment());
// Alignment 0 is identity for alignment 1 for memset, but not store.
if (Alignment == 0)
Alignment = 1;
// If it is an atomic and alignment is less than the size then we will // If it is an atomic and alignment is less than the size then we will
// introduce the unaligned memory access which will be later transformed // introduce the unaligned memory access which will be later transformed

View File

@ -1356,15 +1356,15 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
return eraseInstFromFunction(SI); return eraseInstFromFunction(SI);
// Attempt to improve the alignment. // Attempt to improve the alignment.
unsigned KnownAlign = getOrEnforceKnownAlignment( const Align KnownAlign = Align(getOrEnforceKnownAlignment(
Ptr, DL.getPrefTypeAlignment(Val->getType()), DL, &SI, &AC, &DT); Ptr, DL.getPrefTypeAlignment(Val->getType()), DL, &SI, &AC, &DT));
unsigned StoreAlign = SI.getAlignment(); const MaybeAlign StoreAlign = MaybeAlign(SI.getAlignment());
unsigned EffectiveStoreAlign = const Align EffectiveStoreAlign =
StoreAlign != 0 ? StoreAlign : DL.getABITypeAlignment(Val->getType()); StoreAlign ? *StoreAlign : Align(DL.getABITypeAlignment(Val->getType()));
if (KnownAlign > EffectiveStoreAlign) if (KnownAlign > EffectiveStoreAlign)
SI.setAlignment(KnownAlign); SI.setAlignment(KnownAlign);
else if (StoreAlign == 0) else if (!StoreAlign)
SI.setAlignment(EffectiveStoreAlign); SI.setAlignment(EffectiveStoreAlign);
// Try to canonicalize the stored type. // Try to canonicalize the stored type.

View File

@ -329,7 +329,7 @@ bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
SI->getPointerOperand(), SE); SI->getPointerOperand(), SE);
if (NewAlignment > SI->getAlignment()) { if (NewAlignment > SI->getAlignment()) {
SI->setAlignment(NewAlignment); SI->setAlignment(MaybeAlign(NewAlignment));
++NumStoreAlignChanged; ++NumStoreAlignChanged;
} }
} else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(J)) { } else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(J)) {

View File

@ -894,8 +894,8 @@ private:
++NumLoadsRemoved; ++NumLoadsRemoved;
} else if (auto *ReplacementStore = dyn_cast<StoreInst>(Repl)) { } else if (auto *ReplacementStore = dyn_cast<StoreInst>(Repl)) {
ReplacementStore->setAlignment( ReplacementStore->setAlignment(
std::min(ReplacementStore->getAlignment(), MaybeAlign(std::min(ReplacementStore->getAlignment(),
cast<StoreInst>(I)->getAlignment())); cast<StoreInst>(I)->getAlignment())));
++NumStoresRemoved; ++NumStoresRemoved;
} else if (auto *ReplacementAlloca = dyn_cast<AllocaInst>(Repl)) { } else if (auto *ReplacementAlloca = dyn_cast<AllocaInst>(Repl)) {
ReplacementAlloca->setAlignment( ReplacementAlloca->setAlignment(

View File

@ -1790,7 +1790,7 @@ public:
StoreInst *NewSI = new StoreInst(LiveInValue, Ptr, InsertPos); StoreInst *NewSI = new StoreInst(LiveInValue, Ptr, InsertPos);
if (UnorderedAtomic) if (UnorderedAtomic)
NewSI->setOrdering(AtomicOrdering::Unordered); NewSI->setOrdering(AtomicOrdering::Unordered);
NewSI->setAlignment(Alignment); NewSI->setAlignment(MaybeAlign(Alignment));
NewSI->setDebugLoc(DL); NewSI->setDebugLoc(DL);
if (AATags) if (AATags)
NewSI->setAAMetadata(AATags); NewSI->setAAMetadata(AATags);

View File

@ -3127,7 +3127,7 @@ private:
Value *Op = SI->getOperand(0); Value *Op = SI->getOperand(0);
StoreAlign = DL.getABITypeAlignment(Op->getType()); StoreAlign = DL.getABITypeAlignment(Op->getType());
} }
SI->setAlignment(std::min(StoreAlign, getSliceAlign())); SI->setAlignment(MaybeAlign(std::min(StoreAlign, getSliceAlign())));
continue; continue;
} }

View File

@ -3087,15 +3087,15 @@ static bool mergeConditionalStoreToAddress(BasicBlock *PTB, BasicBlock *PFB,
// store that doesn't execute. // store that doesn't execute.
if (MinAlignment != 0) { if (MinAlignment != 0) {
// Choose the minimum of all non-zero alignments. // Choose the minimum of all non-zero alignments.
SI->setAlignment(MinAlignment); SI->setAlignment(Align(MinAlignment));
} else if (MaxAlignment != 0) { } else if (MaxAlignment != 0) {
// Choose the minimal alignment between the non-zero alignment and the ABI // Choose the minimal alignment between the non-zero alignment and the ABI
// default alignment for the type of the stored value. // default alignment for the type of the stored value.
SI->setAlignment(std::min(MaxAlignment, TypeAlignment)); SI->setAlignment(Align(std::min(MaxAlignment, TypeAlignment)));
} else { } else {
// If both alignments are zero, use ABI default alignment for the type of // If both alignments are zero, use ABI default alignment for the type of
// the stored value. // the stored value.
SI->setAlignment(TypeAlignment); SI->setAlignment(Align(TypeAlignment));
} }
QStore->eraseFromParent(); QStore->eraseFromParent();

View File

@ -4024,7 +4024,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
if (!Alignment) if (!Alignment)
Alignment = DL->getABITypeAlignment(SI->getValueOperand()->getType()); Alignment = DL->getABITypeAlignment(SI->getValueOperand()->getType());
ST->setAlignment(Alignment); ST->setAlignment(Align(Alignment));
Value *V = propagateMetadata(ST, E->Scalars); Value *V = propagateMetadata(ST, E->Scalars);
if (NeedToShuffleReuses) { if (NeedToShuffleReuses) {
V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy), V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy),