[PATCH] D94308: [MachineSink] SinkIntoLoop: analyse stores and aliases in between

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 00:44:38 PST 2021


dmgreen added inline comments.


================
Comment at: llvm/lib/CodeGen/MachineSink.cpp:387
-    bool DontMoveAcrossStore = true;
-    if (!MI.isSafeToMove(AA, DontMoveAcrossStore)) {
-      LLVM_DEBUG(dbgs() << "LoopSink: Instruction not safe to move.\n");
----------------
SjoerdMeijer wrote:
> dmgreen wrote:
> > Why remove this call to isSafeToMove? Don't we need to check for stores/exceptions/unmodelled side effects/etc?
> This has not been deleted but, it has been moved to line 1290 and is now part of `MachineSinking::IsSafeToMove()`. The reason is that we need to have found the sink block and loop in order analyse `DontMoveAcrossStore`.
Oh yeah. There it is. My Ctrl+f failed me.


================
Comment at: llvm/test/CodeGen/AArch64/loop-sink.mir:969-970
   ; CHECK:   [[PHI2:%[0-9]+]]:gpr32 = PHI [[COPY]], %bb.1, %4, %bb.3
+  ; CHECK:   [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @A
+  ; CHECK:   [[LDRWui:%[0-9]+]]:gpr32 = LDRWui killed [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @A :: (dereferenceable load 4 from `i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i64 0, i64 0)`)
   ; CHECK:   [[SDIVWr:%[0-9]+]]:gpr32 = SDIVWr [[PHI2]], [[LDRWui]]
----------------
SjoerdMeijer wrote:
> dmgreen wrote:
> > Some of these look very expensive to avoid a stack reload. Is the reload not cheaper, even if it is in the loop?
> Yep, that might very well be the case. But this is about building up the framework to support loop sinking which requires quite a bit of surgery: after this analysis/correctness patch, we indeed need to work on the cost-model/profitability (your remark), we may need options to force or limit the number of sinks, and then we need to enable this by default. Thus, quite a few steps to go, and cost analysis will be next after this patch.
Do you have the cost part yet? It's difficult to see if this will be a good thing to do without the complete picture. I guess having the code to do it shouldn't hurt in any case.

Naively it would seem to trade one stack reload in the loop for a sunk instruction and the possibly the stack reload of it's arguments. And this appears to be AArch64 - a system with a lot of registers and comparatively cheap stack reloads. On v6m it would be much more likely to come up with the limited amount of registers available. Without being careful it has a high chance of making things worse, not better!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94308/new/

https://reviews.llvm.org/D94308



More information about the llvm-commits mailing list