Repository navigation
Report simd_reduce_max/min with a result type other than the lane type as unsupported - #5044
Conversation
|
@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 |
There was a problem hiding this comment.
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/minwhen the return type differs from the SIMD lane type. - Introduce a new expected test that exercises the unsupported behavior for
u8x4 -> u32andu8x4 -> 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
feliperodri
left a comment
There was a problem hiding this comment.
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:
…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).
model-checking#4950 is about SIMD comparisons, not reductions.
da2bcc0 to
658abbc
Compare
feliperodri
left a comment
There was a problem hiding this comment.
Thanks. The link now points to the generic issue page. I withdraw my point on the unclosed quote: expected files match by substring, and the ubuntu and macos-15-intel regression jobs pass with this test.
compile-timer-long fails in the analyzer step after normal timings, and the macos-14 jobs are cancelled by the runner. Neither comes from this change. Approving.
d048610

Follow-up to #4934, from @feliperodri's review there.
rustc rejects
simd_reduce_maxandsimd_reduce_minwhen 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 au8x4reduced into au32was 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 au8x4into au32and ani8and 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.