[llvm] [WebAssembly] [Backend] Combine and(X, shuffle(X, pow 2 mask)) to all true (PR #145108)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 11:31:54 PDT 2025
================
@@ -0,0 +1,47 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
+target triple = "wasm64"
+
+define i1 @reduce_and_to_all_true_16i8(<16 x i8> %0) {
+; CHECK-LABEL: reduce_and_to_all_true_16i8:
+; CHECK: .functype reduce_and_to_all_true_16i8 (v128) -> (i32)
+; CHECK-NEXT: # %bb.0:
+; CHECK-NEXT: i8x16.all_true $push0=, $0
+; CHECK-NEXT: return $pop0
+ %2 = icmp ne <16 x i8> %0, zeroinitializer
+ %3 = sext <16 x i1> %2 to <16 x i8>
+ %4 = bitcast <16 x i8> %3 to <4 x i32>
+ %5 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %4)
+ %6 = icmp ne i32 %5, 0
+ ret i1 %6
+}
----------------
badumbatish wrote:
hmm, I'm not sure where it comes from but if i remove the bitcast, then it'll produce i8x16 all_true but generates a few more lines. Will investigate more
```
define i1 @reduce_and_to_all_true_16i8(<16 x i8> %0) {
; CHECK-LABEL: reduce_and_to_all_true_16i8:
; CHECK: .functype reduce_and_to_all_true_16i8 (v128) -> (i32)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: i8x16.all_true $push0=, $0
; CHECK-NEXT: i32.const $push1=, 255
; CHECK-NEXT: i32.and $push2=, $pop0, $pop1
; CHECK-NEXT: i32.const $push3=, 0
; CHECK-NEXT: i32.ne $push4=, $pop2, $pop3
; CHECK-NEXT: return $pop4
%2 = icmp ne <16 x i8> %0, zeroinitializer
%3 = sext <16 x i1> %2 to <16 x i8>
%4 = tail call i8 @llvm.vector.reduce.and.v8i16(<16 x i8> %3)
%5 = icmp ne i8 %4, 0
ret i1 %5
}
```
https://github.com/llvm/llvm-project/pull/145108
More information about the llvm-commits
mailing list