Skip to content

[TIR] Fixup max/min with input containing NAN#19589

Open
actinks wants to merge 3 commits into
apache:mainfrom
actinks:users/actinks/fixup-fmax/fminNAN
Open

[TIR] Fixup max/min with input containing NAN#19589
actinks wants to merge 3 commits into
apache:mainfrom
actinks:users/actinks/fixup-fmax/fminNAN

Conversation

@actinks
Copy link
Copy Markdown

@actinks actinks commented May 19, 2026

llvm.minimum and llvm.maximum: Return NaN if one the arguments is NaN.
refs: https://llvm.org/docs/LangRef.html#floating-point-min-max-intrinsics-comparison

fixed #19579

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the LLVM code generation for minimum and maximum operations to use LLVM's CreateMinimum and CreateMaximum instructions for non-integer types. Feedback highlights that these instructions require LLVM 12 or later, so version guards are necessary to prevent compilation failures on older supported versions. It is also suggested to restrict these calls specifically to floating-point types for better type safety.

Comment thread src/target/llvm/codegen_llvm.cc Outdated
Comment thread src/target/llvm/codegen_llvm.cc Outdated
Comment thread src/target/llvm/codegen_llvm.cc Outdated
@actinks
Copy link
Copy Markdown
Author

actinks commented May 20, 2026

@tqchen The failing test case in ir_module.py is due to the LLVM backend lagging behind LLVM IR in its support for llvm.{min,max}imum.{f32,f64}. How should we handle this situation?
Related issue: llvm/llvm-project#53353

LLVM ERROR: Cannot select: 0x5d50add04bf0: f32 = fmaximum 0x5d50add04d28, ConstantFP:f32<0.000000e+00>, IRModule.CodeGenLLVM:0

The fmaximum instruction is supported in llvm 18.1.0 for x86-64 and in llvm 19.1.0 for i686.
proof:
X86-64: https://godbolt.org/z/b95xvbKxn
i686: https://godbolt.org/z/q39dr1bs9

@actinks actinks requested a review from tqchen May 20, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] maximum/minimum/relu/clip do not propagate NaN (IEEE 754 violation)

2 participants