Summary: handle NaN costs more carefully Reviewed-by: kvn, never
Summary: rematerializing nodes results in incorrect inputs Reviewed-by: rasbold