Skip to content

How to use RV's outer loop vectorizer in your LLVM frontend

Simon Moll edited this page Oct 30, 2018 · 5 revisions

RV ships with an outer loop vectorizer pass. The vectorizer pass needs loop metadata to detect vectorizable loops. We lay out the steps below.

The outer-loop vectorizer pass

rv::addRVPasses(PM) adds all of RV's vectorization passes to the pipeline including this one.

Latch exit loops

RV will vectorize arbitrary reducible control inside the outer loops you want to vectorize. However, every loop that shall be vectorized needs to be a simple counting loop. Further, the loop needs to have a unique latch exit. That is, there is a unique latch block and the latch block contains the only loop exit of the loop.

Vectorization metadata

RV's outer-loop vectorizer relies on metadata hints to detect vectorizable loops. This is the same format used by Clang to communicate vectorization hints to LLVM's loop vectorizer. The metadata has the following structure:

; module level metadata
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.vectorize.enable", i1 true}
!13 = !{!"llvm.loop.vectorize.width", i32 16}

def foo () {
...
  ; terminator of loop latch
  br i1 %exitcond, label %for.body.exit, label %for.body.header  !llvm.loop !11
...
}

This metadata tells RV that the loop can be vectorized (llvm.loop.vectorize.enable) and that the maximal vectorization factor for this loop is 16 (llvm.loop.vectorize.width).

Next steps: improved integration

Reduction hints

RV has an integrated reduction analysis for value reductions (data-typed header phi nodes). Use rv::SetReductionHint(loopHeaderPhi, redKind) to set the reduction kind of a loop header phi. Reduction hints take precedence over automatic inference.

Support for critical sections

Encoding critical sections for RV

Clone this wiki locally