@@ -1457,10 +1457,19 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
14571457 let exit_id = fun. push_insn( block, Insn :: Snapshot { state: exit_state. clone( ) } ) ;
14581458 if payload. have_two_fixnums( current_insn_idx as usize ) {
14591459 fun. push_insn( block, Insn :: PatchPoint ( Invariant :: BOPRedefined { klass: INTEGER_REDEFINED_OP_FLAG , bop: $bop } ) ) ;
1460+ if $bop == BOP_NEQ {
1461+ // For opt_neq, the interpreter checks that both neq and eq are unchanged.
1462+ fun. push_insn( block, Insn :: PatchPoint ( Invariant :: BOPRedefined { klass: INTEGER_REDEFINED_OP_FLAG , bop: BOP_EQ } ) ) ;
1463+ }
14601464 let ( left, right) = guard_two_fixnums( & mut state, exit_id, & mut fun, block) ?;
14611465 state. stack_push( fun. push_insn( block, Insn :: $insn { left, right$( , $key: exit_id) ? } ) ) ;
14621466 } else {
1463- let cd: * const rb_call_data = get_arg( pc, 0 ) . as_ptr( ) ;
1467+ let cd: * const rb_call_data = if $bop == BOP_NEQ {
1468+ // opt_neq is a special case where it has two cd and the first one is opt_eq.
1469+ get_arg( pc, 1 ) . as_ptr( )
1470+ } else {
1471+ get_arg( pc, 0 ) . as_ptr( )
1472+ } ;
14641473 let right = state. stack_pop( ) ?;
14651474 let left = state. stack_pop( ) ?;
14661475 state. stack_push( fun. push_insn( block, Insn :: SendWithoutBlock { self_val: left, call_info: CallInfo { method_name: $method_name. into( ) } , cd, args: vec![ right] , state: exit_id } ) ) ;
@@ -2300,10 +2309,11 @@ mod tests {
23002309 fn test:
23012310 bb0(v0:BasicObject, v1:BasicObject):
23022311 PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_NEQ)
2303- v5:Fixnum = GuardType v0, Fixnum
2304- v6:Fixnum = GuardType v1, Fixnum
2305- v7:BoolExact = FixnumNeq v5, v6
2306- Return v7
2312+ PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_EQ)
2313+ v6:Fixnum = GuardType v0, Fixnum
2314+ v7:Fixnum = GuardType v1, Fixnum
2315+ v8:BoolExact = FixnumNeq v6, v7
2316+ Return v8
23072317 "# ] ] ) ;
23082318 }
23092319
@@ -3105,10 +3115,11 @@ mod opt_tests {
31053115 fn test:
31063116 bb0(v0:BasicObject, v1:BasicObject):
31073117 PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_NEQ)
3108- v5:Fixnum = GuardType v0, Fixnum
3109- v6:Fixnum = GuardType v1, Fixnum
3110- v8:Fixnum[5] = Const Value(5)
3111- Return v8
3118+ PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_EQ)
3119+ v6:Fixnum = GuardType v0, Fixnum
3120+ v7:Fixnum = GuardType v1, Fixnum
3121+ v9:Fixnum[5] = Const Value(5)
3122+ Return v9
31123123 "# ] ] ) ;
31133124 }
31143125
0 commit comments