MJIT: Revert FL_EXIVAR check optimization

It seems to slow down optcarrot. I'll revisit this later.
This commit is contained in:
Takashi Kokubun 2022-11-29 22:35:17 -08:00
parent a1d70f5b12
commit d0c0d7fa5b

View File

@ -89,15 +89,10 @@ class RubyVM::MJIT::Compiler
end end
# Generate merged ivar guards first if needed # Generate merged ivar guards first if needed
has_getivar, has_setivar = ivar_usages(iseq.body) if !status.compile_info.disable_ivar_cache && using_ivar?(iseq.body)
if !status.compile_info.disable_ivar_cache && (has_getivar || has_setivar)
src << " if (UNLIKELY(!RB_TYPE_P(GET_SELF(), T_OBJECT))) {" src << " if (UNLIKELY(!RB_TYPE_P(GET_SELF(), T_OBJECT))) {"
src << " goto ivar_cancel;\n" src << " goto ivar_cancel;\n"
src << " }\n" src << " }\n"
elsif !status.compile_info.disable_exivar_cache && has_getivar
src << " if (UNLIKELY(!FL_TEST_RAW(GET_SELF(), FL_EXIVAR))) {"
src << " goto ivar_cancel;\n"
src << " }\n"
end end
compile_insns(0, 0, status, iseq.body, src) compile_insns(0, 0, status, iseq.body, src)
@ -345,7 +340,7 @@ class RubyVM::MJIT::Compiler
# JIT: prepare vm_getivar/vm_setivar arguments and variables # JIT: prepare vm_getivar/vm_setivar arguments and variables
src << "{\n" src << "{\n"
src << " VALUE obj = GET_SELF();\n" src << " VALUE obj = GET_SELF();\n" # T_OBJECT guaranteed by compile_body
# JIT: cache hit path of vm_getivar/vm_setivar, or cancel JIT (recompile it with exivar) # JIT: cache hit path of vm_getivar/vm_setivar, or cancel JIT (recompile it with exivar)
if insn_name == :setinstancevariable if insn_name == :setinstancevariable
src << " const uint32_t index = #{attr_index - 1};\n" src << " const uint32_t index = #{attr_index - 1};\n"
@ -386,7 +381,7 @@ class RubyVM::MJIT::Compiler
src << " const uint32_t index = #{attr_index - 1};\n" src << " const uint32_t index = #{attr_index - 1};\n"
# JIT: cache hit path of vm_getivar, or cancel JIT (recompile it without any ivar optimization) # JIT: cache hit path of vm_getivar, or cancel JIT (recompile it without any ivar optimization)
src << " struct gen_ivtbl *ivtbl;\n" src << " struct gen_ivtbl *ivtbl;\n"
src << " if (LIKELY(source_shape_id == rb_shape_get_shape_id(obj) && rb_ivar_generic_ivtbl_lookup(obj, &ivtbl))) {\n" src << " if (LIKELY(FL_TEST_RAW(GET_SELF(), FL_EXIVAR) && source_shape_id == rb_shape_get_shape_id(obj) && rb_ivar_generic_ivtbl_lookup(obj, &ivtbl))) {\n"
src << " stack[#{stack_size}] = ivtbl->ivptr[index];\n" src << " stack[#{stack_size}] = ivtbl->ivptr[index];\n"
src << " }\n" src << " }\n"
src << " else {\n" src << " else {\n"
@ -788,22 +783,17 @@ class RubyVM::MJIT::Compiler
end end
end end
def ivar_usages(body) def using_ivar?(body)
has_getivar = false
has_setivar = false
pos = 0 pos = 0
while pos < body.iseq_size while pos < body.iseq_size
insn = INSNS.fetch(C.rb_vm_insn_decode(body.iseq_encoded[pos])) insn = INSNS.fetch(C.rb_vm_insn_decode(body.iseq_encoded[pos]))
case insn.name case insn.name
when :getinstancevariable when :getinstancevariable, :setinstancevariable
has_getivar = true return true
when :setinstancevariable
has_setivar = true
end end
break if has_getivar && has_setivar
pos += insn.len pos += insn.len
end end
return has_getivar, has_setivar return false
end end
# Expand simple macro that doesn't require dynamic C code. # Expand simple macro that doesn't require dynamic C code.