Skip to content

Commit 68976ba

Browse files
authored
pulley: Fix mistakes in compare-with-immediate (bytecodealliance#9870)
This commit fixes a few mistakes that were introduced in bytecodealliance#9863. Specifically when lowering `Cond.If...` and the arguments needed swapping the condition was also inverted by accident. More `*.clif` runtests were added to catch this case and expose it. Additionally Pulley now has lowering for all the `FloatCC` orderings to be able to run the `select.clif` runtest which primarily exposed the issue.
1 parent a179f95 commit 68976ba

24 files changed

+652
-10
lines changed

cranelift/codegen/src/isa/pulley_shared/lower.isle

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,13 @@
727727
(rule (lower_fcmp $F32 (FloatCC.LessThanOrEqual) a b) (pulley_flteq32 a b))
728728
(rule (lower_fcmp $F64 (FloatCC.LessThanOrEqual) a b) (pulley_flteq64 a b))
729729

730-
;; NB: Pulley doesn't have lowerings for `Ordered` or `Unordered` `FloatCC`
731-
;; conditions as that's not needed by wasm at this time.
730+
;; Ordered == !a.is_nan() && !b.is_nan()
731+
(rule (lower_fcmp ty (FloatCC.Ordered) a b)
732+
(pulley_xband32 (lower_fcmp ty (FloatCC.Equal) a a) (lower_fcmp ty (FloatCC.Equal) b b)))
733+
734+
;; OrderedNotEqual == a < b || a > b
735+
(rule (lower_fcmp ty (FloatCC.OrderedNotEqual) a b)
736+
(pulley_xbor32 (lower_fcmp ty (FloatCC.LessThan) a b) (lower_fcmp ty (FloatCC.GreaterThan) a b)))
732737

733738
;; Pulley doesn't have instructions for `>` and `>=`, so we have to reverse the
734739
;; operation.
@@ -737,6 +742,11 @@
737742
(rule (lower_fcmp ty (FloatCC.GreaterThanOrEqual) a b)
738743
(lower_fcmp ty (FloatCC.LessThanOrEqual) b a))
739744

745+
;; For other `Unordered*` comparisons generate its complement and invert the result.
746+
(rule -1 (lower_fcmp ty cc a b)
747+
(if-let true (floatcc_unordered cc))
748+
(pulley_xbxor32_s8 (lower_fcmp ty (floatcc_complement cc) a b) 1))
749+
740750
;;;; Rules for `load` and friends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
741751

742752
(decl amode (Value Offset32) Amode)
@@ -937,13 +947,13 @@
937947

938948
;; Note the operand swaps here
939949
(rule (emit_cond (Cond.IfXsgt32I32 src1 src2))
940-
(pulley_xslteq32 (imm $I32 (i64_as_u64 (i32_as_i64 src2))) src1))
941-
(rule (emit_cond (Cond.IfXsgteq32I32 src1 src2))
942950
(pulley_xslt32 (imm $I32 (i64_as_u64 (i32_as_i64 src2))) src1))
951+
(rule (emit_cond (Cond.IfXsgteq32I32 src1 src2))
952+
(pulley_xslteq32 (imm $I32 (i64_as_u64 (i32_as_i64 src2))) src1))
943953
(rule (emit_cond (Cond.IfXugt32I32 src1 src2))
944-
(pulley_xulteq32 (imm $I32 (u32_as_u64 src2)) src1))
945-
(rule (emit_cond (Cond.IfXugteq32I32 src1 src2))
946954
(pulley_xult32 (imm $I32 (u32_as_u64 src2)) src1))
955+
(rule (emit_cond (Cond.IfXugteq32I32 src1 src2))
956+
(pulley_xulteq32 (imm $I32 (u32_as_u64 src2)) src1))
947957

948958
(rule (emit_cond (Cond.IfXeq64I32 src1 src2))
949959
(pulley_xeq64 src1 (imm $I64 (i64_as_u64 (i32_as_i64 src2)))))
@@ -960,13 +970,13 @@
960970

961971
;; Note the operand swaps here
962972
(rule (emit_cond (Cond.IfXsgt64I32 src1 src2))
963-
(pulley_xslteq64 (imm $I64 (i64_as_u64 (i32_as_i64 src2))) src1))
964-
(rule (emit_cond (Cond.IfXsgteq64I32 src1 src2))
965973
(pulley_xslt64 (imm $I64 (i64_as_u64 (i32_as_i64 src2))) src1))
974+
(rule (emit_cond (Cond.IfXsgteq64I32 src1 src2))
975+
(pulley_xslteq64 (imm $I64 (i64_as_u64 (i32_as_i64 src2))) src1))
966976
(rule (emit_cond (Cond.IfXugt64I32 src1 src2))
967-
(pulley_xulteq64 (imm $I64 (u32_as_u64 src2)) src1))
968-
(rule (emit_cond (Cond.IfXugteq64I32 src1 src2))
969977
(pulley_xult64 (imm $I64 (u32_as_u64 src2)) src1))
978+
(rule (emit_cond (Cond.IfXugteq64I32 src1 src2))
979+
(pulley_xulteq64 (imm $I64 (u32_as_u64 src2)) src1))
970980

971981
;;;; Rules for `bitcast` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
972982

cranelift/filetests/filetests/runtests/fcmp-ge.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ target aarch64
66
target s390x
77
target riscv64
88
target riscv64 has_c has_zcb
9+
target pulley32
10+
target pulley32be
11+
target pulley64
12+
target pulley64be
913

1014
function %fcmp_ge_f32(f32, f32) -> i8 {
1115
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-one.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_one_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-ord.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_ord_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-ueq.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_ueq_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-uge.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_uge_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-ugt.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_ugt_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-ule.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_ule_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-ult.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913
function %fcmp_ult_f32(f32, f32) -> i8 {
1014
block0(v0: f32, v1: f32):

cranelift/filetests/filetests/runtests/fcmp-uno.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ target x86_64 has_avx
55
target s390x
66
target riscv64
77
target riscv64 has_c has_zcb
8+
target pulley32
9+
target pulley32be
10+
target pulley64
11+
target pulley64be
812

913

1014
function %fcmp_uno_f32(f32, f32) -> i8 {

0 commit comments

Comments
 (0)