Skip to content

fix(mir-importer): lower is_val_statically_known to false - #1359

Open
Arthur031221 wants to merge 1 commit into
NVIDIA:mainfrom
Arthur031221:fix/is-val-statically-known
Open

Arthur031221 wants to merge 1 commit into
NVIDIA:mainfrom
Arthur031221:fix/is-val-statically-known

Conversation

@Arthur031221

Copy link
Copy Markdown

Summary

A kernel that calls integer pow, checked_pow, overflowing_pow, saturating_pow, wrapping_pow, ilog or checked_ilog fails to compile today, with:

Translation failed: core::num::<impl i32>::checked_pow: [...] Compilation error: invalid input program.
       Unsupported construct: rustc intrinsic `std::intrinsics::is_val_statically_known` is not yet supported on the device

libcore's checked_pow, overflowing_pow and checked_ilog branch on is_val_statically_known, and the other functions above call one of those three (u32::pow fails in overflowing_pow, u32::ilog in checked_ilog). The importer has no arm for the intrinsic, so it hits the generic rejection. f32::powi is not affected.

The intrinsic is allowed to return false for any argument, so this lowers it to a constant false and libcore takes its general path.

With a constant false, a base known at compile time (such as 2u32.pow(n)) takes the general loop instead of libcore's shift shortcut. Keeping the shortcut would mean lowering to llvm.is.constant, which nothing in the lowering emits today, so I left that out of this change.

Fixes #1358.

Changes

  • mir-importer: dispatch core::intrinsics::is_val_statically_known (and the std:: spelling) next to cold_path, through a new emit_bool_constant_intrinsic helper that writes a constant i1 to the call destination and branches to the target block.
  • checked_arith example: new pow_family kernel covering pow on u64, checked_pow on i32, overflowing_pow on u32, saturating_pow on u8, wrapping_pow on i16, ilog(10) and checked_ilog(10), compared against the same expressions on the host. Inputs include a zero exponent, negative bases with odd exponents, and overflowing cases (7^12 and 46341^2 for i32).

slice::fill on integers wider than a byte also calls is_val_statically_known (u8 and i8 go straight to write_bytes). With this change it gets past that point, but still fails later on write_bytes, which the device does not support yet. That is a separate gap and is not touched here.

Testing

  • cargo oxide run checked_arith on an RTX 5090: prints PASS: integer pow family and ilog, also with CUDA_OXIDE_NO_OPT=1. With the two mir-importer files restored from main, the example fails to compile with the error above.

  • The test recipe's cargo test --all-targets package list: 3908 passed, 0 failed, 10 ignored, same as on main. The test-cuda recipe: 1505 passed, 0 failed, 1 ignored.

  • cargo oxide fmt --check, workspace and backend clippy with -D warnings, and clippy in examples/checked_arith pass. The check-guards scripts pass except check-example-license-policy.sh, which needs cargo-deny and I don't have it installed. This change adds no dependencies.

  • just check passes (the local mirror of CI: fmt, clippy, tests, guards, docs)

  • cargo oxide run <example> passes, or scripts/smoketest.sh -o '^<example>$'

  • New example added (if applicable)

Checklist

  • All commits signed off (git commit -s)
  • SPDX headers on new source files (no new source files)

libcore's integer checked_pow, overflowing_pow and checked_ilog branch
on core::intrinsics::is_val_statically_known, and integer pow, ilog,
saturating_pow and wrapping_pow reach it through them. The importer had
no arm for the intrinsic, so a kernel calling any of these failed to
compile with "rustc intrinsic `std::intrinsics::is_val_statically_known`
is not yet supported on the device".

The intrinsic may return false for any argument, so emit a constant
false and let libcore take its general path.

The checked_arith example gains a pow_family kernel checked against
the host results.

Signed-off-by: Arthur031221 <levi74108520963@gmail.com>
@Arthur031221
Arthur031221 force-pushed the fix/is-val-statically-known branch from 3b95bbb to 12997f7 Compare October 2, 2026 08:16
@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

This branch has not been deployed

No deployments
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.

Integer pow, checked_pow and ilog fail to compile: is_val_statically_known unsupported

1 participant