Skip to content
Open
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: 11 additions & 0 deletions cranelift/codegen/src/nan_canonicalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub fn do_nan_canonicalization(func: &mut Function, has_vector_support: bool) {
/// Returns true/false based on whether the instruction is a floating-point
/// arithmetic operation. This ignores operations like `fneg`, `fabs`, or
/// `fcopysign` that only operate on the sign bit of a floating point value.
///
/// Also matches `call` and `call_indirect` instructions that return a single
/// floating-point result, since external function calls (e.g. libcalls like
/// `%CeilF32`) can also produce nondeterministic NaN payloads.
fn is_fp_arith(pos: &mut FuncCursor, inst: Inst) -> bool {
match pos.func.dfg.insts[inst] {
InstructionData::Unary { opcode, .. } => {
Expand All @@ -48,6 +52,13 @@ fn is_fp_arith(pos: &mut FuncCursor, inst: Inst) -> bool {
|| opcode == Opcode::Fsub
}
InstructionData::Ternary { opcode, .. } => opcode == Opcode::Fma,
InstructionData::Call { .. } | InstructionData::CallIndirect { .. } => {
let results = pos.func.dfg.inst_results(inst);
results.len() == 1 && {
let ty = pos.func.dfg.value_type(results[0]);
ty.is_float() || ty == types::F32X4 || ty == types::F64X2
}
}
_ => false,
}
}
Expand Down
Loading