Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cranelift/codegen/src/nan_canonicalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::cursor::{Cursor, FuncCursor};
use crate::ir::condcodes::FloatCC;
use crate::ir::immediates::{Ieee32, Ieee64};
use crate::ir::immediates::{Ieee16, Ieee32, Ieee64, Ieee128};
use crate::ir::types::{self};
use crate::ir::{Function, Inst, InstBuilder, InstructionData, Opcode, Value};
use crate::opts::MemFlags;
Expand Down Expand Up @@ -90,6 +90,10 @@ fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst, has_vector_support: bool)
};

match val_type {
types::F16 => {
let canon_nan = pos.ins().f16const(Ieee16::NAN);
scalar_select(pos, canon_nan);
}
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::NAN);
if has_vector_support {
Expand All @@ -116,6 +120,11 @@ fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst, has_vector_support: bool)
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
types::F128 => {
let nan_const = pos.func.dfg.constants.insert(Ieee128::NAN.into());
let canon_nan = pos.ins().f128const(nan_const);
scalar_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test compile
set enable_nan_canonicalization=true
target riscv64 has_zfhmin has_zfh

function %fadd_f16(f16, f16) -> f16 {
block0(v0: f16, v1: f16):
v2 = fadd v0, v1
return v2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test compile
set enable_nan_canonicalization=true
target s390x

function %fadd_f128(i64, f128, f128) {
block0(v0: i64, v1: f128, v2: f128):
v3 = fadd v1, v2
store v3, v0
return
}