<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106735>106735</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error in RISC-V Vector Peephole Optimization (riscv-vector-peephole) pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
loralb
</td>
</tr>
</table>
<pre>
Running ` llc -mtriple=riscv64 -mattr=+v` with this snippet as input
```
define void @foo(ptr %a, i32 zeroext %avl) {
%sp = call <vscale x 8 x i8> @llvm.stepvector()
%evl = call i32 @llvm.experimental.get.vector.length(i32 %avl, i32 8, i1 true)
call void @llvm.vp.store(<vscale x 8 x i8> %sp, ptr %a, <vscale x 8 x i1> splat(i1 true), i32 %evl)
ret void
}
declare <vscale x 8 x i8> @llvm.stepvector()
declare void @llvm.vp.store(<vscale x 8 x i8>, ptr, <vscale x 8 x i1>, i32)
declare i32 @llvm.experimental.get.vector.length(i32, i32, i1)
```
causes a crash. I do believe the problem is a use-before-def one caused by the `riscv-vector-peephole` pass, because adding the `-print-changed` flag I can see:
```
*** IR Dump After RISC-V DAG->DAG Pattern Instruction Selection (riscv-isel) on foo ***
# Machine code for function foo: IsSSA, TracksLiveness
Function Live Ins: $x10 in %0, $x11 in %1
bb.0 (%ir-block.0):
liveins: $x10, $x11
%1:gprnox0 = COPY $x11
%0:gpr = COPY $x10
%2:vr = PseudoVID_V_M1 $noreg(tied-def 0), -1, 3, 1
%3:gprnox0 = PseudoVSETVLI %1:gprnox0, 192, implicit-def dead $vl, implicit-def dead $vtype
PseudoVSE8_V_M1 killed %2:vr, %0:gpr, killed %3:gprnox0, 3 :: (store unknown-size into %ir.a, align 8)
PseudoRET
# End machine code for function foo.
*** IR Dump After Finalize ISel and expand pseudo-instructions (finalize-isel) on foo omitted because no change ***
*** IR Dump After RISC-V Vector Peephole Optimization (riscv-vector-peephole) on foo ***
# Machine code for function foo: IsSSA, TracksLiveness
Function Live Ins: $x10 in %0, $x11 in %1
bb.0 (%ir-block.0):
liveins: $x10, $x11
%1:gprnox0 = COPY $x11
%0:gpr = COPY $x10
%2:vr = PseudoVID_V_M1 $noreg(tied-def 0), %3:gprnox0, 3, 1
%3:gprnox0 = PseudoVSETVLI %1:gprnox0, 192, implicit-def dead $vl, implicit-def dead $vtype
PseudoVSE8_V_M1 killed %2:vr, %0:gpr, killed %3:gprnox0, 3 :: (store unknown-size into %ir.a, align 8)
PseudoRET
# End machine code for function foo.
...
```
where the `PseudoVID` got its vector lenght argument changed from VLMax (`-1`) to `%3:gprnox0`, which is defined on the next line.
/cc @lukel97
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk1v2zgQ_TX0ZSBBovx58MGN48JAiwZJEWBPBSWNJG5oUiApxe2vXwwlx46TLdAt9lbAsGVq5s0bct5whHOy1ohrNvvAZtuJ6Hxj7FoZK1Q-yU35fX3faS11DWyegFIFRAdvZauQZVsrXdHPpxAdhPeWZVvGP_Rk9yx9A76RDpyWbYsehAOp286zZMuSDZsn4yf8LbGSGqE3sgQ2TSpjGF-23gLjM8H4DciMww-0Bo8-rPWK8RWwxYfBH2jRtcCyLRRCKWDZTe8KoRCOsIQjyCXLbglaqf4QO49tj4U3lvEl46sLEOzVGYWinnzw2KKVB9ReqLhGHw8AsUJd-4bxZTAeqQ2El-EhBW87vIgSoE-pBuy-jZ03FonN-8QpO0K73JM3pimZulYJT3TOcUc6Q3YXRCz6wGM8ksV2fBiPpFDC4n_ayZPvLyU5pvevmY1pvAnyq4f0gkNn84J2VZCF6Bw6EFBY4ZoY9lAayFFJ7BF8g9Bakys8gCSjzmGUY2UsRiVWYDRCACgh_x6s2TwJUokGPlGL2DZGIUmlFc4RmRyDD4iyJLWNblFrpfZR0QhdY0n2lRI17KEQGhwiyzbvJsD4-IH9PWy7QwubyqOF-_3DTfQI283HiGW3281HuBPeo9Ww187brvDSaHhAh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