Skip to content

fix(opt): visit input operand of AtomicOp::CompareAndSwap#1331

Draft
kimjune01 wants to merge 1 commit into
tracel-ai:mainfrom
kimjune01:fix/spirv-atomic-cas-scope
Draft

fix(opt): visit input operand of AtomicOp::CompareAndSwap#1331
kimjune01 wants to merge 1 commit into
tracel-ai:mainfrom
kimjune01:fix/spirv-atomic-cas-scope

Conversation

@kimjune01

@kimjune01 kimjune01 commented May 14, 2026

Copy link
Copy Markdown

Fixes #1318.

visit_atomic for CompareAndSwap visited op.cmp twice and never visited op.input. The atomic pointer variable therefore wasn't tracked as read, and the optimizer could break the binding chain between the Index op (which registers the atomic scope) and the CAS op (which looks it up). The downstream effect was the Atomic should have a scope registered panic in cubecl-spirv.

This change visits op.input and removes the duplicate visit of op.cmp (a copy-paste bug).

Testing

  • cargo xtask validate passes.
  • Existing optimizer tests pass.

Hypothesis graph

Investigation notes and the repo-level hypothesis graph that informed this fix: https://github.com/kimjune01/sweep/blob/master/repo-hypotheses/tracel-ai-cubecl.md

The optimizer's visit_atomic handler for CompareAndSwap visited
op.cmp twice and never visited op.input. This meant the atomic
pointer variable was not tracked as read, so the optimizer could
break the binding chain between the Index op (which registers the
atomic scope) and the CAS op (which looks it up), causing
"Atomic should have a scope registered" panics in cubecl-spirv.

Also fixes the duplicate visit of op.cmp (copy-paste bug).

Fixes tracel-ai#1318
@kimjune01
kimjune01 marked this pull request as draft May 17, 2026 20:09
@kimjune01

Copy link
Copy Markdown
Author

Human here. Unfortunate news: I just moved this into drafts because I just realized that I can't repro the issue locally anymore. I quit my job this past week and no longer have access to a linux or windows machine like I used to. I'm on a macbook pro now. I wish I could've taken it to completion by actually running the tests. Thanks for understanding

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.

cubecl-spirv panics on Atomic<u64> compare_exchange_weak ("Atomic should have a scope registered")

1 participant