[PATCH] D34608: [AArch64] Increase CSR cost when defering use of CSR is preferred

Jun Bum Lim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 14:35:45 PDT 2017


junbuml added inline comments.


================
Comment at: include/llvm/Target/TargetLowering.h:3412
+  virtual unsigned getNumberOfTradableSplitsAgainstCSR() const {
+    return 0;
+  }
----------------
qcolombet wrote:
> I don't think we can have a simple numbers as in static number of instructions. The cost of splitting depends where it happens and not taking that into account would for sure lead to cases where we get it wrong.
I rename this to getWeightFactorToTheFirstCSRAllocation(). 
IIUC, the cost of splitting calculated in calculateRegionSplitCost() consider where it happen.   We have to compare this split cost with the CSRCost which should be the cost for a spill of the CSR in the entry block.  The return value of getWeightFactorToTheFirstCSRAllocation()  approximates the number of copies which can be traded against the first spill of CSR in the entry block. In AArch64, I set 30, which means  the very push/pop for the first CSR in the entry/exit block is tradable against to 30 copies in other blocks.  Hopefully, this might estimate the benefit of shrink wrapping opportunity when deferring the first CSR allocation.


================
Comment at: lib/CodeGen/RegAllocGreedy.cpp:2398
+    return std::max(BestCost.getFrequency(),
+                    EntryFreq * TLI->getNumberOfTradableSpillsAgainstCSR());
+  else if (getStage(VirtReg) < RS_Split)
----------------
qcolombet wrote:
> That formula does not make sense to me.
> We should compare the cost of spilling vs. the CSRCost.
> EntryFreq * #tradableSpills is not the cost of spilling.
IIUC, the spilt cost is the sum of frequencies of the copies at all the related blocks, which is calculated in the current cost model. Similarly, the CSR cost should be a cost for a spill of the CSR in the entry block. I think that why we decide the CSRCost based on the frequency of the entry block in initializeCSRCost(). 
Since we have to compare the cost of copies with the cost of push/pop in prologue|epilogue, especially when allocating the first CSR is not preferred, I gave a weight factor through getWeightFactorToTheFirstCSRAllocation(). Hopefully this make sense to you. If not, please let me know any suggestion. 


================
Comment at: lib/Target/AArch64/AArch64ISelLowering.cpp:10787
+
+// The number of splits in user blocks which can be traded against the spill of
+// the CSR in the entry block when detering the first use of CSR is prefered.
----------------
qcolombet wrote:
> What do user blocks mean in this context?
Rename the function name and update the comment.


https://reviews.llvm.org/D34608





More information about the llvm-commits mailing list