[llvm] Extend vector.reduce.add and splat transform to scalable vectors (PR #161101)
Gábor Spaits via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 02:00:42 PDT 2025
================
@@ -467,15 +467,90 @@ define i2 @constant_multiplied_7xi2(i2 %0) {
ret i2 %4
}
-define i32 @negative_scalable_vector(i32 %0) {
-; CHECK-LABEL: @negative_scalable_vector(
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[TMP0:%.*]], i64 0
-; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <vscale x 4 x i32> [[TMP2]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[TMP3]])
+define i32 @reduce_add_splat_to_mul_vscale_4xi32(i32 %0) {
+; CHECK-LABEL: @reduce_add_splat_to_mul_vscale_4xi32(
+; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[DOTTR:%.*]] = trunc i64 [[TMP2]] to i32
+; CHECK-NEXT: [[TMP3:%.*]] = shl i32 [[DOTTR]], 2
+; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP0:%.*]], [[TMP3]]
; CHECK-NEXT: ret i32 [[TMP4]]
;
%2 = insertelement <vscale x 4 x i32> poison, i32 %0, i64 0
%3 = shufflevector <vscale x 4 x i32> %2, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
%4 = tail call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> %3)
ret i32 %4
}
+
+define i64 @reduce_add_splat_to_mul_vscale_4xi64(i64 %0) {
----------------
spaits wrote:
Alive2 doesn't seem to like these tests: https://alive2.llvm.org/ce/z/W6Tueq .
Usually when I do a syntax or semantic error it gives error code 255 and writes the compile error. But in this case it just gives error code 1 and no output.
The function signatures match. If I remove the body of the `src` it gives output. It says that it doesn't know the semantics of `@llvm.vscale.i64`.
https://github.com/llvm/llvm-project/pull/161101
More information about the llvm-commits
mailing list