Skip to content

Report simd_reduce_max/min with a result type other than the lane type as unsupported - #5044

Open
srivatsansamraj wants to merge 2 commits into
model-checking:mainfrom
srivatsansamraj:simd-reduce-return-type
Open

srivatsansamraj wants to merge 2 commits into
model-checking:mainfrom
srivatsansamraj:simd-reduce-return-type

Conversation

@srivatsansamraj

Copy link
Copy Markdown
Contributor

Follow-up to #4934, from @feliperodri's review there.

rustc rejects simd_reduce_max and simd_reduce_min when the result type is not the lane type (E0511: expected return type 'u8' (element of input 'u8x16')), but that check lives in rustc's codegen backend, which Kani replaces. Kani accepted such a call and cast the result, so a u8x4 reduced into a u32 was verified. No crate that compiles with rustc reaches this, but autoharness can, through a generic helper.

This reports those calls as an unsupported construct, the way the SIMD comparisons handle an invalid mask type since #4950. Reductions with the lane type are unchanged.

Testing: a new expected test, simd-reduce-result-type, reduces a u8x4 into a u32 and an i8 and expects both harnesses to fail as unsupported. With the check removed, both harnesses verify and the test fails. The existing reduction tests (simd-reduce-float, Intrinsics/SIMD/Reduction) still pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@srivatsansamraj
srivatsansamraj requested review from a team as code owners October 22, 2026 07:31
@srivatsansamraj

Copy link
Copy Markdown
Contributor Author

@CYJ904 @Tianshu-Huang @wodex1nhaoIeng @acearyanarun for review. Felipe's follow-up from #4934: if a harness reduces a SIMD vector into a type that isn't its lane type (say u8 lanes into a u32), rustc refuses it, but Kani used to accept it and verify the harness. Now Kani reports it as unsupported, the same way it handles bad mask types in SIMD comparisons. One check in codegen_simd_reduce_max_min and one test.

@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Oct 22, 2026
@feliperodri feliperodri added [C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-Autoharness Issue related to autoharness subcommand labels Nov 6, 2026
@feliperodri feliperodri added this to the Autoharness milestone Nov 6, 2026
@feliperodri feliperodri removed the Z-Autoharness Issue related to autoharness subcommand label Nov 6, 2026
@feliperodri feliperodri removed this from the Autoharness milestone Nov 6, 2026
@feliperodri
feliperodri requested a balanced review from Copilot November 6, 2026 18:56
@feliperodri feliperodri self-assigned this Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Adds a guard to treat simd_reduce_max/min calls with a non-lane return type as unsupported in Kani, matching rustc’s restriction and preventing autoharness-generated cases from being (incorrectly) verified.

Changes:

  • Add a codegen check rejecting simd_reduce_max/min when the return type differs from the SIMD lane type.
  • Introduce a new expected test that exercises the unsupported behavior for u8x4 -> u32 and u8x4 -> i8.
  • Add expected output capturing the two harness failures.
File Description
tests/​expected/​intrinsics/​simd-reduce-result-type/​main.rs New regression test invoking reductions with mismatched return types.
tests/​expected/​intrinsics/​simd-reduce-result-type/​expected Expected failure output for the new regression test.
kani-compiler/​src/​codegen_cprover_gotoc/​codegen/​intrinsic.rs Adds the unsupported-construct check and reuses computed return type for casting.

Review effort: Lite

"`{intrinsic_str}` with the result type `{ret_ty}` (lane type `{lane_ty}`)"
),
loc,
"https://github.com/model-checking/kani/issues/4950",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 658abbc43: it links the generic issue page now.

Comment on lines +1 to +4
Status: FAILURE\
Description: "`simd_reduce_max` with the result type `u32` (lane type `u8`) is not currently supported by Kani
Status: FAILURE\
Description: "`simd_reduce_min` with the result type `i8` (lane type `u8`) is not currently supported by Kani

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the multi-line format of expected files, and the test passes with it.

@feliperodri feliperodri left a comment

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.

The fix is small and correct: a reduction into a type other than the lane type becomes an unsupported construct, and both cases fail in the test.

Before merge:

  1. The link points to #4950, which covers SIMD comparisons. This case is about reduction return types, so link to #4934 or a new issue.
  2. The Description: lines in expected open a quote and never close it. Close it, to match the other expected files.
  3. Six jobs are cancelled. Please re-run them.

…e as unsupported

rustc rejects these with E0511 in its codegen backend, which Kani replaces, so Kani accepted them and
cast the result: a u8x4 reduced into a u32 was verified. Report them as an unsupported construct, as
the SIMD comparisons do for an invalid mask (model-checking#4950).
@srivatsansamraj
srivatsansamraj force-pushed the simd-reduce-return-type branch from da2bcc0 to 658abbc Compare November 7, 2026 06:21

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

[C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants