Skip to content

Commit b81201f

Browse files
committed
Restore Optimization and revert tests
1 parent 161329c commit b81201f

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,6 @@ def dummy(x):
630630
self.assertIn("_PUSH_FRAME", uops)
631631
self.assertIn("_BINARY_OP_ADD_INT", uops)
632632
self.assertNotIn("_CHECK_PEP_523", uops)
633-
self.assertNotIn("_GUARD_CODE_VERSION__PUSH_FRAME", uops)
634-
self.assertNotIn("_GUARD_IP__PUSH_FRAME", uops)
635633

636634
def test_int_type_propagate_through_range(self):
637635
def testfunc(n):
@@ -1542,9 +1540,8 @@ def testfunc(n):
15421540
self.assertIsNotNone(ex)
15431541
uops = get_opnames(ex)
15441542
self.assertIn("_PUSH_FRAME", uops)
1545-
# Both should be not present, as this is a call
1546-
# to a simple function with a known function version.
1547-
self.assertNotIn("_CHECK_FUNCTION_VERSION_INLINE", uops)
1543+
# Strength reduced version
1544+
self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops)
15481545
self.assertNotIn("_CHECK_FUNCTION_VERSION", uops)
15491546
# Removed guard
15501547
self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops)

Python/optimizer_bytecodes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,12 @@ dummy_func(void) {
864864
}
865865

866866
op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
867-
if (sym_get_func_version(callable) == func_version) {
868-
REPLACE_OP(this_instr, _NOP, 0, 0);
869-
}
870-
else {
871-
sym_set_func_version(ctx, callable, func_version);
867+
if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyFunction_Type)) {
868+
assert(PyFunction_Check(sym_get_const(ctx, callable)));
869+
ADD_OP(_CHECK_FUNCTION_VERSION_INLINE, 0, func_version);
870+
uop_buffer_last(&ctx->out_buffer)->operand1 = (uintptr_t)sym_get_const(ctx, callable);
872871
}
872+
sym_set_type(callable, &PyFunction_Type);
873873
}
874874

875875
op(_CHECK_METHOD_VERSION, (func_version/2, callable, null, unused[oparg] -- callable, null, unused[oparg])) {

Python/optimizer_cases.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_symbols.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ _Py_uop_sym_set_func_version(JitOptContext *ctx, JitOptRef ref, uint32_t version
522522
case JIT_SYM_PREDICATE_TAG:
523523
case JIT_SYM_TRUTHINESS_TAG:
524524
sym_set_bottom(ctx, sym);
525-
return true;
525+
return false;
526526
case JIT_SYM_RECORDED_VALUE_TAG: {
527527
PyObject *val = sym->recorded_value.value;
528528
if (Py_TYPE(val) != &PyFunction_Type ||

0 commit comments

Comments
 (0)