[llvm] [RISCV] Handle undef passthrus in foldVMV_V_V (PR #106943)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 22:44:18 PDT 2024


================
@@ -194,3 +194,14 @@ define <vscale x 2 x i32> @unfoldable_mismatched_sew(<vscale x 2 x i32> %passthr
   %b = call <vscale x 2 x i32> @llvm.riscv.vmv.v.v.nxv2i32(<vscale x 2 x i32> %passthru, <vscale x 2 x i32> %a.bitcast, iXLen %avl)
   ret <vscale x 2 x i32> %b
 }
+
+define <vscale x 1 x i64> @undef_passthru(<vscale x 1 x i64> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, iXLen %avl) {
+; CHECK-LABEL: undef_passthru:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetvli zero, a0, e64, m1, tu, ma
+; CHECK-NEXT:    vadd.vv v8, v9, v10
+; CHECK-NEXT:    ret
+  %a = call <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64(<vscale x 1 x i64> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, iXLen %avl)
----------------
lukel97 wrote:

Yup, that's exactly what I did in #106840. I added a new peephole that doesn't check Src, but I closed it because I thought it was too similar to foldVMV_V_V.

However I've since realised that if the vmv.v.v passthru is undef, then we can still relax Src's policy to be tail agnostic if vmv.v.s tail subsumes it. E.g. if we have

```
vsetvli zero, a0, e64, m1, tu, ma
vadd.vv v8, v9, v10
vsetvli zero, zero, e64, m1, ta, ma
vmv.v.v v8, v8
```

We should actually be able to fold it into:

```
vsetvli zero, a0, e64, m1, ta, ma
vadd.vv v8, v9, v10
```

Hence why I moved it back into foldVMV_V_V, so it could take advantage of #105788.

But I completely agree with you here that this is could be much cleaner. I'm going to try again to do this as a separate peephole, but explicitly relaxing Src's policy if possible.

https://github.com/llvm/llvm-project/pull/106943


More information about the llvm-commits mailing list