gh-131798: Optimize _UNARY_INVERT
(GH-135222)
This commit is contained in:
parent
c19e36cc4e
commit
b150b6aca7
@ -2275,6 +2275,21 @@ class TestUopsOptimization(unittest.TestCase):
|
||||
self.assertIn("_UNPACK_SEQUENCE_TWO_TUPLE", uops)
|
||||
self.assertNotIn("_GUARD_TOS_TUPLE", uops)
|
||||
|
||||
def test_unary_invert_long_type(self):
|
||||
def testfunc(n):
|
||||
for _ in range(n):
|
||||
a = 9397
|
||||
x = ~a + ~a
|
||||
|
||||
testfunc(TIER2_THRESHOLD)
|
||||
|
||||
ex = get_first_executor(testfunc)
|
||||
self.assertIsNotNone(ex)
|
||||
uops = get_opnames(ex)
|
||||
|
||||
self.assertNotIn("_GUARD_TOS_INT", uops)
|
||||
self.assertNotIn("_GUARD_NOS_INT", uops)
|
||||
|
||||
|
||||
def global_identity(x):
|
||||
return x
|
||||
|
@ -0,0 +1 @@
|
||||
Optimize ``_UNARY_INVERT`` in JIT-compiled code.
|
@ -467,6 +467,15 @@ dummy_func(void) {
|
||||
res = sym_new_truthiness(ctx, value, false);
|
||||
}
|
||||
|
||||
op(_UNARY_INVERT, (value -- res)) {
|
||||
if (sym_matches_type(value, &PyLong_Type)) {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
else {
|
||||
res = sym_new_not_null(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
op(_COMPARE_OP, (left, right -- res)) {
|
||||
if (oparg & 16) {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
|
7
Python/optimizer_cases.c.h
generated
7
Python/optimizer_cases.c.h
generated
@ -285,8 +285,15 @@
|
||||
}
|
||||
|
||||
case _UNARY_INVERT: {
|
||||
JitOptSymbol *value;
|
||||
JitOptSymbol *res;
|
||||
value = stack_pointer[-1];
|
||||
if (sym_matches_type(value, &PyLong_Type)) {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
else {
|
||||
res = sym_new_not_null(ctx);
|
||||
}
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user