summaryrefslogtreecommitdiff
path: root/zjit/src
diff options
context:
space:
mode:
authorMax Bernstein <[email protected]>2025-04-23 08:57:14 -0400
committerTakashi Kokubun <[email protected]>2025-04-24 11:33:11 -0700
commitf36f792091df3c6bcdbc2f7793d47431c0df3e44 (patch)
tree020d2acb7947e4070dc42c7e276ffcad75f33641 /zjit/src
parentbbd5d3348b519035a5d2cdf777e7c8d5c143055c (diff)
Simplify fixnum guarding code
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13162
Diffstat (limited to 'zjit/src')
-rw-r--r--zjit/src/hir.rs25
1 files changed, 4 insertions, 21 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index 12dcec2a31..bd04a358bb 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -1425,14 +1425,6 @@ impl FrameState {
self.stack.last().ok_or_else(|| ParseError::StackUnderflow(self.clone())).copied()
}
- /// Get a stack operand at idx
- fn stack_opnd(&self, idx: usize) -> Result<InsnId, ParseError> {
- match self.stack.get(self.stack.len() - idx - 1) {
- Some(&opnd) => Ok(opnd),
- _ => Err(ParseError::StackUnderflow(self.clone())),
- }
- }
-
/// Set a stack operand at idx
fn stack_setn(&mut self, idx: usize, opnd: InsnId) {
let idx = self.stack.len() - idx - 1;
@@ -1598,7 +1590,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
// For opt_neq, the interpreter checks that both neq and eq are unchanged.
fun.push_insn(block, Insn::PatchPoint(Invariant::BOPRedefined { klass: INTEGER_REDEFINED_OP_FLAG, bop: BOP_EQ }));
}
- let (left, right) = guard_two_fixnums(&mut state, exit_id, &mut fun, block)?;
+ let right = state.stack_pop()?;
+ let left = state.stack_pop()?;
+ let left = fun.push_insn(block, Insn::GuardType { val: left, guard_type: Fixnum, state: exit_id });
+ let right = fun.push_insn(block, Insn::GuardType { val: right, guard_type: Fixnum, state: exit_id });
state.stack_push(fun.push_insn(block, Insn::$insn { left, right$(, $key: exit_id)? }));
} else {
let cd: *const rb_call_data = if $bop == BOP_NEQ {
@@ -1868,18 +1863,6 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
Ok(fun)
}
-/// Generate guards for two fixnum outputs
-fn guard_two_fixnums(state: &mut FrameState, exit_state: InsnId, fun: &mut Function, block: BlockId) -> Result<(InsnId, InsnId), ParseError> {
- let left = fun.push_insn(block, Insn::GuardType { val: state.stack_opnd(1)?, guard_type: Fixnum, state: exit_state });
- let right = fun.push_insn(block, Insn::GuardType { val: state.stack_opnd(0)?, guard_type: Fixnum, state: exit_state });
-
- // Pop operands after guards for side exits
- state.stack_pop()?;
- state.stack_pop()?;
-
- Ok((left, right))
-}
-
#[cfg(test)]
mod union_find_tests {
use super::UnionFind;