Skip to content

Commit bda1218

Browse files
authored
gh-131798: Optimize _UNARY_NEGATIVE (GH-135223)
1 parent 569fc68 commit bda1218

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,24 @@ def testfunc(n):
24322432
self.assertIn("_POP_TOP_FLOAT", uops)
24332433

24342434

2435+
def test_unary_negative_long_float_type(self):
2436+
def testfunc(n):
2437+
for _ in range(n):
2438+
a = 9397
2439+
f = 9397.0
2440+
x = -a + -a
2441+
y = -f + -f
2442+
2443+
testfunc(TIER2_THRESHOLD)
2444+
2445+
ex = get_first_executor(testfunc)
2446+
self.assertIsNotNone(ex)
2447+
uops = get_opnames(ex)
2448+
2449+
self.assertNotIn("_GUARD_TOS_INT", uops)
2450+
self.assertNotIn("_GUARD_NOS_INT", uops)
2451+
self.assertNotIn("_GUARD_TOS_FLOAT", uops)
2452+
self.assertNotIn("_GUARD_NOS_FLOAT", uops)
24352453

24362454
def global_identity(x):
24372455
return x
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize ``_UNARY_NEGATIVE`` in JIT-compiled code.

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@ dummy_func(void) {
452452
res = sym_new_compact_int(ctx);
453453
}
454454
else {
455-
res = sym_new_not_null(ctx);
455+
PyTypeObject *type = sym_get_type(value);
456+
if (type == &PyLong_Type || type == &PyFloat_Type) {
457+
res = sym_new_type(ctx, type);
458+
}
459+
else {
460+
res = sym_new_not_null(ctx);
461+
}
456462
}
457463
}
458464

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy