<div dir="ltr">Hi Erik,<div><br></div><div>While working on a different patch for the SLP vectorizer, I noticed pretty different behaviour after your patch which looks like a regression. Previously, the trivial testcase below would SLP vectorize - now it does not. I was trying to make it NOT vectorize on AArch64 in certain circumstances, but this revision has rendered this rather moot and probably not correctly.</div>
<div><br></div><div><div>SLP: Analyzing blocks in f.</div><div>SLP: Found 2 stores to vectorize.</div><div>SLP: Analyzing a store chain of length 2.</div><div>SLP: Analyzing a store chain of length 2</div><div>SLP: Analyzing 2 stores at offset 0</div>
<div>SLP: bundle: store double %x1, double* %q</div><div>SLP: initialize schedule region to store double %x1, double* %q</div><div>SLP: extend schedule region end to store double %y1, double* %addr2</div><div>SLP: try schedule bundle [ store double %x1, double* %q; store double %y1, double* %addr2] in block</div>
<div>SLP: update deps of [ store double %x1, double* %q; store double %y1, double* %addr2]</div><div>SLP: update deps of / store double %y1, double* %addr2</div><div>SLP: We are not able to schedule this bundle!</div>
<div>SLP: cancel scheduling of [ store double %x1, double* %q; store double %y1, double* %addr2]</div><div>SLP: Calculating cost for tree of size 1.</div><div>SLP: Check whether the tree with height 1 is fully vectorizable .</div>
<div>SLP: Found cost=2147483647 for VF=2</div><div>; ModuleID = '../test/Transforms/SLPVectorizer/AArch64/load-store-q.ll'</div><div>target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"</div><div>target triple = "arm64-apple-ios5.0.0"</div>
<div><br></div><div>define void @f(double* %p, double* %q) {</div><div> %addr2 = getelementptr double* %q, i32 1</div><div> %addr = getelementptr double* %p, i32 1</div><div> %x = load double* %p</div><div> %y = load double* %addr</div>
<div> %x1 = fadd double %x, 1.000000e+00</div><div> %y1 = fadd double %y, 1.000000e+00</div><div> store double %x1, double* %q</div><div> store double %y1, double* %addr2</div><div> ret void</div><div>}</div></div><div>
<br></div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 1 August 2014 20:24, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Thanks for the work. It looks great. :)</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Aug 1, 2014 12:10 PM, "Erik Eckstein" <<a href="mailto:eeckstein@apple.com" target="_blank">eeckstein@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Eric, David,<br>
<br>
thanks a lot for your detailed feedback and your help!<br>
<br>
Erik<br>
<br>
<br>
On 01 Aug 2014, at 20:29, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>> wrote:<br>
<br>
> For the record, a commit log that's a bit more descriptive is helpful.<br>
> Saying what your patch did, what it changed, how it changed it, etc is<br>
> very helpful.<br>
><br>
> -eric<br>
><br>
> On Fri, Aug 1, 2014 at 2:20 AM, Erik Eckstein <<a href="mailto:eeckstein@apple.com" target="_blank">eeckstein@apple.com</a>> wrote:<br>
>> Author: eeckstein<br>
>> Date: Fri Aug 1 04:20:42 2014<br>
>> New Revision: 214494<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214494&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214494&view=rev</a><br>
>> Log:<br>
>> SLPVectorizer: improved scheduling algorithm.<br>
>><br>
>> Added:<br>
>> llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll<br>
>> Modified:<br>
>> llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
>> llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll<br>
>> llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll<br>
>><br>
>> Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=214494&r1=214493&r2=214494&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=214494&r1=214493&r2=214494&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)<br>
>> +++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Fri Aug 1 04:20:42 2014<br>
>> @@ -43,6 +43,7 @@<br>
>> #include "llvm/Transforms/Utils/VectorUtils.h"<br>
>> #include <algorithm><br>
>> #include <map><br>
>> +#include <memory><br>
>><br>
>> using namespace llvm;<br>
>><br>
>> @@ -71,53 +72,6 @@ static const unsigned MinVecRegSize = 12<br>
>><br>
>> static const unsigned RecursionMaxDepth = 12;<br>
>><br>
>> -/// A helper class for numbering instructions in multiple blocks.<br>
>> -/// Numbers start at zero for each basic block.<br>
>> -struct BlockNumbering {<br>
>> -<br>
>> - BlockNumbering(BasicBlock *Bb) : BB(Bb), Valid(false) {}<br>
>> -<br>
>> - void numberInstructions() {<br>
>> - unsigned Loc = 0;<br>
>> - InstrIdx.clear();<br>
>> - InstrVec.clear();<br>
>> - // Number the instructions in the block.<br>
>> - for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {<br>
>> - InstrIdx[it] = Loc++;<br>
>> - InstrVec.push_back(it);<br>
>> - assert(InstrVec[InstrIdx[it]] == it && "Invalid allocation");<br>
>> - }<br>
>> - Valid = true;<br>
>> - }<br>
>> -<br>
>> - int getIndex(Instruction *I) {<br>
>> - assert(I->getParent() == BB && "Invalid instruction");<br>
>> - if (!Valid)<br>
>> - numberInstructions();<br>
>> - assert(InstrIdx.count(I) && "Unknown instruction");<br>
>> - return InstrIdx[I];<br>
>> - }<br>
>> -<br>
>> - Instruction *getInstruction(unsigned loc) {<br>
>> - if (!Valid)<br>
>> - numberInstructions();<br>
>> - assert(InstrVec.size() > loc && "Invalid Index");<br>
>> - return InstrVec[loc];<br>
>> - }<br>
>> -<br>
>> - void forget() { Valid = false; }<br>
>> -<br>
>> -private:<br>
>> - /// The block we are numbering.<br>
>> - BasicBlock *BB;<br>
>> - /// Is the block numbered.<br>
>> - bool Valid;<br>
>> - /// Maps instructions to numbers and back.<br>
>> - SmallDenseMap<Instruction *, int> InstrIdx;<br>
>> - /// Maps integers to Instructions.<br>
>> - SmallVector<Instruction *, 32> InstrVec;<br>
>> -};<br>
>> -<br>
>> /// \returns the parent basic block if all of the instructions in \p VL<br>
>> /// are in the same block or null otherwise.<br>
>> static BasicBlock *getSameBlock(ArrayRef<Value *> VL) {<br>
>> @@ -422,9 +376,12 @@ public:<br>
>> ScalarToTreeEntry.clear();<br>
>> MustGather.clear();<br>
>> ExternalUses.clear();<br>
>> - MemBarrierIgnoreList.clear();<br>
>> NumLoadsWantToKeepOrder = 0;<br>
>> NumLoadsWantToChangeOrder = 0;<br>
>> + for (auto &Iter : BlocksSchedules) {<br>
>> + BlockScheduling *BS = Iter.second.get();<br>
>> + BS->clear();<br>
>> + }<br>
>> }<br>
>><br>
>> /// \returns true if the memory operations A and B are consecutive.<br>
>> @@ -474,20 +431,6 @@ private:<br>
>> /// roots. This method calculates the cost of extracting the values.<br>
>> int getGatherCost(ArrayRef<Value *> VL);<br>
>><br>
>> - /// \returns the AA location that is being access by the instruction.<br>
>> - AliasAnalysis::Location getLocation(Instruction *I);<br>
>> -<br>
>> - /// \brief Checks if it is possible to sink an instruction from<br>
>> - /// \p Src to \p Dst.<br>
>> - /// \returns the pointer to the barrier instruction if we can't sink.<br>
>> - Value *getSinkBarrier(Instruction *Src, Instruction *Dst);<br>
>> -<br>
>> - /// \returns the index of the last instruction in the BB from \p VL.<br>
>> - int getLastIndex(ArrayRef<Value *> VL);<br>
>> -<br>
>> - /// \returns the Instruction in the bundle \p VL.<br>
>> - Instruction *getLastInstruction(ArrayRef<Value *> VL);<br>
>> -<br>
>> /// \brief Set the Builder insert point to one after the last instruction in<br>
>> /// the bundle<br>
>> void setInsertPointAfterBundle(ArrayRef<Value *> VL);<br>
>> @@ -500,7 +443,7 @@ private:<br>
>> bool isFullyVectorizableTinyTree();<br>
>><br>
>> struct TreeEntry {<br>
>> - TreeEntry() : Scalars(), VectorizedValue(nullptr), LastScalarIndex(0),<br>
>> + TreeEntry() : Scalars(), VectorizedValue(nullptr),<br>
>> NeedToGather(0) {}<br>
>><br>
>> /// \returns true if the scalars in VL are equal to this entry.<br>
>> @@ -515,9 +458,6 @@ private:<br>
>> /// The Scalars are vectorized into this value. It is initialized to Null.<br>
>> Value *VectorizedValue;<br>
>><br>
>> - /// The index in the basic block of the last scalar.<br>
>> - int LastScalarIndex;<br>
>> -<br>
>> /// Do we need to gather this sequence ?<br>
>> bool NeedToGather;<br>
>> };<br>
>> @@ -530,18 +470,16 @@ private:<br>
>> Last->Scalars.insert(Last->Scalars.begin(), VL.begin(), VL.end());<br>
>> Last->NeedToGather = !Vectorized;<br>
>> if (Vectorized) {<br>
>> - Last->LastScalarIndex = getLastIndex(VL);<br>
>> for (int i = 0, e = VL.size(); i != e; ++i) {<br>
>> assert(!ScalarToTreeEntry.count(VL[i]) && "Scalar already in tree!");<br>
>> ScalarToTreeEntry[VL[i]] = idx;<br>
>> }<br>
>> } else {<br>
>> - Last->LastScalarIndex = 0;<br>
>> MustGather.insert(VL.begin(), VL.end());<br>
>> }<br>
>> return Last;<br>
>> }<br>
>> -<br>
>> +<br>
>> /// -- Vectorization State --<br>
>> /// Holds all of the tree entries.<br>
>> std::vector<TreeEntry> VectorizableTree;<br>
>> @@ -569,24 +507,304 @@ private:<br>
>> /// This list holds pairs of (Internal Scalar : External User).<br>
>> UserList ExternalUses;<br>
>><br>
>> - /// A list of instructions to ignore while sinking<br>
>> - /// memory instructions. This map must be reset between runs of getCost.<br>
>> - ValueSet MemBarrierIgnoreList;<br>
>> -<br>
>> /// Holds all of the instructions that we gathered.<br>
>> SetVector<Instruction *> GatherSeq;<br>
>> /// A list of blocks that we are going to CSE.<br>
>> SetVector<BasicBlock *> CSEBlocks;<br>
>><br>
>> - /// Numbers instructions in different blocks.<br>
>> - DenseMap<BasicBlock *, BlockNumbering> BlocksNumbers;<br>
>> + /// Contains all scheduling relevant data for an instruction.<br>
>> + /// A ScheduleData either represents a single instruction or a member of an<br>
>> + /// instruction bundle (= a group of instructions which is combined into a<br>
>> + /// vector instruction).<br>
>> + struct ScheduleData {<br>
>> +<br>
>> + // The initial value for the dependency counters. It means that the<br>
>> + // dependencies are not calculated yet.<br>
>> + enum { InvalidDeps = -1 };<br>
>> +<br>
>> + ScheduleData()<br>
>> + : Inst(nullptr), FirstInBundle(nullptr), NextInBundle(nullptr),<br>
>> + NextLoadStore(nullptr), SchedulingRegionID(0), SchedulingPriority(0),<br>
>> + Dependencies(InvalidDeps), UnscheduledDeps(InvalidDeps),<br>
>> + UnscheduledDepsInBundle(InvalidDeps), IsScheduled(false) {}<br>
>> +<br>
>> + void init(int BlockSchedulingRegionID) {<br>
>> + FirstInBundle = this;<br>
>> + NextInBundle = nullptr;<br>
>> + NextLoadStore = nullptr;<br>
>> + IsScheduled = false;<br>
>> + SchedulingRegionID = BlockSchedulingRegionID;<br>
>> + UnscheduledDepsInBundle = UnscheduledDeps;<br>
>> + clearDependencies();<br>
>> + }<br>
>> +<br>
>> + /// Returns true if the dependency information has been calculated.<br>
>> + bool hasValidDependencies() const { return Dependencies != InvalidDeps; }<br>
>> +<br>
>> + /// Returns true for single instructions and for bundle representatives<br>
>> + /// (= the head of a bundle).<br>
>> + bool isSchedulingEntity() const { return FirstInBundle == this; }<br>
>> +<br>
>> + /// Returns true if it represents an instruction bundle and not only a<br>
>> + /// single instruction.<br>
>> + bool isPartOfBundle() const {<br>
>> + return NextInBundle != nullptr || FirstInBundle != this;<br>
>> + }<br>
>> +<br>
>> + /// Returns true if it is ready for scheduling, i.e. it has no more<br>
>> + /// unscheduled depending instructions/bundles.<br>
>> + bool isReady() const {<br>
>> + assert(isSchedulingEntity() &&<br>
>> + "can't consider non-scheduling entity for ready list");<br>
>> + return UnscheduledDepsInBundle == 0 && !IsScheduled;<br>
>> + }<br>
>> +<br>
>> + /// Modifies the number of unscheduled dependencies, also updating it for<br>
>> + /// the whole bundle.<br>
>> + int incrementUnscheduledDeps(int Incr) {<br>
>> + UnscheduledDeps += Incr;<br>
>> + return FirstInBundle->UnscheduledDepsInBundle += Incr;<br>
>> + }<br>
>> +<br>
>> + /// Sets the number of unscheduled dependencies to the number of<br>
>> + /// dependencies.<br>
>> + void resetUnscheduledDeps() {<br>
>> + incrementUnscheduledDeps(Dependencies - UnscheduledDeps);<br>
>> + }<br>
>> +<br>
>> + /// Clears all dependency information.<br>
>> + void clearDependencies() {<br>
>> + Dependencies = InvalidDeps;<br>
>> + resetUnscheduledDeps();<br>
>> + MemoryDependencies.clear();<br>
>> + }<br>
>> +<br>
>> + void dump(raw_ostream &os) const {<br>
>> + if (!isSchedulingEntity()) {<br>
>> + os << "/ " << *Inst;<br>
>> + } else if (NextInBundle) {<br>
>> + os << '[' << *Inst;<br>
>> + ScheduleData *SD = NextInBundle;<br>
>> + while (SD) {<br>
>> + os << ';' << *SD->Inst;<br>
>> + SD = SD->NextInBundle;<br>
>> + }<br>
>> + os << ']';<br>
>> + } else {<br>
>> + os << *Inst;<br>
>> + }<br>
>> + }<br>
>><br>
>> - /// \brief Get the corresponding instruction numbering list for a given<br>
>> - /// BasicBlock. The list is allocated lazily.<br>
>> - BlockNumbering &getBlockNumbering(BasicBlock *BB) {<br>
>> - auto I = BlocksNumbers.insert(std::make_pair(BB, BlockNumbering(BB)));<br>
>> - return I.first->second;<br>
>> - }<br>
>> + Instruction *Inst;<br>
>> +<br>
>> + /// Points to the head in an instruction bundle (and always to this for<br>
>> + /// single instructions).<br>
>> + ScheduleData *FirstInBundle;<br>
>> +<br>
>> + /// Single linked list of all instructions in a bundle. Null if it is a<br>
>> + /// single instruction.<br>
>> + ScheduleData *NextInBundle;<br>
>> +<br>
>> + /// Single linked list of all memory instructions (e.g. load, store, call)<br>
>> + /// in the block - until the end of the scheduling region.<br>
>> + ScheduleData *NextLoadStore;<br>
>> +<br>
>> + /// The dependent memory instructions.<br>
>> + /// This list is derived on demand in calculateDependencies().<br>
>> + SmallVector<ScheduleData *, 4> MemoryDependencies;<br>
>> +<br>
>> + /// This ScheduleData is in the current scheduling region if this matches<br>
>> + /// the current SchedulingRegionID of BlockScheduling.<br>
>> + int SchedulingRegionID;<br>
>> +<br>
>> + /// Used for getting a "good" final ordering of instructions.<br>
>> + int SchedulingPriority;<br>
>> +<br>
>> + /// The number of dependencies. Constitutes of the number of users of the<br>
>> + /// instruction plus the number of dependent memory instructions (if any).<br>
>> + /// This value is calculated on demand.<br>
>> + /// If InvalidDeps, the number of dependencies is not calculated yet.<br>
>> + ///<br>
>> + int Dependencies;<br>
>> +<br>
>> + /// The number of dependencies minus the number of dependencies of scheduled<br>
>> + /// instructions. As soon as this is zero, the instruction/bundle gets ready<br>
>> + /// for scheduling.<br>
>> + /// Note that this is negative as long as Dependencies is not calculated.<br>
>> + int UnscheduledDeps;<br>
>> +<br>
>> + /// The sum of UnscheduledDeps in a bundle. Equals to UnscheduledDeps for<br>
>> + /// single instructions.<br>
>> + int UnscheduledDepsInBundle;<br>
>> +<br>
>> + /// True if this instruction is scheduled (or considered as scheduled in the<br>
>> + /// dry-run).<br>
>> + bool IsScheduled;<br>
>> + };<br>
>> +<br>
>> + friend raw_ostream &operator<<(raw_ostream &os,<br>
>> + const BoUpSLP::ScheduleData &SD);<br>
>> +<br>
>> + /// Contains all scheduling data for a basic block.<br>
>> + ///<br>
>> + struct BlockScheduling {<br>
>> +<br>
>> + BlockScheduling(BasicBlock *BB)<br>
>> + : BB(BB), ChunkSize(BB->size()), ChunkPos(ChunkSize),<br>
>> + ScheduleStart(nullptr), ScheduleEnd(nullptr),<br>
>> + FirstLoadStoreInRegion(nullptr), LastLoadStoreInRegion(nullptr),<br>
>> + // Make sure that the initial SchedulingRegionID is greater than the<br>
>> + // initial SchedulingRegionID in ScheduleData (which is 0).<br>
>> + SchedulingRegionID(1) {}<br>
>> +<br>
>> + void clear() {<br>
>> + ReadyInsts.clear();<br>
>> + ScheduleStart = nullptr;<br>
>> + ScheduleEnd = nullptr;<br>
>> + FirstLoadStoreInRegion = nullptr;<br>
>> + LastLoadStoreInRegion = nullptr;<br>
>> +<br>
>> + // Make a new scheduling region, i.e. all existing ScheduleData is not<br>
>> + // in the new region yet.<br>
>> + ++SchedulingRegionID;<br>
>> + }<br>
>> +<br>
>> + ScheduleData *getScheduleData(Value *V) {<br>
>> + ScheduleData *SD = ScheduleDataMap[V];<br>
>> + if (SD && SD->SchedulingRegionID == SchedulingRegionID)<br>
>> + return SD;<br>
>> + return nullptr;<br>
>> + }<br>
>> +<br>
>> + bool isInSchedulingRegion(ScheduleData *SD) {<br>
>> + return SD->SchedulingRegionID == SchedulingRegionID;<br>
>> + }<br>
>> +<br>
>> + /// Marks an instruction as scheduled and puts all dependent ready<br>
>> + /// instructions into the ready-list.<br>
>> + template <typename ReadyListType><br>
>> + void schedule(ScheduleData *SD, ReadyListType &ReadyList) {<br>
>> + SD->IsScheduled = true;<br>
>> + DEBUG(dbgs() << "SLP: schedule " << *SD << "\n");<br>
>> +<br>
>> + ScheduleData *BundleMember = SD;<br>
>> + while (BundleMember) {<br>
>> + // Handle the def-use chain dependencies.<br>
>> + for (Use &U : BundleMember->Inst->operands()) {<br>
>> + ScheduleData *OpDef = getScheduleData(U.get());<br>
>> + if (OpDef && OpDef->hasValidDependencies() &&<br>
>> + OpDef->incrementUnscheduledDeps(-1) == 0) {<br>
>> + // There are no more unscheduled dependencies after decrementing,<br>
>> + // so we can put the dependent instruction into the ready list.<br>
>> + ScheduleData *DepBundle = OpDef->FirstInBundle;<br>
>> + assert(!DepBundle->IsScheduled &&<br>
>> + "already scheduled bundle gets ready");<br>
>> + ReadyList.insert(DepBundle);<br>
>> + DEBUG(dbgs() << "SLP: gets ready (def): " << *DepBundle << "\n");<br>
>> + }<br>
>> + }<br>
>> + // Handle the memory dependencies.<br>
>> + for (ScheduleData *MemoryDepSD : BundleMember->MemoryDependencies) {<br>
>> + if (MemoryDepSD->incrementUnscheduledDeps(-1) == 0) {<br>
>> + // There are no more unscheduled dependencies after decrementing,<br>
>> + // so we can put the dependent instruction into the ready list.<br>
>> + ScheduleData *DepBundle = MemoryDepSD->FirstInBundle;<br>
>> + assert(!DepBundle->IsScheduled &&<br>
>> + "already scheduled bundle gets ready");<br>
>> + ReadyList.insert(DepBundle);<br>
>> + DEBUG(dbgs() << "SLP: gets ready (mem): " << *DepBundle << "\n");<br>
>> + }<br>
>> + }<br>
>> + BundleMember = BundleMember->NextInBundle;<br>
>> + }<br>
>> + }<br>
>> +<br>
>> + /// Put all instructions into the ReadyList which are ready for scheduling.<br>
>> + template <typename ReadyListType><br>
>> + void initialFillReadyList(ReadyListType &ReadyList) {<br>
>> + for (auto *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode()) {<br>
>> + ScheduleData *SD = getScheduleData(I);<br>
>> + if (SD->isSchedulingEntity() && SD->isReady()) {<br>
>> + ReadyList.insert(SD);<br>
>> + DEBUG(dbgs() << "SLP: initially in ready list: " << *I << "\n");<br>
>> + }<br>
>> + }<br>
>> + }<br>
>> +<br>
>> + /// Checks if a bundle of instructions can be scheduled, i.e. has no<br>
>> + /// cyclic dependencies. This is only a dry-run, no instructions are<br>
>> + /// actually moved at this stage.<br>
>> + bool tryScheduleBundle(ArrayRef<Value *> VL, AliasAnalysis *AA);<br>
>> +<br>
>> + /// Un-bundles a group of instructions.<br>
>> + void cancelScheduling(ArrayRef<Value *> VL);<br>
>> +<br>
>> + /// Extends the scheduling region so that V is inside the region.<br>
>> + void extendSchedulingRegion(Value *V);<br>
>> +<br>
>> + /// Initialize the ScheduleData structures for new instructions in the<br>
>> + /// scheduling region.<br>
>> + void initScheduleData(Instruction *FromI, Instruction *ToI,<br>
>> + ScheduleData *PrevLoadStore,<br>
>> + ScheduleData *NextLoadStore);<br>
>> +<br>
>> + /// Updates the dependency information of a bundle and of all instructions/<br>
>> + /// bundles which depend on the original bundle.<br>
>> + void calculateDependencies(ScheduleData *SD, bool InsertInReadyList,<br>
>> + AliasAnalysis *AA);<br>
>> +<br>
>> + /// Sets all instruction in the scheduling region to un-scheduled.<br>
>> + void resetSchedule();<br>
>> +<br>
>> + BasicBlock *BB;<br>
>> +<br>
>> + /// Simple memory allocation for ScheduleData.<br>
>> + std::vector<std::unique_ptr<ScheduleData[]>> ScheduleDataChunks;<br>
>> +<br>
>> + /// The size of a ScheduleData array in ScheduleDataChunks.<br>
>> + int ChunkSize;<br>
>> +<br>
>> + /// The allocator position in the current chunk, which is the last entry<br>
>> + /// of ScheduleDataChunks.<br>
>> + int ChunkPos;<br>
>> +<br>
>> + /// Attaches ScheduleData to Instruction.<br>
>> + /// Note that the mapping survives during all vectorization iterations, i.e.<br>
>> + /// ScheduleData structures are recycled.<br>
>> + DenseMap<Value *, ScheduleData *> ScheduleDataMap;<br>
>> +<br>
>> + struct ReadyList : SmallVector<ScheduleData *, 8> {<br>
>> + void insert(ScheduleData *SD) { push_back(SD); }<br>
>> + };<br>
>> +<br>
>> + /// The ready-list for scheduling (only used for the dry-run).<br>
>> + ReadyList ReadyInsts;<br>
>> +<br>
>> + /// The first instruction of the scheduling region.<br>
>> + Instruction *ScheduleStart;<br>
>> +<br>
>> + /// The first instruction _after_ the scheduling region.<br>
>> + Instruction *ScheduleEnd;<br>
>> +<br>
>> + /// The first memory accessing instruction in the scheduling region<br>
>> + /// (can be null).<br>
>> + ScheduleData *FirstLoadStoreInRegion;<br>
>> +<br>
>> + /// The last memory accessing instruction in the scheduling region<br>
>> + /// (can be null).<br>
>> + ScheduleData *LastLoadStoreInRegion;<br>
>> +<br>
>> + /// The ID of the scheduling region. For a new vectorization iteration this<br>
>> + /// is incremented which "removes" all ScheduleData from the region.<br>
>> + int SchedulingRegionID;<br>
>> + };<br>
>> +<br>
>> + /// Attaches the BlockScheduling structures to basic blocks.<br>
>> + DenseMap<BasicBlock *, std::unique_ptr<BlockScheduling>> BlocksSchedules;<br>
>> +<br>
>> + /// Performs the "real" scheduling. Done before vectorization is actually<br>
>> + /// performed in a basic block.<br>
>> + void scheduleBlock(BasicBlock *BB);<br>
>><br>
>> /// List of users to ignore during scheduling and that don't need extracting.<br>
>> ArrayRef<Value *> UserIgnoreList;<br>
>> @@ -609,6 +827,11 @@ private:<br>
>> /// Instruction builder to construct the vectorized tree.<br>
>> IRBuilder<> Builder;<br>
>> };<br>
>> +<br>
>> +raw_ostream &operator<<(raw_ostream &os, const BoUpSLP::ScheduleData &SD) {<br>
>> + SD.dump(os);<br>
>> + return os;<br>
>> +}<br>
>><br>
>> void BoUpSLP::buildTree(ArrayRef<Value *> Roots,<br>
>> ArrayRef<Value *> UserIgnoreLst) {<br>
>> @@ -743,69 +966,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> // Check that all of the users of the scalars that we want to vectorize are<br>
>> // schedulable.<br>
>> Instruction *VL0 = cast<Instruction>(VL[0]);<br>
>> - int MyLastIndex = getLastIndex(VL);<br>
>> BasicBlock *BB = cast<Instruction>(VL0)->getParent();<br>
>><br>
>> - for (unsigned i = 0, e = VL.size(); i != e; ++i) {<br>
>> - Instruction *Scalar = cast<Instruction>(VL[i]);<br>
>> - DEBUG(dbgs() << "SLP: Checking users of " << *Scalar << ". \n");<br>
>> - for (User *U : Scalar->users()) {<br>
>> - DEBUG(dbgs() << "SLP: \tUser " << *U << ". \n");<br>
>> - Instruction *UI = dyn_cast<Instruction>(U);<br>
>> - if (!UI) {<br>
>> - DEBUG(dbgs() << "SLP: Gathering due unknown user. \n");<br>
>> - newTreeEntry(VL, false);<br>
>> - return;<br>
>> - }<br>
>> -<br>
>> - // We don't care if the user is in a different basic block.<br>
>> - BasicBlock *UserBlock = UI->getParent();<br>
>> - if (UserBlock != BB) {<br>
>> - DEBUG(dbgs() << "SLP: User from a different basic block "<br>
>> - << *UI << ". \n");<br>
>> - continue;<br>
>> - }<br>
>> -<br>
>> - // If this is a PHINode within this basic block then we can place the<br>
>> - // extract wherever we want.<br>
>> - if (isa<PHINode>(*UI)) {<br>
>> - DEBUG(dbgs() << "SLP: \tWe can schedule PHIs:" << *UI << ". \n");<br>
>> - continue;<br>
>> - }<br>
>> -<br>
>> - // Check if this is a safe in-tree user.<br>
>> - if (ScalarToTreeEntry.count(UI)) {<br>
>> - int Idx = ScalarToTreeEntry[UI];<br>
>> - int VecLocation = VectorizableTree[Idx].LastScalarIndex;<br>
>> - if (VecLocation <= MyLastIndex) {<br>
>> - DEBUG(dbgs() << "SLP: Gathering due to unschedulable vector. \n");<br>
>> - newTreeEntry(VL, false);<br>
>> - return;<br>
>> - }<br>
>> - DEBUG(dbgs() << "SLP: In-tree user (" << *UI << ") at #" <<<br>
>> - VecLocation << " vector value (" << *Scalar << ") at #"<br>
>> - << MyLastIndex << ".\n");<br>
>> - continue;<br>
>> - }<br>
>> -<br>
>> - // Ignore users in the user ignore list.<br>
>> - if (std::find(UserIgnoreList.begin(), UserIgnoreList.end(), UI) !=<br>
>> - UserIgnoreList.end())<br>
>> - continue;<br>
>> -<br>
>> - // Make sure that we can schedule this unknown user.<br>
>> - BlockNumbering &BN = getBlockNumbering(BB);<br>
>> - int UserIndex = BN.getIndex(UI);<br>
>> - if (UserIndex < MyLastIndex) {<br>
>> -<br>
>> - DEBUG(dbgs() << "SLP: Can't schedule extractelement for "<br>
>> - << *UI << ". \n");<br>
>> - newTreeEntry(VL, false);<br>
>> - return;<br>
>> - }<br>
>> - }<br>
>> - }<br>
>> -<br>
>> // Check that every instructions appears once in this bundle.<br>
>> for (unsigned i = 0, e = VL.size(); i < e; ++i)<br>
>> for (unsigned j = i+1; j < e; ++j)<br>
>> @@ -815,39 +977,20 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> return;<br>
>> }<br>
>><br>
>> - // Check that instructions in this bundle don't reference other instructions.<br>
>> - // The runtime of this check is O(N * N-1 * uses(N)) and a typical N is 4.<br>
>> - for (unsigned i = 0, e = VL.size(); i < e; ++i) {<br>
>> - for (User *U : VL[i]->users()) {<br>
>> - for (unsigned j = 0; j < e; ++j) {<br>
>> - if (i != j && U == VL[j]) {<br>
>> - DEBUG(dbgs() << "SLP: Intra-bundle dependencies!" << *U << ". \n");<br>
>> - newTreeEntry(VL, false);<br>
>> - return;<br>
>> - }<br>
>> - }<br>
>> - }<br>
>> + auto &BSRef = BlocksSchedules[BB];<br>
>> + if (!BSRef) {<br>
>> + BSRef = llvm::make_unique<BlockScheduling>(BB);<br>
>> + }<br>
>> + BlockScheduling &BS = *BSRef.get();<br>
>> +<br>
>> + if (!BS.tryScheduleBundle(VL, AA)) {<br>
>> + DEBUG(dbgs() << "SLP: We are not able to schedule this bundle!\n");<br>
>> + BS.cancelScheduling(VL);<br>
>> + newTreeEntry(VL, false);<br>
>> + return;<br>
>> }<br>
>> -<br>
>> DEBUG(dbgs() << "SLP: We are able to schedule this bundle.\n");<br>
>><br>
>> - // Check if it is safe to sink the loads or the stores.<br>
>> - if (Opcode == Instruction::Load || Opcode == Instruction::Store) {<br>
>> - Instruction *Last = getLastInstruction(VL);<br>
>> -<br>
>> - for (unsigned i = 0, e = VL.size(); i < e; ++i) {<br>
>> - if (VL[i] == Last)<br>
>> - continue;<br>
>> - Value *Barrier = getSinkBarrier(cast<Instruction>(VL[i]), Last);<br>
>> - if (Barrier) {<br>
>> - DEBUG(dbgs() << "SLP: Can't sink " << *VL[i] << "\n down to " << *Last<br>
>> - << "\n because of " << *Barrier << ". Gathering.\n");<br>
>> - newTreeEntry(VL, false);<br>
>> - return;<br>
>> - }<br>
>> - }<br>
>> - }<br>
>> -<br>
>> switch (Opcode) {<br>
>> case Instruction::PHI: {<br>
>> PHINode *PH = dyn_cast<PHINode>(VL0);<br>
>> @@ -859,6 +1002,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> cast<PHINode>(VL[j])->getIncomingValueForBlock(PH->getIncomingBlock(i)));<br>
>> if (Term) {<br>
>> DEBUG(dbgs() << "SLP: Need to swizzle PHINodes (TerminatorInst use).\n");<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> return;<br>
>> }<br>
>> @@ -882,6 +1026,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> bool Reuse = CanReuseExtract(VL);<br>
>> if (Reuse) {<br>
>> DEBUG(dbgs() << "SLP: Reusing extract sequence.\n");<br>
>> + } else {<br>
>> + BS.cancelScheduling(VL);<br>
>> }<br>
>> newTreeEntry(VL, Reuse);<br>
>> return;<br>
>> @@ -891,6 +1037,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> for (unsigned i = 0, e = VL.size() - 1; i < e; ++i) {<br>
>> LoadInst *L = cast<LoadInst>(VL[i]);<br>
>> if (!L->isSimple()) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Gathering non-simple loads.\n");<br>
>> return;<br>
>> @@ -899,6 +1046,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> if (VL.size() == 2 && isConsecutiveAccess(VL[1], VL[0])) {<br>
>> ++NumLoadsWantToChangeOrder;<br>
>> }<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Gathering non-consecutive loads.\n");<br>
>> return;<br>
>> @@ -925,6 +1073,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> for (unsigned i = 0; i < VL.size(); ++i) {<br>
>> Type *Ty = cast<Instruction>(VL[i])->getOperand(0)->getType();<br>
>> if (Ty != SrcTy || Ty->isAggregateType() || Ty->isVectorTy()) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Gathering casts with different src types.\n");<br>
>> return;<br>
>> @@ -952,6 +1101,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> CmpInst *Cmp = cast<CmpInst>(VL[i]);<br>
>> if (Cmp->getPredicate() != P0 ||<br>
>> Cmp->getOperand(0)->getType() != ComparedTy) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Gathering cmp with different predicate.\n");<br>
>> return;<br>
>> @@ -998,20 +1148,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> if (isa<BinaryOperator>(VL0) && VL0->isCommutative()) {<br>
>> ValueList Left, Right;<br>
>> reorderInputsAccordingToOpcode(VL, Left, Right);<br>
>> - BasicBlock *LeftBB = getSameBlock(Left);<br>
>> - BasicBlock *RightBB = getSameBlock(Right);<br>
>> - // If we have common uses on separate paths in the tree make sure we<br>
>> - // process the one with greater common depth first.<br>
>> - // We can use block numbering to determine the subtree traversal as<br>
>> - // earler user has to come in between the common use and the later user.<br>
>> - if (LeftBB && RightBB && LeftBB == RightBB &&<br>
>> - getLastIndex(Right) > getLastIndex(Left)) {<br>
>> - buildTree_rec(Right, Depth + 1);<br>
>> - buildTree_rec(Left, Depth + 1);<br>
>> - } else {<br>
>> - buildTree_rec(Left, Depth + 1);<br>
>> - buildTree_rec(Right, Depth + 1);<br>
>> - }<br>
>> + buildTree_rec(Left, Depth + 1);<br>
>> + buildTree_rec(Right, Depth + 1);<br>
>> return;<br>
>> }<br>
>><br>
>> @@ -1030,6 +1168,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> for (unsigned j = 0; j < VL.size(); ++j) {<br>
>> if (cast<Instruction>(VL[j])->getNumOperands() != 2) {<br>
>> DEBUG(dbgs() << "SLP: not-vectorizable GEP (nested indexes).\n");<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> return;<br>
>> }<br>
>> @@ -1042,6 +1181,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> Type *CurTy = cast<Instruction>(VL[j])->getOperand(0)->getType();<br>
>> if (Ty0 != CurTy) {<br>
>> DEBUG(dbgs() << "SLP: not-vectorizable GEP (different types).\n");<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> return;<br>
>> }<br>
>> @@ -1053,6 +1193,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> if (!isa<ConstantInt>(Op)) {<br>
>> DEBUG(<br>
>> dbgs() << "SLP: not-vectorizable GEP (non-constant indexes).\n");<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> return;<br>
>> }<br>
>> @@ -1074,6 +1215,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> // Check if the stores are consecutive or of we need to swizzle them.<br>
>> for (unsigned i = 0, e = VL.size() - 1; i < e; ++i)<br>
>> if (!isConsecutiveAccess(VL[i], VL[i + 1])) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Non-consecutive store.\n");<br>
>> return;<br>
>> @@ -1086,8 +1228,6 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> for (unsigned j = 0; j < VL.size(); ++j)<br>
>> Operands.push_back(cast<Instruction>(VL[j])->getOperand(0));<br>
>><br>
>> - // We can ignore these values because we are sinking them down.<br>
>> - MemBarrierIgnoreList.insert(VL.begin(), VL.end());<br>
>> buildTree_rec(Operands, Depth + 1);<br>
>> return;<br>
>> }<br>
>> @@ -1098,6 +1238,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> // represented by an intrinsic call<br>
>> Intrinsic::ID ID = getIntrinsicIDForCall(CI, TLI);<br>
>> if (!isTriviallyVectorizable(ID)) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Non-vectorizable call.\n");<br>
>> return;<br>
>> @@ -1110,6 +1251,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> CallInst *CI2 = dyn_cast<CallInst>(VL[i]);<br>
>> if (!CI2 || CI2->getCalledFunction() != Int ||<br>
>> getIntrinsicIDForCall(CI2, TLI) != ID) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: mismatched calls:" << *CI << "!=" << *VL[i]<br>
>> << "\n");<br>
>> @@ -1120,6 +1262,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> if (hasVectorInstrinsicScalarOpd(ID, 1)) {<br>
>> Value *A1J = CI2->getArgOperand(1);<br>
>> if (A1I != A1J) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: mismatched arguments in call:" << *CI<br>
>> << " argument "<< A1I<<"!=" << A1J<br>
>> @@ -1145,6 +1288,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> // If this is not an alternate sequence of opcode like add-sub<br>
>> // then do not vectorize this instruction.<br>
>> if (!isAltShuffle) {<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: ShuffleVector are not vectorized.\n");<br>
>> return;<br>
>> @@ -1162,6 +1306,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
>> return;<br>
>> }<br>
>> default:<br>
>> + BS.cancelScheduling(VL);<br>
>> newTreeEntry(VL, false);<br>
>> DEBUG(dbgs() << "SLP: Gathering unknown instruction.\n");<br>
>> return;<br>
>> @@ -1450,14 +1595,6 @@ int BoUpSLP::getGatherCost(ArrayRef<Valu<br>
>> return getGatherCost(VecTy);<br>
>> }<br>
>><br>
>> -AliasAnalysis::Location BoUpSLP::getLocation(Instruction *I) {<br>
>> - if (StoreInst *SI = dyn_cast<StoreInst>(I))<br>
>> - return AA->getLocation(SI);<br>
>> - if (LoadInst *LI = dyn_cast<LoadInst>(I))<br>
>> - return AA->getLocation(LI);<br>
>> - return AliasAnalysis::Location();<br>
>> -}<br>
>> -<br>
>> Value *BoUpSLP::getPointerOperand(Value *I) {<br>
>> if (LoadInst *LI = dyn_cast<LoadInst>(I))<br>
>> return LI->getPointerOperand();<br>
>> @@ -1515,59 +1652,9 @@ bool BoUpSLP::isConsecutiveAccess(Value<br>
>> return X == PtrSCEVB;<br>
>> }<br>
>><br>
>> -Value *BoUpSLP::getSinkBarrier(Instruction *Src, Instruction *Dst) {<br>
>> - assert(Src->getParent() == Dst->getParent() && "Not the same BB");<br>
>> - BasicBlock::iterator I = Src, E = Dst;<br>
>> - /// Scan all of the instruction from SRC to DST and check if<br>
>> - /// the source may alias.<br>
>> - for (++I; I != E; ++I) {<br>
>> - // Ignore store instructions that are marked as 'ignore'.<br>
>> - if (MemBarrierIgnoreList.count(I))<br>
>> - continue;<br>
>> - if (Src->mayWriteToMemory()) /* Write */ {<br>
>> - if (!I->mayReadOrWriteMemory())<br>
>> - continue;<br>
>> - } else /* Read */ {<br>
>> - if (!I->mayWriteToMemory())<br>
>> - continue;<br>
>> - }<br>
>> - AliasAnalysis::Location A = getLocation(&*I);<br>
>> - AliasAnalysis::Location B = getLocation(Src);<br>
>> -<br>
>> - if (!A.Ptr || !B.Ptr || AA->alias(A, B))<br>
>> - return I;<br>
>> - }<br>
>> - return nullptr;<br>
>> -}<br>
>> -<br>
>> -int BoUpSLP::getLastIndex(ArrayRef<Value *> VL) {<br>
>> - BasicBlock *BB = cast<Instruction>(VL[0])->getParent();<br>
>> - assert(BB == getSameBlock(VL) && "Invalid block");<br>
>> - BlockNumbering &BN = getBlockNumbering(BB);<br>
>> -<br>
>> - int MaxIdx = BN.getIndex(BB->getFirstNonPHI());<br>
>> - for (unsigned i = 0, e = VL.size(); i < e; ++i)<br>
>> - MaxIdx = std::max(MaxIdx, BN.getIndex(cast<Instruction>(VL[i])));<br>
>> - return MaxIdx;<br>
>> -}<br>
>> -<br>
>> -Instruction *BoUpSLP::getLastInstruction(ArrayRef<Value *> VL) {<br>
>> - BasicBlock *BB = cast<Instruction>(VL[0])->getParent();<br>
>> - assert(BB == getSameBlock(VL) && "Invalid block");<br>
>> - BlockNumbering &BN = getBlockNumbering(BB);<br>
>> -<br>
>> - int MaxIdx = BN.getIndex(cast<Instruction>(VL[0]));<br>
>> - for (unsigned i = 1, e = VL.size(); i < e; ++i)<br>
>> - MaxIdx = std::max(MaxIdx, BN.getIndex(cast<Instruction>(VL[i])));<br>
>> - Instruction *I = BN.getInstruction(MaxIdx);<br>
>> - assert(I && "bad location");<br>
>> - return I;<br>
>> -}<br>
>> -<br>
>> void BoUpSLP::setInsertPointAfterBundle(ArrayRef<Value *> VL) {<br>
>> Instruction *VL0 = cast<Instruction>(VL[0]);<br>
>> - Instruction *LastInst = getLastInstruction(VL);<br>
>> - BasicBlock::iterator NextInst = LastInst;<br>
>> + BasicBlock::iterator NextInst = VL0;<br>
>> ++NextInst;<br>
>> Builder.SetInsertPoint(VL0->getParent(), NextInst);<br>
>> Builder.SetCurrentDebugLocation(VL0->getDebugLoc());<br>
>> @@ -1650,6 +1737,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
>> setInsertPointAfterBundle(E->Scalars);<br>
>> return Gather(E->Scalars, VecTy);<br>
>> }<br>
>> + BasicBlock *BB = VL0->getParent();<br>
>> + scheduleBlock(BB);<br>
>> +<br>
>> unsigned Opcode = getSameOpcode(E->Scalars);<br>
>><br>
>> switch (Opcode) {<br>
>> @@ -2070,9 +2160,6 @@ Value *BoUpSLP::vectorizeTree() {<br>
>> }<br>
>> }<br>
>><br>
>> - for (auto &BN : BlocksNumbers)<br>
>> - BN.second.forget();<br>
>> -<br>
>> Builder.ClearInsertionPoint();<br>
>><br>
>> return VectorizableTree[0].VectorizedValue;<br>
>> @@ -2166,6 +2253,363 @@ void BoUpSLP::optimizeGatherSequence() {<br>
>> GatherSeq.clear();<br>
>> }<br>
>><br>
>> +// Groups the instructions to a bundle (which is then a single scheduling entity)<br>
>> +// and schedules instructions until the bundle gets ready.<br>
>> +bool BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL,<br>
>> + AliasAnalysis *AA) {<br>
>> + if (isa<PHINode>(VL[0]))<br>
>> + return true;<br>
>> +<br>
>> + // Initialize the instruction bundle.<br>
>> + Instruction *OldScheduleEnd = ScheduleEnd;<br>
>> + ScheduleData *PrevInBundle = nullptr;<br>
>> + ScheduleData *Bundle = nullptr;<br>
>> + bool ReSchedule = false;<br>
>> + DEBUG(dbgs() << "SLP: bundle: " << *VL[0] << "\n");<br>
>> + for (Value *V : VL) {<br>
>> + extendSchedulingRegion(V);<br>
>> + ScheduleData *BundleMember = getScheduleData(V);<br>
>> + assert(BundleMember &&<br>
>> + "no ScheduleData for bundle member (maybe not in same basic block)");<br>
>> + if (BundleMember->IsScheduled) {<br>
>> + // A bundle member was scheduled as single instruction before and now<br>
>> + // needs to be scheduled as part of the bundle. We just get rid of the<br>
>> + // existing schedule.<br>
>> + DEBUG(dbgs() << "SLP: reset schedule because " << *BundleMember<br>
>> + << " was already scheduled\n");<br>
>> + ReSchedule = true;<br>
>> + }<br>
>> + assert(BundleMember->isSchedulingEntity() &&<br>
>> + "bundle member already part of other bundle");<br>
>> + if (PrevInBundle) {<br>
>> + PrevInBundle->NextInBundle = BundleMember;<br>
>> + } else {<br>
>> + Bundle = BundleMember;<br>
>> + }<br>
>> + BundleMember->UnscheduledDepsInBundle = 0;<br>
>> + Bundle->UnscheduledDepsInBundle += BundleMember->UnscheduledDeps;<br>
>> +<br>
>> + // Group the instructions to a bundle.<br>
>> + BundleMember->FirstInBundle = Bundle;<br>
>> + PrevInBundle = BundleMember;<br>
>> + }<br>
>> + if (ScheduleEnd != OldScheduleEnd) {<br>
>> + // The scheduling region got new instructions at the lower end (or it is a<br>
>> + // new region for the first bundle). This makes it necessary to<br>
>> + // recalculate all dependencies.<br>
>> + // It is seldom that this needs to be done a second time after adding the<br>
>> + // initial bundle to the region.<br>
>> + for (auto *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode()) {<br>
>> + ScheduleData *SD = getScheduleData(I);<br>
>> + SD->clearDependencies();<br>
>> + }<br>
>> + ReSchedule = true;<br>
>> + }<br>
>> + if (ReSchedule) {<br>
>> + resetSchedule();<br>
>> + initialFillReadyList(ReadyInsts);<br>
>> + }<br>
>> +<br>
>> + DEBUG(dbgs() << "SLP: try schedule bundle " << *Bundle << " in block "<br>
>> + << BB->getName() << "\n");<br>
>> +<br>
>> + calculateDependencies(Bundle, true, AA);<br>
>> +<br>
>> + // Now try to schedule the new bundle. As soon as the bundle is "ready" it<br>
>> + // means that there are no cyclic dependencies and we can schedule it.<br>
>> + // Note that's important that we don't "schedule" the bundle yet (see<br>
>> + // cancelScheduling).<br>
>> + while (!Bundle->isReady() && !ReadyInsts.empty()) {<br>
>> +<br>
>> + ScheduleData *pickedSD = ReadyInsts.back();<br>
>> + ReadyInsts.pop_back();<br>
>> +<br>
>> + if (pickedSD->isSchedulingEntity() && pickedSD->isReady()) {<br>
>> + schedule(pickedSD, ReadyInsts);<br>
>> + }<br>
>> + }<br>
>> + return Bundle->isReady();<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::BlockScheduling::cancelScheduling(ArrayRef<Value *> VL) {<br>
>> + if (isa<PHINode>(VL[0]))<br>
>> + return;<br>
>> +<br>
>> + ScheduleData *Bundle = getScheduleData(VL[0]);<br>
>> + DEBUG(dbgs() << "SLP: cancel scheduling of " << *Bundle << "\n");<br>
>> + assert(!Bundle->IsScheduled &&<br>
>> + "Can't cancel bundle which is already scheduled");<br>
>> + assert(Bundle->isSchedulingEntity() && Bundle->isPartOfBundle() &&<br>
>> + "tried to unbundle something which is not a bundle");<br>
>> +<br>
>> + // Un-bundle: make single instructions out of the bundle.<br>
>> + ScheduleData *BundleMember = Bundle;<br>
>> + while (BundleMember) {<br>
>> + assert(BundleMember->FirstInBundle == Bundle && "corrupt bundle links");<br>
>> + BundleMember->FirstInBundle = BundleMember;<br>
>> + ScheduleData *Next = BundleMember->NextInBundle;<br>
>> + BundleMember->NextInBundle = nullptr;<br>
>> + BundleMember->UnscheduledDepsInBundle = BundleMember->UnscheduledDeps;<br>
>> + if (BundleMember->UnscheduledDepsInBundle == 0) {<br>
>> + ReadyInsts.insert(BundleMember);<br>
>> + }<br>
>> + BundleMember = Next;<br>
>> + }<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::BlockScheduling::extendSchedulingRegion(Value *V) {<br>
>> + if (getScheduleData(V))<br>
>> + return;<br>
>> + Instruction *I = dyn_cast<Instruction>(V);<br>
>> + assert(I && "bundle member must be an instruction");<br>
>> + assert(!isa<PHINode>(I) && "phi nodes don't need to be scheduled");<br>
>> + if (!ScheduleStart) {<br>
>> + // It's the first instruction in the new region.<br>
>> + initScheduleData(I, I->getNextNode(), nullptr, nullptr);<br>
>> + ScheduleStart = I;<br>
>> + ScheduleEnd = I->getNextNode();<br>
>> + assert(ScheduleEnd && "tried to vectorize a TerminatorInst?");<br>
>> + DEBUG(dbgs() << "SLP: initialize schedule region to " << *I << "\n");<br>
>> + return;<br>
>> + }<br>
>> + // Search up and down at the same time, because we don't know if the new<br>
>> + // instruction is above or below the existing scheduling region.<br>
>> + BasicBlock::reverse_iterator UpIter(ScheduleStart);<br>
>> + BasicBlock::reverse_iterator UpperEnd = BB->rend();<br>
>> + BasicBlock::iterator DownIter(ScheduleEnd);<br>
>> + BasicBlock::iterator LowerEnd = BB->end();<br>
>> + for (;;) {<br>
>> + if (UpIter != UpperEnd) {<br>
>> + if (&*UpIter == I) {<br>
>> + initScheduleData(I, ScheduleStart, nullptr, FirstLoadStoreInRegion);<br>
>> + ScheduleStart = I;<br>
>> + DEBUG(dbgs() << "SLP: extend schedule region start to " << *I << "\n");<br>
>> + return;<br>
>> + }<br>
>> + UpIter++;<br>
>> + }<br>
>> + if (DownIter != LowerEnd) {<br>
>> + if (&*DownIter == I) {<br>
>> + initScheduleData(ScheduleEnd, I->getNextNode(), LastLoadStoreInRegion,<br>
>> + nullptr);<br>
>> + ScheduleEnd = I->getNextNode();<br>
>> + assert(ScheduleEnd && "tried to vectorize a TerminatorInst?");<br>
>> + DEBUG(dbgs() << "SLP: extend schedule region end to " << *I << "\n");<br>
>> + return;<br>
>> + }<br>
>> + DownIter++;<br>
>> + }<br>
>> + assert((UpIter != UpperEnd || DownIter != LowerEnd) &&<br>
>> + "instruction not found in block");<br>
>> + }<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::BlockScheduling::initScheduleData(Instruction *FromI,<br>
>> + Instruction *ToI,<br>
>> + ScheduleData *PrevLoadStore,<br>
>> + ScheduleData *NextLoadStore) {<br>
>> + ScheduleData *CurrentLoadStore = PrevLoadStore;<br>
>> + for (Instruction *I = FromI; I != ToI; I = I->getNextNode()) {<br>
>> + ScheduleData *SD = ScheduleDataMap[I];<br>
>> + if (!SD) {<br>
>> + // Allocate a new ScheduleData for the instruction.<br>
>> + if (ChunkPos >= ChunkSize) {<br>
>> + ScheduleDataChunks.push_back(<br>
>> + llvm::make_unique<ScheduleData[]>(ChunkSize));<br>
>> + ChunkPos = 0;<br>
>> + }<br>
>> + SD = &(ScheduleDataChunks.back()[ChunkPos++]);<br>
>> + ScheduleDataMap[I] = SD;<br>
>> + SD->Inst = I;<br>
>> + }<br>
>> + assert(!isInSchedulingRegion(SD) &&<br>
>> + "new ScheduleData already in scheduling region");<br>
>> + SD->init(SchedulingRegionID);<br>
>> +<br>
>> + if (I->mayReadOrWriteMemory()) {<br>
>> + // Update the linked list of memory accessing instructions.<br>
>> + if (CurrentLoadStore) {<br>
>> + CurrentLoadStore->NextLoadStore = SD;<br>
>> + } else {<br>
>> + FirstLoadStoreInRegion = SD;<br>
>> + }<br>
>> + CurrentLoadStore = SD;<br>
>> + }<br>
>> + }<br>
>> + if (NextLoadStore) {<br>
>> + if (CurrentLoadStore)<br>
>> + CurrentLoadStore->NextLoadStore = NextLoadStore;<br>
>> + } else {<br>
>> + LastLoadStoreInRegion = CurrentLoadStore;<br>
>> + }<br>
>> +}<br>
>> +<br>
>> +/// \returns the AA location that is being access by the instruction.<br>
>> +static AliasAnalysis::Location getLocation(Instruction *I, AliasAnalysis *AA) {<br>
>> + if (StoreInst *SI = dyn_cast<StoreInst>(I))<br>
>> + return AA->getLocation(SI);<br>
>> + if (LoadInst *LI = dyn_cast<LoadInst>(I))<br>
>> + return AA->getLocation(LI);<br>
>> + return AliasAnalysis::Location();<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::BlockScheduling::calculateDependencies(ScheduleData *SD,<br>
>> + bool InsertInReadyList,<br>
>> + AliasAnalysis *AA) {<br>
>> + assert(SD->isSchedulingEntity());<br>
>> +<br>
>> + SmallVector<ScheduleData *, 10> WorkList;<br>
>> + WorkList.push_back(SD);<br>
>> +<br>
>> + while (!WorkList.empty()) {<br>
>> + ScheduleData *SD = WorkList.back();<br>
>> + WorkList.pop_back();<br>
>> +<br>
>> + ScheduleData *BundleMember = SD;<br>
>> + while (BundleMember) {<br>
>> + assert(isInSchedulingRegion(BundleMember));<br>
>> + if (!BundleMember->hasValidDependencies()) {<br>
>> +<br>
>> + DEBUG(dbgs() << "SLP: update deps of " << *BundleMember << "\n");<br>
>> + BundleMember->Dependencies = 0;<br>
>> + BundleMember->resetUnscheduledDeps();<br>
>> +<br>
>> + // Handle def-use chain dependencies.<br>
>> + for (User *U : BundleMember->Inst->users()) {<br>
>> + if (isa<Instruction>(U)) {<br>
>> + ScheduleData *UseSD = getScheduleData(U);<br>
>> + if (UseSD && isInSchedulingRegion(UseSD->FirstInBundle)) {<br>
>> + BundleMember->Dependencies++;<br>
>> + ScheduleData *DestBundle = UseSD->FirstInBundle;<br>
>> + if (!DestBundle->IsScheduled) {<br>
>> + BundleMember->incrementUnscheduledDeps(1);<br>
>> + }<br>
>> + if (!DestBundle->hasValidDependencies()) {<br>
>> + WorkList.push_back(DestBundle);<br>
>> + }<br>
>> + }<br>
>> + } else {<br>
>> + // I'm not sure if this can ever happen. But we need to be safe.<br>
>> + // This lets the instruction/bundle never be scheduled and eventally<br>
>> + // disable vectorization.<br>
>> + BundleMember->Dependencies++;<br>
>> + BundleMember->incrementUnscheduledDeps(1);<br>
>> + }<br>
>> + }<br>
>> +<br>
>> + // Handle the memory dependencies.<br>
>> + ScheduleData *DepDest = BundleMember->NextLoadStore;<br>
>> + if (DepDest) {<br>
>> + AliasAnalysis::Location SrcLoc = getLocation(BundleMember->Inst, AA);<br>
>> + bool SrcMayWrite = BundleMember->Inst->mayWriteToMemory();<br>
>> +<br>
>> + while (DepDest) {<br>
>> + assert(isInSchedulingRegion(DepDest));<br>
>> + if (SrcMayWrite || DepDest->Inst->mayWriteToMemory()) {<br>
>> + AliasAnalysis::Location DstLoc = getLocation(DepDest->Inst, AA);<br>
>> + if (!SrcLoc.Ptr || !DstLoc.Ptr || AA->alias(SrcLoc, DstLoc)) {<br>
>> + DepDest->MemoryDependencies.push_back(BundleMember);<br>
>> + BundleMember->Dependencies++;<br>
>> + ScheduleData *DestBundle = DepDest->FirstInBundle;<br>
>> + if (!DestBundle->IsScheduled) {<br>
>> + BundleMember->incrementUnscheduledDeps(1);<br>
>> + }<br>
>> + if (!DestBundle->hasValidDependencies()) {<br>
>> + WorkList.push_back(DestBundle);<br>
>> + }<br>
>> + }<br>
>> + }<br>
>> + DepDest = DepDest->NextLoadStore;<br>
>> + }<br>
>> + }<br>
>> + }<br>
>> + BundleMember = BundleMember->NextInBundle;<br>
>> + }<br>
>> + if (InsertInReadyList && SD->isReady()) {<br>
>> + ReadyInsts.push_back(SD);<br>
>> + DEBUG(dbgs() << "SLP: gets ready on update: " << *SD->Inst << "\n");<br>
>> + }<br>
>> + }<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::BlockScheduling::resetSchedule() {<br>
>> + assert(ScheduleStart &&<br>
>> + "tried to reset schedule on block which has not been scheduled");<br>
>> + for (Instruction *I = ScheduleStart; I != ScheduleEnd; I = I->getNextNode()) {<br>
>> + ScheduleData *SD = getScheduleData(I);<br>
>> + assert(isInSchedulingRegion(SD));<br>
>> + SD->IsScheduled = false;<br>
>> + SD->resetUnscheduledDeps();<br>
>> + }<br>
>> + ReadyInsts.clear();<br>
>> +}<br>
>> +<br>
>> +void BoUpSLP::scheduleBlock(BasicBlock *BB) {<br>
>> + DEBUG(dbgs() << "SLP: schedule block " << BB->getName() << "\n");<br>
>> +<br>
>> + BlockScheduling *BS = BlocksSchedules[BB].get();<br>
>> + if (!BS || !BS->ScheduleStart)<br>
>> + return;<br>
>> +<br>
>> + BS->resetSchedule();<br>
>> +<br>
>> + // For the real scheduling we use a more sophisticated ready-list: it is<br>
>> + // sorted by the original instruction location. This lets the final schedule<br>
>> + // be as close as possible to the original instruction order.<br>
>> + struct ScheduleDataCompare {<br>
>> + bool operator()(ScheduleData *SD1, ScheduleData *SD2) {<br>
>> + return SD2->SchedulingPriority < SD1->SchedulingPriority;<br>
>> + }<br>
>> + };<br>
>> + std::set<ScheduleData *, ScheduleDataCompare> ReadyInsts;<br>
>> +<br>
>> + // Ensure that all depencency data is updated and fill the ready-list with<br>
>> + // initial instructions.<br>
>> + int Idx = 0;<br>
>> + int NumToSchedule = 0;<br>
>> + for (auto *I = BS->ScheduleStart; I != BS->ScheduleEnd;<br>
>> + I = I->getNextNode()) {<br>
>> + ScheduleData *SD = BS->getScheduleData(I);<br>
>> + assert(<br>
>> + SD->isPartOfBundle() == (ScalarToTreeEntry.count(SD->Inst) != 0) &&<br>
>> + "scheduler and vectorizer have different opinion on what is a bundle");<br>
>> + SD->FirstInBundle->SchedulingPriority = Idx++;<br>
>> + if (SD->isSchedulingEntity()) {<br>
>> + BS->calculateDependencies(SD, false, AA);<br>
>> + NumToSchedule++;<br>
>> + }<br>
>> + }<br>
>> + BS->initialFillReadyList(ReadyInsts);<br>
>> +<br>
>> + Instruction *LastScheduledInst = BS->ScheduleEnd;<br>
>> +<br>
>> + // Do the "real" scheduling.<br>
>> + while (!ReadyInsts.empty()) {<br>
>> + ScheduleData *picked = *ReadyInsts.begin();<br>
>> + ReadyInsts.erase(ReadyInsts.begin());<br>
>> +<br>
>> + // Move the scheduled instruction(s) to their dedicated places, if not<br>
>> + // there yet.<br>
>> + ScheduleData *BundleMember = picked;<br>
>> + while (BundleMember) {<br>
>> + Instruction *pickedInst = BundleMember->Inst;<br>
>> + if (LastScheduledInst->getNextNode() != pickedInst) {<br>
>> + BB->getInstList().remove(pickedInst);<br>
>> + BB->getInstList().insert(LastScheduledInst, pickedInst);<br>
>> + }<br>
>> + LastScheduledInst = pickedInst;<br>
>> + BundleMember = BundleMember->NextInBundle;<br>
>> + }<br>
>> +<br>
>> + BS->schedule(picked, ReadyInsts);<br>
>> + NumToSchedule--;<br>
>> + }<br>
>> + assert(NumToSchedule == 0 && "could not schedule all instructions");<br>
>> +<br>
>> + // Avoid duplicate scheduling of the block.<br>
>> + BS->ScheduleStart = nullptr;<br>
>> +}<br>
>> +<br>
>> /// The SLPVectorizer Pass.<br>
>> struct SLPVectorizer : public FunctionPass {<br>
>> typedef SmallVector<StoreInst *, 8> StoreList;<br>
>><br>
>> Modified: llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll?rev=214494&r1=214493&r2=214494&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll?rev=214494&r1=214493&r2=214494&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll (original)<br>
>> +++ llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll Fri Aug 1 04:20:42 2014<br>
>> @@ -1,4 +1,4 @@<br>
>> -; RUN: opt -slp-vectorizer -mtriple=x86_64-apple-macosx10.9.0 -mcpu=corei7-avx -S < %s | FileCheck %s<br>
>> +; RUN: opt -basicaa -slp-vectorizer -mtriple=x86_64-apple-macosx10.9.0 -mcpu=corei7-avx -S < %s | FileCheck %s<br>
>> target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
>> target triple = "x86_64-apple-macosx10.9.0"<br>
>><br>
>><br>
>> Modified: llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll?rev=214494&r1=214493&r2=214494&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll?rev=214494&r1=214493&r2=214494&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll (original)<br>
>> +++ llvm/trunk/test/Transforms/SLPVectorizer/X86/in-tree-user.ll Fri Aug 1 04:20:42 2014<br>
>> @@ -5,9 +5,11 @@ target triple = "x86_64-apple-macosx10.7<br>
>><br>
>> @.str = private unnamed_addr constant [6 x i8] c"bingo\00", align 1<br>
>><br>
>> -; We can't vectorize when the roots are used inside the tree.<br>
>> +; Uses inside the tree must be scheduled after the corresponding tree bundle.<br>
>> ;CHECK-LABEL: @in_tree_user(<br>
>> -;CHECK-NOT: load <2 x double><br>
>> +;CHECK: load <2 x double><br>
>> +;CHECK: fadd <2 x double><br>
>> +;CHECK: InTreeUser = fadd<br>
>> ;CHECK: ret<br>
>> define void @in_tree_user(double* nocapture %A, i32 %n) {<br>
>> entry:<br>
>> @@ -22,7 +24,7 @@ for.body:<br>
>> %mul1 = fmul double %conv, %1<br>
>> %mul2 = fmul double %mul1, 7.000000e+00<br>
>> %add = fadd double %mul2, 5.000000e+00<br>
>> - %BadValue = fadd double %add, %add ; <------------------ In tree user.<br>
>> + %InTreeUser = fadd double %add, %add ; <------------------ In tree user.<br>
>> %2 = or i64 %0, 1<br>
>> %arrayidx6 = getelementptr inbounds double* %A, i64 %2<br>
>> %3 = load double* %arrayidx6, align 8<br>
>> @@ -43,6 +45,7 @@ for.inc:<br>
>> br i1 %exitcond, label %for.end, label %for.body<br>
>><br>
>> for.end: ; preds = %for.inc<br>
>> + store double %InTreeUser, double* %A, align 8 ; Avoid dead code elimination of the InTreeUser.<br>
>> ret void<br>
>> }<br>
>><br>
>><br>
>> Added: llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll?rev=214494&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll?rev=214494&view=auto</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll (added)<br>
>> +++ llvm/trunk/test/Transforms/SLPVectorizer/X86/scheduling.ll Fri Aug 1 04:20:42 2014<br>
>> @@ -0,0 +1,78 @@<br>
>> +; RUN: opt < %s -basicaa -slp-vectorizer -S -mtriple=i386-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s<br>
>> +<br>
>> +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
>> +target triple = "x86_64-apple-macosx10.9.0"<br>
>> +<br>
>> +;CHECK-LABEL: @foo<br>
>> +;CHECK: load <4 x i32><br>
>> +;CHECK: load <4 x i32><br>
>> +;CHECK: %[[S1:.+]] = add <4 x i32><br>
>> +;CHECK-DAG: store <4 x i32> %[[S1]]<br>
>> +;CHECK-DAG: %[[A1:.+]] = add nsw i32<br>
>> +;CHECK-DAG: %[[A2:.+]] = add nsw i32 %[[A1]]<br>
>> +;CHECK-DAG: %[[A3:.+]] = add nsw i32 %[[A2]]<br>
>> +;CHECK-DAG: %[[A4:.+]] = add nsw i32 %[[A3]]<br>
>> +;CHECK: ret i32 %[[A4]]<br>
>> +<br>
>> +define i32 @foo(i32* nocapture readonly %diff) #0 {<br>
>> +entry:<br>
>> + %m2 = alloca [8 x [8 x i32]], align 16<br>
>> + %0 = bitcast [8 x [8 x i32]]* %m2 to i8*<br>
>> + br label %for.body<br>
>> +<br>
>> +for.body: ; preds = %for.body, %entry<br>
>> + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]<br>
>> + %a.088 = phi i32 [ 0, %entry ], [ %add52, %for.body ]<br>
>> + %1 = shl i64 %indvars.iv, 3<br>
>> + %arrayidx = getelementptr inbounds i32* %diff, i64 %1<br>
>> + %2 = load i32* %arrayidx, align 4<br>
>> + %3 = or i64 %1, 4<br>
>> + %arrayidx2 = getelementptr inbounds i32* %diff, i64 %3<br>
>> + %4 = load i32* %arrayidx2, align 4<br>
>> + %add3 = add nsw i32 %4, %2<br>
>> + %arrayidx6 = getelementptr inbounds [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 0<br>
>> + store i32 %add3, i32* %arrayidx6, align 16<br>
>> + %add10 = add nsw i32 %add3, %a.088<br>
>> + %5 = or i64 %1, 1<br>
>> + %arrayidx13 = getelementptr inbounds i32* %diff, i64 %5<br>
>> + %6 = load i32* %arrayidx13, align 4<br>
>> + %7 = or i64 %1, 5<br>
>> + %arrayidx16 = getelementptr inbounds i32* %diff, i64 %7<br>
>> + %8 = load i32* %arrayidx16, align 4<br>
>> + %add17 = add nsw i32 %8, %6<br>
>> + %arrayidx20 = getelementptr inbounds [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 1<br>
>> + store i32 %add17, i32* %arrayidx20, align 4<br>
>> + %add24 = add nsw i32 %add10, %add17<br>
>> + %9 = or i64 %1, 2<br>
>> + %arrayidx27 = getelementptr inbounds i32* %diff, i64 %9<br>
>> + %10 = load i32* %arrayidx27, align 4<br>
>> + %11 = or i64 %1, 6<br>
>> + %arrayidx30 = getelementptr inbounds i32* %diff, i64 %11<br>
>> + %12 = load i32* %arrayidx30, align 4<br>
>> + %add31 = add nsw i32 %12, %10<br>
>> + %arrayidx34 = getelementptr inbounds [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 2<br>
>> + store i32 %add31, i32* %arrayidx34, align 8<br>
>> + %add38 = add nsw i32 %add24, %add31<br>
>> + %13 = or i64 %1, 3<br>
>> + %arrayidx41 = getelementptr inbounds i32* %diff, i64 %13<br>
>> + %14 = load i32* %arrayidx41, align 4<br>
>> + %15 = or i64 %1, 7<br>
>> + %arrayidx44 = getelementptr inbounds i32* %diff, i64 %15<br>
>> + %16 = load i32* %arrayidx44, align 4<br>
>> + %add45 = add nsw i32 %16, %14<br>
>> + %arrayidx48 = getelementptr inbounds [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 3<br>
>> + store i32 %add45, i32* %arrayidx48, align 4<br>
>> + %add52 = add nsw i32 %add38, %add45<br>
>> + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1<br>
>> + %exitcond = icmp eq i64 %indvars.iv.next, 8<br>
>> + br i1 %exitcond, label %for.end, label %for.body<br>
>> +<br>
>> +for.end: ; preds = %for.body<br>
>> + %arraydecay = getelementptr inbounds [8 x [8 x i32]]* %m2, i64 0, i64 0<br>
>> + call void @ff([8 x i32]* %arraydecay) #1<br>
>> + ret i32 %add52<br>
>> +}<br>
>> +<br>
>> +declare void @ff([8 x i32]*) #2<br>
>> +<br>
>> +<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>