[llvm-dev] Trip count re-computation during Epilog vectorization

17 views
Skip to first unread message

Venkataramanan Kumar via llvm-dev

unread,
Jan 26, 2022, 8:20:59 AM1/26/22
to llvm-dev, Florian Hahn, Bardia Mahjour

Hi, 

We are caching TripCount of a loop in  "EpilogueLoopVectorizationInfo.TripCount"  during first pass ( Main Loop) vectorization. 
I see we use the cached value at "emitMinimumVectorEpilogueIterCountCheck" during the second pass( Epilog Vector loop).

--Snip--
BasicBlock *
EpilogueVectorizerEpilogueLoop::emitMinimumVectorEpilogueIterCountCheck(
    Loop *L, BasicBlock *Bypass, BasicBlock *Insert) {

  assert(EPI.TripCount &&
         "Expected trip count to have been safed in the first pass.");
  assert(
      (!isa<Instruction>(EPI.TripCount) ||
       DT->dominates(cast<Instruction>(EPI.TripCount)->getParent(), Insert)) &&
      "saved trip count does not dominate insertion point.");
  Value *TC = EPI.TripCount;
 --Snip--

Can  that be used in other places also in second pass?   (TripCount = EPI.TripCount).  In the trunk I see we are recomputing again via getOrCreateTripCount(L)  during the second pass (Epilog vector loop) 
is it guaranteed that trip count will always dominate the epilog vector loop  and scalar loop ?

regards,
Venkat.

Bardia Mahjour via llvm-dev

unread,
Jan 26, 2022, 3:45:04 PM1/26/22
to Venkataramanan Kumar, llvm-dev

Hi,



> Can  that be used in other places also in second pass?   (TripCount = EPI.TripCount).

Perhaps it could, but I'm not sure why we'd do that? EPI is only available to the interfaces specifically extended for epilogue vectorization, and overwriting TripCount from EPI seems awkward, especially because `getOrCreateTripCount` takes a loop as input.


> is it guaranteed that trip count will always dominate the epilog vector loop  and scalar loop ?

The `getOrCreateTripCount` for the original loop is currently first called when generating the first set of tripcount checks in a basic block that dominates the main vector, epilogue vector and the scalar loops. This diagram might help: https://llvm.org/docs/Vectorizers.html#epilogue-vectorization

BTW, the community is migrating away from the dev-mailing list in favour of Discourse. Please post future questions to https://llvm.discourse.group/c/ir-optimizations.

Bardia Mahjour
Compiler Optimizations
IBM Toronto Software Lab


Inactive hide details for "Venkataramanan Kumar" ---2022/01/26 08:20:58 AM---Hi, We are caching TripCount of a loop in"Venkataramanan Kumar" ---2022/01/26 08:20:58 AM---Hi, We are caching TripCount of a loop in

Reply all
Reply to author
Forward
0 new messages