Skip to content

Simplify branch hint instrumentation#8624

Merged
tlively merged 1 commit into
mainfrom
branch-hint-transparent-instrument
Apr 20, 2026
Merged

Simplify branch hint instrumentation#8624
tlively merged 1 commit into
mainfrom
branch-hint-transparent-instrument

Conversation

@tlively

@tlively tlively commented Apr 18, 2026

Copy link
Copy Markdown
Member

The previous branch hint instrumentation logic would introduce a scratch local to hold the condition so it could be passed into both the logging function and the original branching instruction. The de-instrumentation pass would then need to find this local and attempt to undo the data flow change. Simplify all of this by having the logging function return the condition value so it can interpose between the condition and the branch without any new locals. De-instrumentation can now just replace the call to the log function with its condition parameter.

To allow further simplification, also change the order of parameters to the logging function so the condition value is the first parameter. This ensures that we don't need to introduce a scratch local even when the condition is a pop, because the pop will remain the leftmost leaf expression in the catch body.

@tlively tlively requested a review from a team as a code owner April 18, 2026 04:26
@tlively tlively requested review from kripken and removed request for a team April 18, 2026 04:26
The previous branch hint instrumentation logic would introduce a scratch local to hold the condition so it could be passed into both the logging function and the original branching instruction. The de-instrumentation pass would then need to find this local and attempt to undo the data flow change. Simplify all of this by having the logging function return the condition value so it can interpose between the condition and the branch without any new locals. De-instrumentation can now just replace the call to the log function with its condition parameter.

To allow further simplification, also change the order of parameters to the logging function so the condition value is the first parameter. This ensures that we don't need to introduce a scratch local even when the condition is a `pop`, because the pop will remain the leftmost leaf expression in the catch body.
@tlively tlively force-pushed the branch-hint-transparent-instrument branch from 4356c25 to 1456ddf Compare April 18, 2026 04:36

@kripken kripken 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.

Nice!

Have you verified this catches bugs properly? E.g. removing the branch hint updates from RemoveUnusedBrs or OptimizeInstructions should quickly lead the fuzzer to a problem.

@tlively

tlively commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

Yes, just confirmed that now.

@tlively tlively merged commit 93b0629 into main Apr 20, 2026
16 checks passed
@tlively tlively deleted the branch-hint-transparent-instrument branch April 20, 2026 17:30
@kripken

kripken commented Apr 20, 2026

Copy link
Copy Markdown
Member

I see branch hint fuzzer errors after this landed, e.g. seed 18155827997069348795

@tlively

tlively commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

Taking a look.

@tlively

tlively commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

What commit does that seed come from? It doesn't reproduce on the current head or on the commit where this PR landed. Regardless, I'll run the fuzzer locally to see if I find problems.

@kripken

kripken commented Apr 20, 2026

Copy link
Copy Markdown
Member

Weird, it works for me on both those commits. I guess there is not enough determinism in these seeds...

I get an error every few thousand iterations, so hopefully you're reproduced by now. If not I can reduce one of them.

@kripken

kripken commented Apr 20, 2026

Copy link
Copy Markdown
Member

Disabling all other fuzzers, I see a problem every 100 iterations or so.

@tlively

tlively commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

Ok, I have a reproducer. It looks like another bad interaction between the recent parser changes and this pass. Thankfully it shouldn't be too hard to fix.

@kripken

kripken commented Apr 21, 2026

Copy link
Copy Markdown
Member

I just saw another crash even after the fix. 11105918128978086081 likely won't reproduce for you but that is the seed. Unfortunately the reducer can't handle it for some reason I can't immediately see.

@tlively

tlively commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

Maybe it needs to be hacked to use text reduction. Or maybe it depends on some very stacky code that any round tripping destroys. You could try using wasm-tools to get an exact text dump and then reducing with AI assistance.

Maybe a nop got in between the logging and the branch somehow and caused the fallthrough to be a get of a temp variable, causing the hint deletion to fail?

FWIW I ran about 140k iterations of just the branch hint handler and didn't see anything.

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.

2 participants