Skip to content

Default slang-test compiler invocations to -O0#11805

Open
jkwak-work wants to merge 10 commits into
shader-slang:masterfrom
jkwak-work:disable-spv-opt-in-slang-test
Open

Default slang-test compiler invocations to -O0#11805
jkwak-work wants to merge 10 commits into
shader-slang:masterfrom
jkwak-work:disable-spv-opt-in-slang-test

Conversation

@jkwak-work

@jkwak-work jkwak-work commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Fixes #11804

Motivation

Release slang-test runs spend substantial time compiling tests with optimization enabled even though most tests only need stable codegen or execution coverage. In the measured Release build, defaulting test compiler invocations to -O0 reduced a full run from 34 min 9 sec to 11 min 24 sec.

The SPIR-V tests also become less sensitive to spirv-opt output changes. When SPIR-V submodules are updated, optimizer differences can otherwise change expected output for tests that do not actually mean to exercise optimized SPIR-V. Skipping the optimizer by default makes those updates less noisy, while optimization-sensitive tests can still opt in explicitly.

Proposed solution

slang-test now appends a default -O0 when it builds a Slang compiler command line and the test did not already provide a recognized optimization option. Compiler-backed paths receive -O0 directly. Render-test-backed paths receive -Xslang -O0, which is the render-test spelling for forwarding the option to Slang.

Every render-test-backed path receives an explicit slang-test-controlled default. Metal render tests receive -Xslang -O1 instead of -O0: the Slang optimization level is never read by Slang's own IR pipeline (the emitted MSL is byte-identical at every level), but it selects the flags passed to the downstream metal toolchain that produces the metallib, and macOS CI showed mass flaky failures (650+ tests, differing sets between jobs, fast empty-output failures) when that toolchain runs at -O0. -O1 maps to the toolchain flags that were in effect before this PR, so Metal keeps the exact behavior that passes CI while still getting an explicit level like every other target.

The override detection uses slangc's known optimization spellings instead of treating every -O... option as an optimization level. That keeps unrelated future options from accidentally suppressing the slang-test default. Tests whose expected output or runtime behavior depends on optimization opt in explicitly with the lowest optimization level required by that backend.

Change summary

  • tools/slang-test/slang-test-optimization-options.h centralizes the default optimization option, direct compiler override detection, render-test forwarding detection, and render-test default insertion, including the Metal-specific -O1 default (kMetalRenderTestOptimizationOption).
  • tools/slang-test/slang-test-main.cpp appends the shared default across compiler-backed and render-test-backed command builders, with compiler-backed paths adding it after _initSlangCompiler() for consistent duplicate-detection behavior.
  • tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp covers the accepted optimization spellings, render-test forwarding forms, idempotent default insertion, and the Metal-specific defaulting for -mtl/-metal spellings including the override case.
  • tools/slang-test/README.md documents the new default, the compiler-backed opt-in spelling, the render-test-backed forwarding spellings (all four recognized forms), the Metal -O1 exception, accepted optimization spellings, and the diagnostic-test pitfall.
  • Optimization-sensitive tests from the failure log now declare explicit optimization levels in their //TEST directives. This includes tests/autodiff/path-tracer/pt-loop.slang, whose -vk directive opts into -Xslang -O1 because its unoptimized SPIR-V (spirv-opt skipped at -O0) crashed the Linux CI test server.

Concepts and vocabulary

  • Compiler-backed tests build command lines that go directly to the Slang compiler.
  • Render-test-backed tests invoke render-test, so Slang compiler arguments must be forwarded with render-test options such as -Xslang.
  • Optimization-sensitive tests are tests whose expected output or runtime result depends on optimization passes being enabled.
  • The Slang optimization level (-O0..-O3) does not change Slang's own IR passes; it controls whether spirv-opt runs (skipped entirely at -O0) and which flags downstream compilers (dxc, metal, nvrtc, gcc/clang) receive.

Process report

The input shape reaching slang-test is the parsed argument list from a //TEST directive. That shape is intentional: tests can already specify compiler options, and an explicit optimization option is the right source of truth for optimization-sensitive tests. The helper only checks whether such an override exists before appending the default; it does not reinterpret the test directive or change how other options are parsed.

For compiler-backed commands, SlangTest::addDefaultSlangOptimization runs after the command builder has added directive arguments (and after _initSlangCompiler() for paths that call it), so its override check sees the full argument list — but it inserts the default -O0 at the front of the argument list rather than appending it. Front insertion makes the default position-independent: slangc option parsing accepts options in any order, while an appended -O0 could be consumed as the argument of a trailing option a test intentionally leaves dangling. This is why tests/diagnostics/command-line/option-missing-argument.slang needs no modification: its -profile ps_4_0 -target directive keeps -target dangling and still reports the missing-argument diagnostic. The slangTestDefaultOptimizationInsertion unit test pins the front-insertion contract with exactly that dangling--target shape.

For render-test-backed commands, SlangTest::addDefaultRenderTestSlangOptimization performs the same check through render-test forwarding forms and inserts -Xslang <level> at the front of the argument list so the option reaches the Slang compiler rather than being treated as a render-test option. Front insertion here mirrors the compiler-backed path, per review: a directive that accidentally leaves an option without its required parameter cannot consume the inserted default, so the mistake stays visible instead of silently changing the command. This is safe because render-test's parser collects positional arguments in order and stripDownstreamArgs handles forwarding pairs position-independently. The helper recognizes -compile-arg, -xslang, -Xslang, and -Xslang... ... -X. forms. The unit test locks in those spellings and the front-insertion contract because a directive-level integration test could pass even if a helper accidentally inserted a stray -O0.

Metal render tests receive -O1 instead of -O0. This was verified empirically across four CI rounds: commits without a Metal exception (968453a, 5b4c9df) failed 650+ Metal tests on macOS with flaky, fast, empty-output failures, while commits with one (ef2ec5f, eab84de) passed. The mechanism was traced in code: Slang's IR pipeline never reads the optimization level (verified by diffing slangc -target metal output at -O0 vs default — byte-identical), so the only Metal-path difference is GCCDownstreamCompilerUtil::calcArgs passing -O0 instead of -Os to the metal CLI when slang-rhi requests SLANG_METAL_LIB. The instability therefore lives in the downstream Metal toolchain/runtime on the macOS runners, not in Slang, and is out of scope for this test-infrastructure PR. Choosing -O1 (which maps back to -Os) keeps the uniform "slang-test always sets an explicit level" invariant while pinning Metal to the previously passing downstream flags. This supersedes the earlier fully-uniform -O0 approach; see the Reviewer Directives section.

tests/autodiff/path-tracer/pt-loop.slang opts its -vk directive into -Xslang -O1. At -O0, spirv-opt is skipped entirely (source/slang-glslang/slang-glslang.cpp, SLANG_OPTIMIZATION_LEVEL_NONE early-out), and this heavy autodiff path-tracer's unoptimized SPIR-V consistently crashed the Linux CI test server (JSON RPC failure) on the NVIDIA driver while passing on Windows GPU. -O1 restores exactly the pre-PR behavior for this one test, using the opt-in mechanism the issue prescribes.

The remaining tests changed in this PR are the cases exposed by the -O0 default. Their expected output or runtime behavior depends on optimized Slang IR or downstream optimized codegen, so the directives now opt in explicitly. The opt-in levels are the lowest that keep each test passing, and they are not interchangeable: tests/language-feature/dynamic-dispatch/layout-array-2d.slang fails at -Xslang -O3 because dxc's validator rejects the shader with an uninitialized-value (undef) read that only surfaces at the higher downstream optimization level, and tests/language-feature/swizzles/matrix-swizzle-out-arg-writeback.slang fails at -O3 because spirv-opt's aggressive passes flatten the exact OpAccessChain/OpStore shapes its FileCheck patterns pin, while -O1 preserves them.

Reviewer Directives (maintained by agent)

  • [human @jkwak-work] Treat all target platforms uniformly for the slang-test optimization default. Source: Default slang-test compiler invocations to -O0 #11805 (comment)Amended by CI evidence: fully-uniform -O0 demonstrably breaks 650+ Metal tests on macOS CI (see Process report). The current implementation keeps the uniform "always append an explicit level" shape but pins Metal to -O1 (the previously passing downstream flags). Pending explicit confirmation from @jkwak-work.
  • [human @jkwak-work] Do not add directive-level .slang regression tests for this command-line default; keep the coverage focused in helper/unit tests instead. Source: Default slang-test compiler invocations to -O0 #11805 (comment)
  • [human @jkwak-work] Minimize modifications to existing test files; prefer infrastructure-level solutions over editing many //TEST directives. (Stated during agent session, 2026-07-01.)
  • [human @jkwak-work] Prefer -O3 for optimization opt-ins where possible (requested for layout-array-2d.slang and matrix-swizzle-out-arg-writeback.slang). — Amended by validation evidence: both tests fail at -O3 (dxc undef-read validation error on dx12; spirv-opt flattening the pinned OpAccessChain shapes for spirv-asm), so they remain at -O2/-O1 respectively; see the thread replies for the traces. This also supersedes the earlier session note that -O2 and -O3 are equivalent in practice — they map to different downstream dxc levels. Pending confirmation from @jkwak-work.
  • [human @jkwak-work] Insert the slang-test default optimization option at the front of the argument list — never append — for both compiler-backed and render-test-backed commands, so a directive with an accidentally missing option parameter cannot consume the inserted default. Source: Default slang-test compiler invocations to -O0 #11805 (comment)

@jkwak-work jkwak-work added pr: non-breaking PRs without breaking changes CoPilot labels Jun 28, 2026
@jkwak-work jkwak-work self-assigned this Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fb076c77-784c-45fa-8b34-d24d14a37e60

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds default optimization handling for slang-test compiler and render-test command lines, with Metal render tests defaulting to -O1. Updates runner wiring, unit coverage, documentation, and test directives that need explicit optimization flags.

Changes

Default slang-test optimization handling

Layer / File(s) Summary
Optimization detection/injection helpers and docs
tools/slang-test/slang-test-optimization-options.h, tools/slang-test/README.md
New helpers detect existing optimization arguments and inject default -O0 or -O1 values; the README documents the defaulting and forwarding rules.
Runner wiring
tools/slang-test/slang-test-main.cpp
Adds the new helper include and injects default optimization into compiler-backed and render-test-backed command lines before execution.
Helper unit tests
tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp
New tests cover optimization-argument detection and default insertion behavior for compiler and render-test command lines.
Test directive updates
tests/autodiff/*, tests/bugs/*, tests/compute/*, tests/cross-compile/*, tests/glsl*/*, tests/hlsl*/*, tests/language-feature/*, tests/llvm/*, tests/optimization/*, tests/pipeline/*, tests/spirv/*, tests/vkray/*, tests/wgsl/*
Many test directives now pass explicit optimization flags, with minor whitespace and formatting edits around some of the changed directives.

Suggested reviewers: bmillsNV, aidanfnv, jkiviluoto-nv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the PR’s main change: defaulting slang-test compiler invocations to -O0.
Description check ✅ Passed The description is directly about the optimization-defaulting changes and the related test updates.
Linked Issues check ✅ Passed The PR implements the requested -O0 defaulting for compiler and render-test paths while preserving explicit optimization overrides.
Out of Scope Changes check ✅ Passed The changes stay focused on optimization defaulting, helper coverage, docs, and necessary test opt-ins, with no clear unrelated additions.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@jkwak-work jkwak-work marked this pull request as ready for review June 28, 2026 13:19
@jkwak-work jkwak-work requested a review from a team as a code owner June 28, 2026 13:19
@jkwak-work jkwak-work requested review from bmillsNV and removed request for a team June 28, 2026 13:19
@coderabbitai

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@jkwak-work jkwak-work force-pushed the disable-spv-opt-in-slang-test branch from f270d60 to 968453a Compare June 28, 2026 14:18

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a81fff05-4c13-4ed6-b887-a77409d4d901

📥 Commits

Reviewing files that changed from the base of the PR and between f270d60 and 968453a.

⛔ Files ignored due to path filters (1)
  • tests/bugs/vk-structured-buffer-load.hlsl is excluded by !**/*.hlsl
📒 Files selected for processing (42)
  • tests/autodiff/differentiable-interface-return.slang
  • tests/autodiff/reverse-loop-immediate-return.slang
  • tests/bugs/gh-10774-concrete-return.slang
  • tests/bugs/gh-6482-interface-method-existential-specialize.slang
  • tests/bugs/gh-9916.slang
  • tests/bugs/metal-return-value-lost.slang
  • tests/bugs/spirv-opt-SROA-of-globals.slang
  • tests/compute/byte-address-buffer-array.slang
  • tests/compute/half-texture.slang
  • tests/compute/nonuniformres-as-function-parameter.slang
  • tests/compute/nonuniformres-nested-rwstructuredbuf.slang
  • tests/compute/static-const-array.slang
  • tests/cooperative-vector/layout-structuredbuffer.slang
  • tests/cross-compile/loop-attribs.slang
  • tests/cross-compile/precise-keyword.slang
  • tests/diagnostics/command-line/option-missing-argument.slang
  • tests/glsl-intrinsic/intrinsic-basic-vector.slang
  • tests/glsl-intrinsic/intrinsic-texture.slang
  • tests/glsl/matrix-bool-lowering.slang
  • tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang
  • tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-chit.slang
  • tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-miss.slang
  • tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-rgen.slang
  • tests/hlsl/texture-mips-operator.slang
  • tests/language-feature/dynamic-dispatch/layout-array-2d.slang
  • tests/language-feature/dynamic-dispatch/layout-array-field.slang
  • tests/language-feature/dynamic-dispatch/layout-array-of-structs.slang
  • tests/language-feature/dynamic-dispatch/layout-array-of-vectors.slang
  • tests/language-feature/execution-model/varying-array-input.slang
  • tests/language-feature/stage-switch.slang
  • tests/language-feature/swizzles/matrix-swizzle-out-arg-writeback.slang
  • tests/llvm/printf.slang
  • tests/optimization/arrray-storage-lowering.slang
  • tests/optimization/buffer-load-defer-bindless.slang
  • tests/optimization/defer-structured-buffer-load.slang
  • tests/pipeline/ray-tracing/ray-query-subroutine.slang
  • tests/pipeline/ray-tracing/trace-ray-inline.slang
  • tests/spirv/abort-defer.slang
  • tests/spirv/mesh-shader-invert-y.slang
  • tests/vkray/anyhit.slang
  • tools/slang-test/README.md
  • tools/slang-test/slang-test-main.cpp

Comment thread tools/slang-test/slang-test-main.cpp Outdated
Comment thread tools/slang-test/slang-test-main.cpp Outdated
github-actions[bot]

This comment was marked as outdated.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6bfb9b5c-f93b-4a95-8d91-89401fc40065

📥 Commits

Reviewing files that changed from the base of the PR and between 968453a and ef2ec5f.

📒 Files selected for processing (5)
  • tests/wgsl/matrix-bool-lowering.slang
  • tools/slang-test/README.md
  • tools/slang-test/slang-test-main.cpp
  • tools/slang-test/slang-test-optimization-options.h
  • tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp

Comment thread tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp Outdated
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

Comment thread tools/slang-test/slang-test-main.cpp
Comment thread tools/slang-test/slang-test-optimization-options.h Outdated
@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4a8b9f6c-1ba2-4b6b-bff3-05cd465e9653

📥 Commits

Reviewing files that changed from the base of the PR and between d3a525f and 265ad27.

📒 Files selected for processing (3)
  • tools/slang-test/README.md
  • tools/slang-test/slang-test-optimization-options.h
  • tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp

Comment thread tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp
github-actions[bot]

This comment was marked as outdated.

//CHECK1: unknown code generation target '-profile'

//DIAGNOSTIC_TEST:SIMPLE(diag=CHECK2):-profile ps_4_0 -target
//DIAGNOSTIC_TEST:SIMPLE(diag=CHECK2):-profile ps_4_0 -O3 -target

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't make sense.
We shouldn't need this change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Agent] Agreed — fixed at the root in 265ad27 and this test file is now unchanged from master. The real problem was that slang-test appended its default -O0 after the directive arguments, so a diagnostic test ending with an intentionally dangling -target would consume -O0 as its argument and report a different diagnostic. addDefaultSlangOptimization now inserts the default at the front of the argument list (slangc option parsing is position-independent), so test-provided arguments keep their meaning and no test needs to compensate. Validation: the slangTestDefaultOptimizationInsertion unit test now pins the front-insertion behavior with a dangling -target case, and tests/diagnostics/, tests/front-end/, and tests/cross-compile/ all pass locally (756/756).

// which must be packed element-by-element into AnyValue storage.

//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx12 -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx12 -compute -shaderobj -output-using-type -Xslang -O2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should be -O3 not -O2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Agent] I tried -Xslang -O3 and it fails locally on dx12: dxc validation rejects the shader with 'Instructions should not read uninitialized value' at 'select i1 %15, float fadd (float fadd (float undef, float undef), float undef), ...' in computeMain, so the compute run returns no output and the CHECK comparison fails. At -O2 the test passes (5/5 locally, and it passed CI). So -O2 and -O3 do differ on the DXIL path: the Slang level maps to different downstream dxc optimization flags, and dxc at the higher level exposes an undef read in the generated HLSL. I kept -O2 for now. Two follow-ups for your call: (1) confirm keeping -O2 here, and (2) the undef read that dxc surfaces at -O3 may be a real codegen issue in the dynamic-dispatch/AnyValue path worth filing separately.

@@ -1,5 +1,5 @@
//TEST:SIMPLE(filecheck=CHECK_HLSL): -target hlsl -entry computeMain -stage compute
//TEST:SIMPLE(filecheck=CHECK_SPV): -target spirv-asm -entry computeMain -stage compute
//TEST:SIMPLE(filecheck=CHECK_SPV): -target spirv-asm -entry computeMain -stage compute -O1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Agent] I tried -O3 and the test fails: this SIMPLE test pins exact SPIR-V shapes (CHECK_SPV: OpAccessChain %_ptr_Function_v4float %m %int_3 followed by a second OpAccessChain and OpStore %float_11), and at -O3 spirv-opt's aggressive passes flatten those two-level access chains away, so the patterns cannot match. At -O1 the pinned shapes are present and the test passes — which is why the opt-in was -O1. I kept -O1. If you prefer -O3 here, the CHECK_SPV patterns would need to be rewritten against the optimized output, which weakens the element-level write-back assertions this regression test (#10212) exists to check. Please confirm which you prefer.

Comment thread tests/language-feature/dynamic-dispatch/layout-array-2d.slang
Comment thread tests/bugs/gh-9916.slang
Comment thread tests/diagnostics/command-line/option-missing-argument.slang Outdated
Comment thread tools/slang-test/README.md
Comment thread tools/slang-test/slang-test-optimization-options.h Outdated
Comment thread tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp
Comment on lines +129 to +130
ioCmdLine.addArg("-Xslang");
ioCmdLine.addArg(isMetal ? kMetalRenderTestOptimizationOption : kTestOptimizationOption);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we should prepend the options rather than append to the end.
Because if the given test command line argument has a missing parameters by mistake, we don't want it to be mixed up with the newly appened options.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Agent] Done in 3e6ebdf. addDefaultRenderTestSlangOptimization now inserts -Xslang at the front of the argument list instead of appending, matching addDefaultSlangOptimization — so a directive that accidentally leaves an option without its parameter cannot consume the inserted default. render-test's parser collects positionals in order and stripDownstreamArgs handles forwarding pairs position-independently, so a leading -Xslang pair is safe. Validation: the three helper unit tests pass (including the updated dangling -xslang case, which now keeps the mistake visible as a trailing dangling flag), and pt-loop.slang, layout-array-2d.slang, and compute/simple.slang all pass locally through render-test (16/16). The README note now covers both command paths.

@jkwak-work

This comment has been minimized.

@coderabbitai

This comment has been minimized.

@github-actions github-actions Bot 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.

Verdict: 🟡 Has issues — 0 bugs, 1 gap, 1 question

The PR is test-infrastructure only: no IR pass, emitter, or .meta.slang file is touched. The slang-test-optimization-options.h helpers (arg detection, front-insertion, Metal exception) are correctly implemented and thoroughly unit-tested. Slang's own IR pipeline is confirmed independent of the -O level; only spirv-opt gating and downstream-compiler flags change. The remaining concerns are about asymmetric per-line opt-ins in a few test files where only one backend received the new explicit level while sibling lines with the same CHECK contract dropped to -O0.

Changes Overview

slang-test default optimization (tools/slang-test/slang-test-optimization-options.h new, tools/slang-test/slang-test-main.cpp, tools/slang-test/README.md)

  • New default -O0 for compiler-backed commands and -Xslang -O0 for render-test-backed commands, front-inserted so trailing dangling options remain diagnosable. Metal render tests receive -Xslang -O1 instead because the downstream metal toolchain is unstable at -O0 on macOS CI. Detection recognizes slangc's canonical -O/-O0/-Onone/-O1/-Odefault/-O2/-Ohigh/-O3/-Omaximal spellings and the render-test forwarding forms -compile-arg, -xslang, -Xslang, -Xslang... -X..

Unit test coverage (tools/slang-unit-test/unit-test-slang-test-optimization-options.cpp new)

  • Locks in the accepted -O spellings, all four forwarding forms, idempotent default insertion, front-insertion contract (verified with a dangling--target shape), and Metal -mtl/-metal synonym mapping to -O1.

Test opt-ins (~42 .slang/.hlsl files under tests/)

  • Tests whose expected output or runtime behavior depends on spirv-opt or a downstream optimizer now declare an explicit -O<n> (mostly -O3, with -O2/-O1 used where a higher level breaks the CHECK pattern or downstream validator). tests/autodiff/path-tracer/pt-loop.slang opts its -vk line into -Xslang -O1 because -O0 skips spirv-opt and the unoptimized SPIR-V crashed the Linux CI test server.
Findings (2 total)
Severity Location Finding
🟡 Gap tests/language-feature/dynamic-dispatch/layout-array-2d.slang:5 Only -dx12 gets -Xslang -O2; -vk/-cuda/-cpu sharing the same CHECK buffer silently drop to -O0. Same pattern in layout-array-field.slang, layout-array-of-structs.slang, layout-array-of-vectors.slang.
🔵 Question tests/bugs/gh-9916.slang:2 Non-bindless line got -O3; CHECK_BINDLESS line did not — intentional, or overlooked?

Comment thread tests/language-feature/dynamic-dispatch/layout-array-2d.slang
Comment thread tests/bugs/gh-9916.slang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CoPilot pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default slang-test compiler invocations to -O0

3 participants