Skip to content
Prev Previous commit
Next Next commit
work
  • Loading branch information
kripken committed Feb 21, 2024
commit 29174f692edfbfefd5b9da32239bc0254c6077c4
6 changes: 3 additions & 3 deletions src/passes/DeNaN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ struct DeNaN : public WalkerPass<
if (expr->type == Type::f32) {
if (c && c->value.isNaN()) {
replacement = builder.makeConst(float(0));
} else {
} else if (!c) {
replacement = builder.makeCall(deNan32, {expr}, Type::f32);
}
} else if (expr->type == Type::f64) {
if (c && c->value.isNaN()) {
replacement = builder.makeConst(double(0));
} else {
} else if (!c) {
replacement = builder.makeCall(deNan64, {expr}, Type::f64);
}
} else if (expr->type == Type::v128) {
if (c && hasNaNLane(c)) {
uint8_t zero[16] = {};
replacement = builder.makeConst(Literal(zero));
} else {
} else if (!c) {
replacement = builder.makeCall(deNan128, {expr}, Type::v128);
}
}
Expand Down
7 changes: 3 additions & 4 deletions test/lit/passes/denan-simd.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (call $deNan128
;; CHECK-NEXT: (v128.const i32x4 0x00000001 0x00000002 0x00000003 0x00000004)
;; CHECK-NEXT: )
;; CHECK-NEXT: (v128.const i32x4 0x00000001 0x00000002 0x00000003 0x00000004)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
Expand All @@ -35,7 +33,7 @@
(func $foo128 (param $x v128) (result v128)
;; The incoming param will be de-naned.

;; This is not a NaN. (We do still emit a call for it atm, FIXME)
;; This is not a NaN.
(drop
(v128.const i32x4 0x00000001 0x00000002 0x00000003 0x00000004)
)
Expand All @@ -48,6 +46,7 @@
(v128.const i32x4 0x00000001 0xffffffff 0x00000003 0x00000004)
)

;; The result here will be de-naned.
(call $foo128 (local.get $x))
)
)
Expand Down
34 changes: 34 additions & 0 deletions test/lit/passes/denan.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

;; CHECK: (type $3 (func (param f32 f64)))

;; CHECK: (type $4 (func))

;; CHECK: (global $global$1 (mut f32) (f32.const 0))
(global $global$1 (mut f32) (f32.const nan))
;; CHECK: (global $global$2 (mut f32) (f32.const 12.34000015258789))
Expand Down Expand Up @@ -139,6 +141,38 @@
(drop (local.get $f))
(drop (local.get $d))
)

;; CHECK: (func $constants
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (f32.const 12.34000015258789)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (f32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (f64.const 12.34)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (f64.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $constants
;; Constants can be fixed up or left alone - we never need to add a call on
;; them.
(drop
(f32.const 12.34)
)
(drop
(f32.const nan)
)
(drop
(f64.const 12.34)
)
(drop
(f64.const nan)
)
)

;; CHECK: (func $tees (param $x f32) (result f32)
;; CHECK-NEXT: (local.set $x
;; CHECK-NEXT: (call $deNan32
Expand Down