summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-03-05 15:23:08 (GMT)
committerGitHub <noreply@github.com>2024-03-05 15:23:08 (GMT)
commit23db9c62272f7470aadf8f52fe3ebb42b5e5d380 (patch)
treed3794d721c4e97f691fa0c5bed595f219075f4b7 /Python
parent0c81ce13602b88fd59f23f701ed8dc377d74e76e (diff)
downloadcpython-23db9c62272f7470aadf8f52fe3ebb42b5e5d380.zip
cpython-23db9c62272f7470aadf8f52fe3ebb42b5e5d380.tar.gz
cpython-23db9c62272f7470aadf8f52fe3ebb42b5e5d380.tar.bz2
GH-115685: Split `_TO_BOOL_ALWAYS_TRUE` into micro-ops (GH-116352)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c13
-rw-r--r--Python/executor_cases.c.h7
-rw-r--r--Python/generated_cases.c.h23
-rw-r--r--Python/optimizer_analysis.c3
-rw-r--r--Python/optimizer_cases.c.h2
5 files changed, 27 insertions, 21 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 396a8f0..15794cb 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -382,15 +382,16 @@ dummy_func(
}
}
- inst(TO_BOOL_ALWAYS_TRUE, (unused/1, version/2, value -- res)) {
- // This one is a bit weird, because we expect *some* failures:
- assert(version);
- EXIT_IF(Py_TYPE(value)->tp_version_tag != version);
- STAT_INC(TO_BOOL, hit);
- DECREF_INPUTS();
+ op(_REPLACE_WITH_TRUE, (value -- res)) {
+ Py_DECREF(value);
res = Py_True;
}
+ macro(TO_BOOL_ALWAYS_TRUE) =
+ unused/1 +
+ _GUARD_TYPE_VERSION +
+ _REPLACE_WITH_TRUE;
+
inst(UNARY_INVERT, (value -- res)) {
res = PyNumber_Invert(value);
DECREF_INPUTS();
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 56ee938..806f748 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -383,15 +383,10 @@
break;
}
- case _TO_BOOL_ALWAYS_TRUE: {
+ case _REPLACE_WITH_TRUE: {
PyObject *value;
PyObject *res;
value = stack_pointer[-1];
- uint32_t version = (uint32_t)CURRENT_OPERAND();
- // This one is a bit weird, because we expect *some* failures:
- assert(version);
- if (Py_TYPE(value)->tp_version_tag != version) goto side_exit;
- STAT_INC(TO_BOOL, hit);
Py_DECREF(value);
res = Py_True;
stack_pointer[-1] = res;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index e612c9e..4947c91 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -5580,17 +5580,24 @@
next_instr += 4;
INSTRUCTION_STATS(TO_BOOL_ALWAYS_TRUE);
static_assert(INLINE_CACHE_ENTRIES_TO_BOOL == 3, "incorrect cache size");
+ PyObject *owner;
PyObject *value;
PyObject *res;
/* Skip 1 cache entry */
- value = stack_pointer[-1];
- uint32_t version = read_u32(&this_instr[2].cache);
- // This one is a bit weird, because we expect *some* failures:
- assert(version);
- DEOPT_IF(Py_TYPE(value)->tp_version_tag != version, TO_BOOL);
- STAT_INC(TO_BOOL, hit);
- Py_DECREF(value);
- res = Py_True;
+ // _GUARD_TYPE_VERSION
+ owner = stack_pointer[-1];
+ {
+ uint32_t type_version = read_u32(&this_instr[2].cache);
+ PyTypeObject *tp = Py_TYPE(owner);
+ assert(type_version != 0);
+ DEOPT_IF(tp->tp_version_tag != type_version, TO_BOOL);
+ }
+ // _REPLACE_WITH_TRUE
+ value = owner;
+ {
+ Py_DECREF(value);
+ res = Py_True;
+ }
stack_pointer[-1] = res;
DISPATCH();
}
diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c
index 21cccdb..18e3382 100644
--- a/Python/optimizer_analysis.c
+++ b/Python/optimizer_analysis.c
@@ -456,6 +456,9 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
last->opcode = _NOP;
buffer[pc].opcode = NOP;
}
+ if (last->opcode == _REPLACE_WITH_TRUE) {
+ last->opcode = _NOP;
+ }
break;
}
case _JUMP_TO_TOP:
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index 6e65e2e..4ed1ac9 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -203,7 +203,7 @@
break;
}
- case _TO_BOOL_ALWAYS_TRUE: {
+ case _REPLACE_WITH_TRUE: {
_Py_UopsSymbol *res;
res = sym_new_unknown(ctx);
if (res == NULL) goto out_of_space;