Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

aarch64: implement ISLE lowering for bitselect.i128 (#14237)

Dsecurityc9f29a4e773b
diff --git a/cranelift/codegen/src/isa/aarch64/lower.isle b/cranelift/codegen/src/isa/aarch64/lower.isle
index e713d3c9e2..ba17125a07 100644
--- a/cranelift/codegen/src/isa/aarch64/lower.isle
+++ b/cranelift/codegen/src/isa/aarch64/lower.isle
@@ -2116,6 +2116,25 @@
(tmp2 Reg (bic ty y c)))
(orr ty tmp1 tmp2)))
+(attr rule bitselect_i128 (tag i128))
+(rule bitselect_i128 2 (lower (bitselect $I128 c x y))
+ (let ((c ValueRegs (put_in_regs c))
+ (x ValueRegs (put_in_regs x))
+ (y ValueRegs (put_in_regs y))
+ (c_lo Reg (value_regs_get c 0))
+ (c_hi Reg (value_regs_get c 1))
+ (x_lo Reg (value_regs_get x 0))
+ (x_hi Reg (value_regs_get x 1))
+ (y_lo Reg (value_regs_get y 0))
+ (y_hi Reg (value_regs_get y 1))
+ (tmp1_lo Reg (and_reg $I64 x_lo c_lo))
+ (tmp1_hi Reg (and_reg $I64 x_hi c_hi))
+ (tmp2_lo Reg (bic $I64 y_lo c_lo))
+ (tmp2_hi Reg (bic $I64 y_hi c_hi))
+ (res_lo Reg (orr $I64 tmp1_lo tmp2_lo))
+ (res_hi Reg (orr $I64 tmp1_hi tmp2_hi)))
+ (value_regs res_lo res_hi)))
+
(rule 1 (lower (bitselect (ty_vec128 ty) c x y))
(bsl ty c x y))
diff --git a/cranelift/filetests/filetests/isa/aarch64/bitselect-i128.clif b/cranelift/filetests/filetests/isa/aarch64/bitselect-i128.clif
new file mode 100644
index 0000000000..2d2d88aee5
--- /dev/null
+++ b/cranelift/filetests/filetests/isa/aarch64/bitselect-i128.clif
@@ -0,0 +1,29 @@
+test compile precise-output
+set unwind_info=false
+target aarch64
+
+function %f0(i128, i128, i128) -> i128 {
+block0(v0: i128, v1: i128, v2: i128):
+ v3 = bitselect v0, v1, v2
+ return v3
+}
+
+; VCode:
+; block0:
+; and x7, x2, x0
+; and x9, x3, x1
+; bic x11, x4, x0
+; bic x13, x5, x1
+; orr x0, x7, x11
+; orr x1, x9, x13
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; and x7, x2, x0
+; and x9, x3, x1
+; bic x11, x4, x0
+; bic x13, x5, x1
+; orr x0, x7, x11
+; orr x1, x9, x13
+; ret
diff --git a/cranelift/filetests/filetests/runtests/i128-bitselect.clif b/cranelift/filetests/filetests/runtests/i128-bitselect.clif
index 9277d290e2..28152a1872 100644
--- a/cranelift/filetests/filetests/runtests/i128-bitselect.clif
+++ b/cranelift/filetests/filetests/runtests/i128-bitselect.clif
@@ -1,6 +1,7 @@
test run
set opt_level=none
set enable_llvm_abi_extensions=true
+target aarch64
target x86_64
set enable_multi_ret_implicit_sret
target s390x