title: How do I use the RISC-V Vector (RVV) instructions in LLVM IR?
body: <p>In <a href="https://llvm.org/devmtg/2019-04/slides/TechTalk-Kruppe-Espasa-RISC-V_Vectors_and_LLVM.pdf" rel="nofollow noreferrer">this presentation</a> Kruppe and Espasa give an overview of the RISC-V Vector extension (RVV) and on <a href="https://llvm.org/devmtg/2019-04/slides/TechTalk-Kruppe-Espasa-RISC-V_Vectors_and_LLVM.pdf#page=16" rel="nofollow noreferrer">slide 16</a> they show LLVM IR samples which use the vector instructions through intrinsic functions, such as:</p>
  <pre><code>%vl = call i32 @llvm.riscv.vsetvl(i32 8)
  </code></pre>
  <p>At the time of the talk (April 2019) LLVM support for the V extension was developed out-of-tree at <a href="https://github.com/hanna-kruppe/rvv-llvm" rel="nofollow noreferrer">https://github.com/hanna-kruppe/rvv-llvm</a>. However, that repository is archived now and the README file indicates that it is outdated since support for the RISC-V V extension is now developed upstream. I assume that this means that the features are now available from LLVM master at <a href="https://github.com/llvm/llvm-project" rel="nofollow noreferrer">https://github.com/llvm/llvm-project</a>.</p>
  <p>However, when I pull the current master and build it and try to compile the sample code with <code>llc</code> (specifying the target with <code>--mtriple=riscv32-unkown-none-rv32imv</code>), I get following error:</p>
  <pre><code>error: ../llvm-project/build/bin/llc: test.ll:4:18: error: use of undefined value '@llvm.riscv.vsetvl'
  </code></pre>
  <p>It seems that the V extension is available, since <code>llc -march=riscv32 -mattr=help</code> lists it:</p>
  <pre><code>Available features for this target:
  ...
    experimental-v           - 'V' (Vector Instructions).
  </code></pre>
  <p>Do I have to explicitly enable target features that are marked as experimental? Are these vector intrinsics shown in the slides even present in the upstream version? If yes, how do I use them? If no, how do I then use vector instructions in LLVM IR?</p>
  <hr />
  <p>Follow-up: in <a href="http://lists.llvm.org/pipermail/llvm-dev/2018-September/126446.html" rel="nofollow noreferrer">this post</a> Eli Friedman explains that target-specific intrinsics should be defined in <code>include/llvm/IR/IntrinsicsRISCV.td</code>, and indeed in the <a href="https://github.com/hanna-kruppe/rvv-llvm" rel="nofollow noreferrer">archived out-of-tree repository</a> that file contains some <a href="https://github.com/hanna-kruppe/rvv-llvm/blob/rvv-2018-11-01/include/llvm/IR/IntrinsicsRISCV.td#L40" rel="nofollow noreferrer">vector-specific intrinsics</a> which are not present in <a href="https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/IR/IntrinsicsRISCV.td" rel="nofollow noreferrer">the upstream version</a>. If these intrinsics have not been ported upstream, what is then the correct way to use the RISC-V vector instructions?</p>