Skip to content

Simplify branch hint instrumentation#8624

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

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

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Apr 18, 2026

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
Copy link
Copy Markdown
Member

@kripken kripken left a comment

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
Copy link
Copy Markdown
Member Author

tlively commented Apr 20, 2026

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
Copy link
Copy Markdown
Member

kripken commented Apr 20, 2026

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

@tlively
Copy link
Copy Markdown
Member Author

tlively commented Apr 20, 2026

Taking a look.

@tlively
Copy link
Copy Markdown
Member Author

tlively commented Apr 20, 2026

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
Copy link
Copy Markdown
Member

kripken commented Apr 20, 2026

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
Copy link
Copy Markdown
Member

kripken commented Apr 20, 2026

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

@tlively
Copy link
Copy Markdown
Member Author

tlively commented Apr 20, 2026

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.

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