[llvm] [WebAssembly] Fold any/alltrue SIMD boolean reductions with eqz (PR #184704)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 08:06:07 PST 2026
================
@@ -44,6 +44,30 @@ define i32 @any_v16i8_eq(<16 x i8> %x) {
ret i32 %c
}
+; CHECK-LABEL: any_v16i8_eq_0:
+; CHECK-NEXT: .functype any_v16i8_eq_0 (v128) -> (i32){{$}}
+; CHECK-NEXT: v128.any_true $push[[T:[0-9]+]]=, $0{{$}}
+; CHECK-NEXT: i32.eqz $push[[R:[0-9]+]]=, $pop[[T]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define i32 @any_v16i8_eq_0(<16 x i8> %x) {
+ %a = call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+ %b = icmp eq i32 %a, 0
+ %c = zext i1 %b to i32
+ ret i32 %c
+}
+
+; CHECK-LABEL: any_v16i8_ne_1:
+; CHECK-NEXT: .functype any_v16i8_ne_1 (v128) -> (i32){{$}}
+; CHECK-NEXT: v128.any_true $push[[T:[0-9]+]]=, $0{{$}}
+; CHECK-NEXT: i32.eqz $push[[R:[0-9]+]]=, $pop[[T]]{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+define i32 @any_v16i8_ne_1(<16 x i8> %x) {
+ %a = call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
+ %b = icmp ne i32 %a, 1
+ %c = zext i1 %b to i32
+ ret i32 %c
+}
----------------
aheejin wrote:
Nit: How about moving this after `any_v16i8_ne`? Current order is ne-eq-eq-ne, so...
Also changing the existing functions' name to `any_v16i8_ne_0` and `any_v16i8_eq_1` would be more consistent. The same for other tests.
https://github.com/llvm/llvm-project/pull/184704
More information about the llvm-commits
mailing list