Repository navigation
cranelift: charge Else and End operator fuel in target blocks - #14646
Merged
alexcrichton merged 1 commit intoOct 10, 2026
Merged
Conversation
`FuncEnvironment::fuel_before_op` previously added the operator cost for every instruction other than `Nop` and `Drop` before `translate_operator` ran, guarded by `state.reachable` at instruction entry. For `Operator::Else` and `Operator::End`, this caused two bugs when custom `OperatorCost` values were configured: 1. At entry to `Operator::Else`, `builder` is still positioned at the end of the `then` block before `translate_operator` emits the jump to `exit_block` and switches `builder` to the `else` block. Charging `Else` in `fuel_before_op` therefore charged `Else` when the `then` branch was taken and failed to charge `Else` when the `else` branch was taken. 2. When the `then` block (or the body preceding `End`) ended with an unconditional control transfer (`return`, `br`, etc.), `state.reachable` was `false` entering `Else` or `End`, so `before_translate_operator` skipped `fuel_before_op` even when the `else` block or merged `End` block was reachable via another incoming edge. Defer `Operator::Else` and `Operator::End` fuel charging from `fuel_before_op` to `fuel_after_op`, after `translate_operator` has switched `builder` to the target block and updated `state.reachable`. Assisted-by: Gemini
ctiller
force-pushed
the
fix/else-end-operator-fuel
branch
from
October 10, 2026 00:05
2ec1d8a to
2db2014
Compare
cfallin
approved these changes
Oct 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FuncEnvironment::fuel_before_oppreviously added the operator cost for every instruction other thanNopandDropbeforetranslate_operatorran, guarded bystate.reachableat instruction entry. ForOperator::ElseandOperator::End, this caused two bugs when customOperatorCostvalues were configured:Operator::Else,builderis still positioned at the end of thethenblock beforetranslate_operatoremits the jump toexit_blockand switchesbuilderto theelseblock. ChargingElseinfuel_before_optherefore chargedElsewhen thethenbranch was taken and failed to chargeElsewhen theelsebranch was taken.thenblock (or the body precedingEnd) ended with an unconditional control transfer (return,br, etc.),state.reachablewasfalseenteringElseorEnd, sobefore_translate_operatorskippedfuel_before_opeven when theelseblock or mergedEndblock was reachable via another incoming edge.Defer
Operator::ElseandOperator::Endfuel charging fromfuel_before_optofuel_after_op, aftertranslate_operatorhas switchedbuilderto the target block and updatedstate.reachable.Assisted-by: Gemini