tlopex opened a new pull request, #20054: URL: https://github.com/apache/tvm/pull/20054
PR Description: This PR fixes NaN handling in floating-point `min` and `max` code generation. Previously, the ordered comparison caused a NaN in the left operand to be discarded, while a NaN in the right operand was preserved. For floating-point operands, this PR implements the following semantics: ```c max: (a > b || isnan(a)) ? a : b min: (a < b || isnan(a)) ? a : b ``` This preserves a NaN from either operand while retaining the existing behavior of selecting the second operand when the operands compare equal. For the C host backend, `a != a` is used as the NaN check: ```c (a > b || a != a) ? a : b (a < b || a != a) ? a : b ``` This compact form also produces better optimized code than the equivalent nested conditional expression. For LLVM, the lowering combines an ordered comparison with an unordered self-comparison and emits a single select. This avoids relying on `llvm.maximum`/`llvm.minimum`, whose signed-zero semantics differ from the existing TVM behavior and whose legalization may vary across LLVM targets. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
