Skip to content

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

Fix fmin f16 cprop rule using $F32 instead of $F16 (#12854)

Shun Kashiwac2abcc2a0796
diff --git a/cranelift/codegen/src/opts/cprop.isle b/cranelift/codegen/src/opts/cprop.isle
index a865449610..81a6273a08 100644
--- a/cranelift/codegen/src/opts/cprop.isle
+++ b/cranelift/codegen/src/opts/cprop.isle
@@ -403,7 +403,7 @@
(rule (simplify (fmin $F16 (f16const $F16 n) (f16const $F16 m)))
(if-let r (f16_min n m))
- (subsume (f16const $F32 r)))
+ (subsume (f16const $F16 r)))
(rule (simplify (fmin $F32 (f32const $F32 n) (f32const $F32 m)))
(if-let r (f32_min n m))
(subsume (f32const $F32 r)))
diff --git a/cranelift/filetests/filetests/egraph/cprop.clif b/cranelift/filetests/filetests/egraph/cprop.clif
index fe3741aae7..5a691e1606 100644
--- a/cranelift/filetests/filetests/egraph/cprop.clif
+++ b/cranelift/filetests/filetests/egraph/cprop.clif
@@ -484,6 +484,19 @@ block0:
; check: v4 = f16const -0.0
; check: return v4 ; v4 = -0.0
+function %f16_fmin_promotes_correctly() -> f64 {
+block0:
+ v1 = f16const 0x1.0p0
+ v2 = f16const 0x1.0p1
+ v3 = fmin v1, v2
+ v4 = fpromote.f64 v3
+ return v4
+}
+
+; check: v5 = f16const 0x1.000p0
+; check: v4 = fpromote.f64 v5 ; v5 = 0x1.000p0
+; check: return v4
+
function %f16_fmax() -> f16 {
block0:
v1 = f16const -0x1.5p6