[llvm-branch-commits] [llvm] ef4dbb2 - [LV] Use ScalarEvolution::getURemExpr to reduce duplication.

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 22 06:57:05 PST 2020


Author: Florian Hahn
Date: 2020-12-22T14:48:42Z
New Revision: ef4dbb2b7a85b47bfd84188bd1c6a9eddc5c536b

URL: https://github.com/llvm/llvm-project/commit/ef4dbb2b7a85b47bfd84188bd1c6a9eddc5c536b
DIFF: https://github.com/llvm/llvm-project/commit/ef4dbb2b7a85b47bfd84188bd1c6a9eddc5c536b.diff

LOG: [LV] Use ScalarEvolution::getURemExpr to reduce duplication.

ScalarEvolution should be able to handle both constant and variable trip
counts using getURemExpr, so we do not have to handle them separately.

This is a small simplification of a56280094e08.

Reviewed By: gilr

Differential Revision: https://reviews.llvm.org/D93677

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0b9e660c987a..6ab8e5884a76 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5506,20 +5506,15 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
          "MaxVF must be a power of 2");
   unsigned MaxVFtimesIC =
       UserIC ? MaxVF.getFixedValue() * UserIC : MaxVF.getFixedValue();
-  if (TC > 0 && TC % MaxVFtimesIC == 0) {
-    // Accept MaxVF if we do not have a tail.
-    LLVM_DEBUG(dbgs() << "LV: No tail will remain for any chosen VF.\n");
-    return MaxVF;
-  }
-
   // Avoid tail folding if the trip count is known to be a multiple of any VF we
   // chose.
   ScalarEvolution *SE = PSE.getSE();
   const SCEV *BackedgeTakenCount = PSE.getBackedgeTakenCount();
   const SCEV *ExitCount = SE->getAddExpr(
       BackedgeTakenCount, SE->getOne(BackedgeTakenCount->getType()));
-  unsigned TCisMultipleOf = 1 << SE->GetMinTrailingZeros(ExitCount);
-  if (TCisMultipleOf % MaxVFtimesIC == 0) {
+  const SCEV *Rem = SE->getURemExpr(
+      ExitCount, SE->getConstant(BackedgeTakenCount->getType(), MaxVFtimesIC));
+  if (Rem->isZero()) {
     // Accept MaxVF if we do not have a tail.
     LLVM_DEBUG(dbgs() << "LV: No tail will remain for any chosen VF.\n");
     return MaxVF;


        


More information about the llvm-branch-commits mailing list