[llvm] [AArch64] Fold uaddv(a) to a if the all lanes except the 0th are zeros (PR #159086)

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 16 11:47:16 PDT 2025


================
@@ -493,3 +493,58 @@ entry:
   ret i128 %arg1
 }
 
+define i16 @addv_zero_lanes_v4i16(ptr %arr)  {
+; CHECK-SD-LABEL: addv_zero_lanes_v4i16:
+; CHECK-SD:       // %bb.0:
+; CHECK-SD-NEXT:    ldrb w0, [x0]
+; CHECK-SD-NEXT:    ret
+;
+; CHECK-GI-LABEL: addv_zero_lanes_v4i16:
+; CHECK-GI:       // %bb.0:
+; CHECK-GI-NEXT:    ldrb w8, [x0]
+; CHECK-GI-NEXT:    fmov d0, x8
+; CHECK-GI-NEXT:    addv h0, v0.4h
+; CHECK-GI-NEXT:    fmov w0, s0
+; CHECK-GI-NEXT:    ret
+  %v = load i64, ptr %arr
+  %and = and i64 %v, 255
+  %vec = bitcast i64 %and to <4 x i16>
+  %r = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %vec)
+  ret i16 %r
+}
+
+define i8 @addv_zero_lanes_v8i8(ptr %arr)  {
----------------
davemgreen wrote:

It doesn't apply at the moment, but can you add a v16i8 and maybe v8i16/v4i32/v2i32 tests too?

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


More information about the llvm-commits mailing list