[llvm-commits] [llvm] r96613 - in /llvm/trunk: include/llvm/CodeGen/LiveIntervalAnalysis.h lib/CodeGen/CalcSpillWeights.cpp lib/CodeGen/LiveIntervalAnalysis.cpp test/CodeGen/X86/2008-02-22-ReMatBug.ll test/CodeGen/X86/pr3495-2.ll

Evan Cheng evan.cheng at apple.com
Thu Feb 18 13:39:02 PST 2010


On Feb 18, 2010, at 1:33 PM, Jakob Stoklund Olesen wrote:

> Author: stoklund
> Date: Thu Feb 18 15:33:05 2010
> New Revision: 96613
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=96613&view=rev
> Log:
> Always normalize spill weights, also for intervals created by spilling.
> 
> Moderate the weight given to very small intervals.
> 
> The spill weight given to new intervals created when spilling was not
> normalized in the same way as the original spill weights calculated by
> CalcSpillWeights. That meant that restored registers would tend to hang around
> because they had a much higher spill weight that unspilled registers.
> 
> This improves the runtime of a few tests by up to 10%, and there are no
> significant regressions.

Nice.

> 
> 
> 
> +    // After summing the spill weights of all defs and uses, the final weight
> +    // should be normalized, dividing the weight of the interval by its size.
> +    // This encourages spilling of intervals that are large and have few uses,
> +    // and discourages spilling of small intervals with many uses.
> +    void normalizeSpillWeight(LiveInterval &li) {
> +      li.weight /= getApproximateInstructionCount(li) + 25;
> +    }
> +

Why 25? The new meaning of life? :-)

Evan

>     typedef Reg2IntervalMap::iterator iterator;
>     typedef Reg2IntervalMap::const_iterator const_iterator;
>     const_iterator begin() const { return r2iMap_.begin(); }
> @@ -409,6 +417,9 @@
>         DenseMap<unsigned,unsigned> &MBBVRegsMap,
>         std::vector<LiveInterval*> &NewLIs);
> 
> +    // Normalize the spill weight of all the intervals in NewLIs.
> +    void normalizeSpillWeights(std::vector<LiveInterval*> &NewLIs);
> +
>     static LiveInterval* createInterval(unsigned Reg);
> 
>     void printInstrs(raw_ostream &O) const;
> 
> Modified: llvm/trunk/lib/CodeGen/CalcSpillWeights.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CalcSpillWeights.cpp?rev=96613&r1=96612&r2=96613&view=diff
> 
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/CalcSpillWeights.cpp (original)
> +++ llvm/trunk/lib/CodeGen/CalcSpillWeights.cpp Thu Feb 18 15:33:05 2010
> @@ -131,10 +131,7 @@
>       if (Hint.first || Hint.second)
>         li.weight *= 1.01F;
> 
> -      // Divide the weight of the interval by its size.  This encourages
> -      // spilling of intervals that are large and have few uses, and
> -      // discourages spilling of small intervals with many uses.
> -      li.weight /= lis->getApproximateInstructionCount(li) * SlotIndex::NUM;
> +      lis->normalizeSpillWeight(li);
>     }
>   }
> 
> 
> Modified: llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp?rev=96613&r1=96612&r2=96613&view=diff
> 
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp (original)
> +++ llvm/trunk/lib/CodeGen/LiveIntervalAnalysis.cpp Thu Feb 18 15:33:05 2010
> @@ -1562,6 +1562,12 @@
>   }
> }
> 
> +void
> +LiveIntervals::normalizeSpillWeights(std::vector<LiveInterval*> &NewLIs) {
> +  for (unsigned i = 0, e = NewLIs.size(); i != e; ++i)
> +    normalizeSpillWeight(*NewLIs[i]);
> +}
> +
> std::vector<LiveInterval*> LiveIntervals::
> addIntervalsForSpillsFast(const LiveInterval &li,
>                           const MachineLoopInfo *loopInfo,
> @@ -1739,6 +1745,7 @@
>     }
> 
>     handleSpilledImpDefs(li, vrm, rc, NewLIs);
> +    normalizeSpillWeights(NewLIs);
>     return NewLIs;
>   }
> 
> @@ -1814,6 +1821,7 @@
>   // Insert spills / restores if we are splitting.
>   if (!TrySplit) {
>     handleSpilledImpDefs(li, vrm, rc, NewLIs);
> +    normalizeSpillWeights(NewLIs);
>     return NewLIs;
>   }
> 
> @@ -1973,6 +1981,7 @@
>   }
> 
>   handleSpilledImpDefs(li, vrm, rc, RetNewLIs);
> +  normalizeSpillWeights(RetNewLIs);
>   return RetNewLIs;
> }
> 
> 
> Modified: llvm/trunk/test/CodeGen/X86/2008-02-22-ReMatBug.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-02-22-ReMatBug.ll?rev=96613&r1=96612&r2=96613&view=diff
> 
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/2008-02-22-ReMatBug.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/2008-02-22-ReMatBug.ll Thu Feb 18 15:33:05 2010
> @@ -1,4 +1,4 @@
> -; RUN: llc < %s -march=x86 -stats |& grep {Number of re-materialization} | grep 3
> +; RUN: llc < %s -march=x86 -stats |& grep {Number of re-materialization} | grep 2
> ; rdar://5761454
> 
> 	%struct.quad_struct = type { i32, i32, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct*, %struct.quad_struct* }
> 
> Modified: llvm/trunk/test/CodeGen/X86/pr3495-2.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr3495-2.ll?rev=96613&r1=96612&r2=96613&view=diff
> 
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/pr3495-2.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/pr3495-2.ll Thu Feb 18 15:33:05 2010
> @@ -1,4 +1,8 @@
> -; RUN: llc < %s -march=x86 -relocation-model=pic -disable-fp-elim -stats |& grep {Number of reloads omited}
> +; RUN: llc < %s -march=x86 -relocation-model=pic -disable-fp-elim -stats |& grep {Number of loads added} | grep 1
> +; PR3495
> +;
> +; This test may not be testing what it was supposed to test.
> +; It used to have two spills and four reloads, but not it only has one spill and one reload.
> 
> target datalayout = "e-p:32:32:32"
> target triple = "i386-apple-darwin9.6"
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list