Skip to content

Fix LLVM 23 compatibility: replace removed NoNaNsFPMath/NoInfsFPMath TargetOptions fields#9029

Merged
alexreinking merged 3 commits intoautomated/upgrade-halide-llvmfrom
copilot/sub-pr-9028
Mar 15, 2026
Merged

Fix LLVM 23 compatibility: replace removed NoNaNsFPMath/NoInfsFPMath TargetOptions fields#9029
alexreinking merged 3 commits intoautomated/upgrade-halide-llvmfrom
copilot/sub-pr-9028

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

llvm::TargetOptions::NoNaNsFPMath and NoInfsFPMath were removed in LLVM 23, causing build failures across all platforms when building with halide-llvm 23.0.0.dev85505+g69780be1. The proper replacement is to use LLVM function attributes "no-nans-fp-math"="true" and "no-infs-fp-math"="true", which convey the same information at the per-function level.

Changes

  • src/CodeGen_Internal.cpp (get_target_options): Add #if LLVM_VERSION < 230 guards around options.NoInfsFPMath and options.NoNaNsFPMath for backward compatibility with LLVM < 23.

  • src/CodeGen_Internal.cpp (set_function_attributes_from_halide_target_options): Add "no-nans-fp-math" and "no-infs-fp-math" function attributes when the module is in fast-math mode (i.e., !per_instruction_fast_math_flags). This is the LLVM 23 replacement for the removed TargetOptions fields, and also resolves a pre-existing FIXME comment suggesting this migration.

  • src/CodeGen_PTX_Dev.cpp (init_module): Add #if LLVM_VERSION < 230 guards around options.NoNaNsFPMath and options.NoInfsFPMath. Also set the halide_per_instruction_fast_math_flags module flag on the PTX GPU module so that set_function_attributes_from_halide_target_options correctly determines whether to apply the fast-math function attributes to PTX kernel functions (previously this flag was only set on host modules).


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…SION < 230

Co-authored-by: alexreinking <169273+alexreinking@users.noreply.github.com>
Copilot AI changed the title [WIP] Upgrade halide-llvm to 23.0.0.dev85505+g69780be1 Fix LLVM 23 compatibility: guard removed NoNaNsFPMath field Mar 15, 2026
Copilot AI requested a review from alexreinking March 15, 2026 10:41
@alexreinking
Copy link
Copy Markdown
Member

@copilot what is the replacement for this flag? Is there anything else we need to update to use a replacement API?

…ment for removed TargetOptions fields

Co-authored-by: alexreinking <169273+alexreinking@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 15, 2026

@copilot what is the replacement for this flag? Is there anything else we need to update to use a replacement API?

The replacement for NoNaNsFPMath and NoInfsFPMath in TargetOptions is to use LLVM function attributes "no-nans-fp-math"="true" and "no-infs-fp-math"="true". These attributes serve the same purpose at the per-function level.

I've implemented the replacement in commit bef5472:

  • In set_function_attributes_from_halide_target_options(), we now add "no-nans-fp-math" and "no-infs-fp-math" function attributes when the module is in fast-math mode (i.e., !per_instruction_fast_math_flags). This resolves the FIXME comment that was already noting this migration.
  • In CodeGen_PTX_Dev::init_module(), I added the halide_per_instruction_fast_math_flags module flag to the PTX GPU module so the function attribute logic can read it correctly (previously this flag was only set on host modules).

The #if LLVM_VERSION < 230 guards remain for the TargetOptions fields to keep backward compatibility with LLVM < 23.

Copilot AI changed the title Fix LLVM 23 compatibility: guard removed NoNaNsFPMath field Fix LLVM 23 compatibility: replace removed NoNaNsFPMath/NoInfsFPMath TargetOptions fields Mar 15, 2026
@alexreinking alexreinking marked this pull request as ready for review March 15, 2026 14:57
@alexreinking alexreinking merged commit a7e0dbd into automated/upgrade-halide-llvm Mar 15, 2026
17 checks passed
@alexreinking alexreinking deleted the copilot/sub-pr-9028 branch March 15, 2026 14:57
Comment thread src/CodeGen_Internal.cpp
// TargetOptions in favor of these per-function attributes.
bool per_instruction_fast_math_flags = get_modflag_bool(module, "halide_per_instruction_fast_math_flags");
if (!per_instruction_fast_math_flags) {
fn.addFnAttr("no-nans-fp-math", "true");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fishy. LLVM has been progressively removing these kinds of flags but I haven't seen us do this before. It's weird to have an LLVM API go from an enum to a magic string. Are you sure this is the correct fix?

@abadams
Copy link
Copy Markdown
Member

abadams commented Mar 15, 2026

This was indeed not the right fix (see #9039)

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.

3 participants