From eb11fae6d08f479c0799db45860a98af528fa6e7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 28 Jul 2018 10:51:19 +0000 Subject: Vendor import of llvm trunk r338150: https://llvm.org/svn/llvm-project/llvm/trunk@338150 --- lib/Transforms/Scalar/AlignmentFromAssumptions.cpp | 90 +++++++--------------- 1 file changed, 28 insertions(+), 62 deletions(-) (limited to 'lib/Transforms/Scalar/AlignmentFromAssumptions.cpp') diff --git a/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp b/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp index 99480f12da9e..fa7bcec677f7 100644 --- a/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp +++ b/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp @@ -98,8 +98,8 @@ static unsigned getNewAlignmentDiff(const SCEV *DiffSCEV, const SCEV *DiffAlign = SE->getMulExpr(DiffAlignDiv, AlignSCEV); const SCEV *DiffUnitsSCEV = SE->getMinusSCEV(DiffAlign, DiffSCEV); - DEBUG(dbgs() << "\talignment relative to " << *AlignSCEV << " is " << - *DiffUnitsSCEV << " (diff: " << *DiffSCEV << ")\n"); + LLVM_DEBUG(dbgs() << "\talignment relative to " << *AlignSCEV << " is " + << *DiffUnitsSCEV << " (diff: " << *DiffSCEV << ")\n"); if (const SCEVConstant *ConstDUSCEV = dyn_cast(DiffUnitsSCEV)) { @@ -139,12 +139,12 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, // address. This address is displaced by the provided offset. DiffSCEV = SE->getMinusSCEV(DiffSCEV, OffSCEV); - DEBUG(dbgs() << "AFI: alignment of " << *Ptr << " relative to " << - *AlignSCEV << " and offset " << *OffSCEV << - " using diff " << *DiffSCEV << "\n"); + LLVM_DEBUG(dbgs() << "AFI: alignment of " << *Ptr << " relative to " + << *AlignSCEV << " and offset " << *OffSCEV + << " using diff " << *DiffSCEV << "\n"); unsigned NewAlignment = getNewAlignmentDiff(DiffSCEV, AlignSCEV, SE); - DEBUG(dbgs() << "\tnew alignment: " << NewAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew alignment: " << NewAlignment << "\n"); if (NewAlignment) { return NewAlignment; @@ -160,8 +160,8 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, const SCEV *DiffStartSCEV = DiffARSCEV->getStart(); const SCEV *DiffIncSCEV = DiffARSCEV->getStepRecurrence(*SE); - DEBUG(dbgs() << "\ttrying start/inc alignment using start " << - *DiffStartSCEV << " and inc " << *DiffIncSCEV << "\n"); + LLVM_DEBUG(dbgs() << "\ttrying start/inc alignment using start " + << *DiffStartSCEV << " and inc " << *DiffIncSCEV << "\n"); // Now compute the new alignment using the displacement to the value in the // first iteration, and also the alignment using the per-iteration delta. @@ -170,26 +170,26 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV, NewAlignment = getNewAlignmentDiff(DiffStartSCEV, AlignSCEV, SE); unsigned NewIncAlignment = getNewAlignmentDiff(DiffIncSCEV, AlignSCEV, SE); - DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n"); - DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n"); if (!NewAlignment || !NewIncAlignment) { return 0; } else if (NewAlignment > NewIncAlignment) { if (NewAlignment % NewIncAlignment == 0) { - DEBUG(dbgs() << "\tnew start/inc alignment: " << - NewIncAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewIncAlignment + << "\n"); return NewIncAlignment; } } else if (NewIncAlignment > NewAlignment) { if (NewIncAlignment % NewAlignment == 0) { - DEBUG(dbgs() << "\tnew start/inc alignment: " << - NewAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewAlignment + << "\n"); return NewAlignment; } } else if (NewIncAlignment == NewAlignment) { - DEBUG(dbgs() << "\tnew start/inc alignment: " << - NewAlignment << "\n"); + LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewAlignment + << "\n"); return NewAlignment; } } @@ -339,55 +339,24 @@ bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) { unsigned NewDestAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV, MI->getDest(), SE); - // For memory transfers, we need a common alignment for both the - // source and destination. If we have a new alignment for this - // instruction, but only for one operand, save it. If we reach the - // other operand through another assumption later, then we may - // change the alignment at that point. + LLVM_DEBUG(dbgs() << "\tmem inst: " << NewDestAlignment << "\n";); + if (NewDestAlignment > MI->getDestAlignment()) { + MI->setDestAlignment(NewDestAlignment); + ++NumMemIntAlignChanged; + } + + // For memory transfers, there is also a source alignment that + // can be set. if (MemTransferInst *MTI = dyn_cast(MI)) { unsigned NewSrcAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV, MTI->getSource(), SE); - DenseMap::iterator DI = - NewDestAlignments.find(MTI); - unsigned AltDestAlignment = (DI == NewDestAlignments.end()) ? - 0 : DI->second; - - DenseMap::iterator SI = - NewSrcAlignments.find(MTI); - unsigned AltSrcAlignment = (SI == NewSrcAlignments.end()) ? - 0 : SI->second; - - DEBUG(dbgs() << "\tmem trans: " << NewDestAlignment << " " << - AltDestAlignment << " " << NewSrcAlignment << - " " << AltSrcAlignment << "\n"); - - // Of these four alignments, pick the largest possible... - unsigned NewAlignment = 0; - if (NewDestAlignment <= std::max(NewSrcAlignment, AltSrcAlignment)) - NewAlignment = std::max(NewAlignment, NewDestAlignment); - if (AltDestAlignment <= std::max(NewSrcAlignment, AltSrcAlignment)) - NewAlignment = std::max(NewAlignment, AltDestAlignment); - if (NewSrcAlignment <= std::max(NewDestAlignment, AltDestAlignment)) - NewAlignment = std::max(NewAlignment, NewSrcAlignment); - if (AltSrcAlignment <= std::max(NewDestAlignment, AltDestAlignment)) - NewAlignment = std::max(NewAlignment, AltSrcAlignment); - - if (NewAlignment > MI->getAlignment()) { - MI->setAlignment(ConstantInt::get(Type::getInt32Ty( - MI->getParent()->getContext()), NewAlignment)); + LLVM_DEBUG(dbgs() << "\tmem trans: " << NewSrcAlignment << "\n";); + + if (NewSrcAlignment > MTI->getSourceAlignment()) { + MTI->setSourceAlignment(NewSrcAlignment); ++NumMemIntAlignChanged; } - - NewDestAlignments.insert(std::make_pair(MTI, NewDestAlignment)); - NewSrcAlignments.insert(std::make_pair(MTI, NewSrcAlignment)); - } else if (NewDestAlignment > MI->getAlignment()) { - assert((!isa(MI) || isa(MI)) && - "Unknown memory intrinsic"); - - MI->setAlignment(ConstantInt::get(Type::getInt32Ty( - MI->getParent()->getContext()), NewDestAlignment)); - ++NumMemIntAlignChanged; } } @@ -421,9 +390,6 @@ bool AlignmentFromAssumptionsPass::runImpl(Function &F, AssumptionCache &AC, SE = SE_; DT = DT_; - NewDestAlignments.clear(); - NewSrcAlignments.clear(); - bool Changed = false; for (auto &AssumeVH : AC.assumptions()) if (AssumeVH) -- cgit v1.2.3