[llvm-dev] Computing loop trip counts with Scalar evolution

Alex Susu via llvm-dev llvm-dev at lists.llvm.org
Thu May 18 11:30:33 PDT 2017


   Hello.
     I tried to get the trip count of a loop with Scalar evolution. I got inspired from 
http://stackoverflow.com/questions/13834364/how-to-get-loop-bounds-in-llvm .
     However the analysis described there doesn't work well for the second inner loop of 
thes function below (although if we declare Bcols a short it works well):
       void MatMul(int Arows, int Acols, int Brows, int Bcols) {
         short i, j, k;
         for (i = 0; i < Arows; ++i) {
           for (j = 0; j < Bcols; ++j) {
             C[i][j] = 0;
             for (k = 0; k < Acols; ++k) {
               C[i][j] += A[i][k] * B[j][k];
             }
           }
         }
       }

     However, I discovered in LoopVectorize.cpp 
(http://llvm.org/docs/doxygen/html/LoopVectorize_8cpp_source.html) we have the method 
InnerLoopVectorizer::getOrCreateTripCount() that seems to do a better job at computing the 
trip count, even if the implementation differences are not big. The differences are subtle 
- first of all the method getOrCreateTripCount() doesn't call 
hasLoopInvariantBackedgeTakenCount().

     Please don't hesitate  to comment why InnerLoopVectorizer::getOrCreateTripCount() 
works better. I will try to come back myself with more info.

   Thank you,
     Alex

PS: Could you please recommend me one important paper for Scalar evolutions?


More information about the llvm-dev mailing list