[PATCH] D109368: [LV] Don't vectorize if we can prove RT + vector cost >= scalar cost.

Evgeniy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 27 00:33:24 PDT 2021


ebrevnov added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8226
+    //  The total cost of the vector loop is
+    //    RtC + VecC * (TC / VF) + EpiC
+    //  where
----------------
dmgreen wrote:
> This should be `RtC + VecC * floor(TC / VF) + EpiC` or `RtC + VecC * ceil(TC / VF)` when folding the tail (assuming there is no epilogue then). That makes the math more difficult unless it makes the assumption that those round to the same thing.
> 
> It is also assuming that the runtime checks do not fail, otherwise a probability factor would need to be added. (Probably fine to assume, but the more runtime checks there are, the less likely they are to all succeed).
> 
> And there can be other costs for vectorizations. The "check N is less than MinProfTripCount" isn't free and there can be other inefficiencies from vector loops.
> This should be `RtC + VecC * floor(TC / VF) + EpiC` or `RtC + VecC * ceil(TC / VF)` when folding the tail (assuming there is no epilogue then).
Since we already compute upper estimate for MinTC1 it doesn't seem to be necessary to do additional adjustment when folding tail.  But we probably want/need to do an adjustment for "requiresScalarEpilogue" case.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8242
+    //
+    // For now we assume the epilogue cost EpiC = 0 for simplicity.
+    unsigned VF = SelectedVF.Width.getKnownMinValue();
----------------
dmgreen wrote:
> lebedev.ri wrote:
> > I agree that here the math checks out, the sign is correct.
> Perhaps add some more assumptions, like the ones mentioned above and that (ScalarC - (VecC / VF)) > 0 from other profitability checks.
It's totally fine for '(ScalarC - (VecC / VF))' to be negative since we take max(MinTC1, MinTC2) and MinTC2>=0 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109368



More information about the llvm-commits mailing list