Repository navigation
Conversation
Gen.tof/Gen.tou emitted a second OpBitcast to turn a value back into the type it was bitcast from: a register read as float and then flushed (flush_f32 reads the float's bits), a float result stored back, and so on. On a 133-shader corpus sample bitcasts are 14% of body lines, and 1.9% are such round trips. Gen.bitcast_from maps each tof/tou result to its source, and the reverse bitcast returns the source. Always valid SSA: wherever the result is usable its source is too, since the result's own definition uses it. Keys are only ids tof/tou just made, never module-scope constants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_bitcast_round_trip.py checks that tof/tou return the source for the reverse bitcast without emitting one, and that a translated module with a v_mad_f32 and a v_mul_legacy_f32 has no OpBitcast whose operand is a bitcast from the same type. main's translator emits five such round trips in that module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 7ea906d5 on Windows 11: tests/semantic/test_bitcast_round_trip.py -> 2 tests, OK; compileall and git diff --check clean.
tof/tou now reuse the original id when a bitcast returns to the source type, and the new cases verify no round-trip bitcast is emitted; the source's definition dominates every later use, so no dominance is lost. No blocking issue.
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
|
Tested
AI-assisted (Devin). |
|
Tested 7ea906d merged with main 03b09a0 on Linux (WSL2), Python 3.12.16: pass. |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted independent Windows CPU check of 7ea906d5 against 03b09a08, plus a clean scratch merge with #4473 aa813789. uv CPython 3.12.13, Vulkan SDK 1.4.363.0, synthetic fragment shaders only.
- All 1,006 cases that translated had bit-identical
mrt0output across the three trees, including signed zero, denormals, infinities and NaN payload inputs. All three rejected the same 18 multiply-with-clamp cases at the existing undefinedFClampcheck. - A separate 16-module sample assembled and passed
spirv-val --target-env vulkan1.3in all three trees.OpBitcastcount fell from 456 to 399 in both the PR and the combined tree. - The existing
%intinputs totou()in signed d16 packing andv_mad_i16feed integer consumers. I found no current route from those result IDs totof(). A future such route would need to preserve the float destination type instead of reusing the signed source ID.
|
Tested
No GPU, no game data. AI-assisted. |
tou remembers its argument so that tof can hand it back, which is only right when that argument is a %float. v_mad_i16 and the signed d16 buffer store passed the %int halves from i16_half; nothing bitcast those results back yet, but a later tof would have been given the %int as a float (@whattheflop's review). They now use int_bits, a plain bitcast with no memo, and tof/tou say what they take. The new test checks the type of every tof/tou argument in a module with v_mad_i16 and fails without the change; a corpus sample (133 shaders, 716,716 calls) already held it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@whattheflop Thanks, good catch. Fixed in
AI-assisted (Claude Code). |
|
Replying to @mrp1no. Confirmed the signed D16 buffer-store caller in For the GPU check I set the descriptor to 32_SINT and stored from AI-assisted. |
New SHADER item. Claim: #4421 (comment)
Gen.tof/Gen.touemitted a secondOpBitcastto turn a value back into the type it had just been bitcast from. It happens when a register is read as float and then flushed (flush_f32reads the float's bits), when a float result is stored back, and so on. On a 133-shader corpus sample, bitcasts are 14% of all body lines, and 1.9% are such round trips.Commits
rdna2spirv:Gen.bitcast_frommaps eachtof/touresult to its source, and the reverse bitcast returns that source.tof/toujust made, never module-scope constants, so nothing crosses a function.tests/semantic/test_bitcast_round_trip.pychecks two things:v_mad_f32and av_mul_legacy_f32has noOpBitcastwhose operand is a bitcast from the same type.main's translator emits five such round trips in that module, and the test fails there.Measured on my own 1.0.2.1 corpus (shard 0/40, counts only)
main03b09a08spirv-valSemantic suite: 7,458 tests. The only failures are the ones
mainalready has:test_loop_ballot_barrier(5),test_cmp_class_f64(2), andtest_mutations' legacy anchor (2, fixed by #3883).Independent of #4345, #4391, #4477 and @SweatierKey's
%activereuse item. Each one removes a different redundancy, so the savings add up. AI-assisted (Claude Code).🤖 Generated with Claude Code