# But all of the appends we care about are still there:
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
+ def test_narrow_type_to_constant_int_zero(self):
+ def f(n):
+ trace = []
+ for i in range(n):
+ # zero is always (int) 0, but we can only prove that it's a integer:
+ false = i == TIER2_THRESHOLD # this will always be false, while hopefully still fooling optimizer improvements
+ zero = false + 0 # this should always set the variable zero equal to 0
+ trace.append("A")
+ if not zero: # Kept.
+ trace.append("B")
+ if not zero: # Removed!
+ trace.append("C")
+ trace.append("D")
+ if zero: # Removed!
+ trace.append("X")
+ trace.append("E")
+ trace.append("F")
+ if zero: # Removed!
+ trace.append("X")
+ trace.append("G")
+ return trace
+
+ trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
+ self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD)
+ self.assertIsNotNone(ex)
+ uops = get_opnames(ex)
+ # Only one guard remains:
+ self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 1)
+ self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 0)
+ # But all of the appends we care about are still there:
+ self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
def global_identity(x):
return x
Rémi Lapeyre
Soren Larsen
Amos Latteier
+Keenan Lau
Piers Lauder
Ben Laurie
Yoni Lavi
--- /dev/null
+Improve JIT understanding of integers in boolean context.
op(_TO_BOOL_INT, (value -- res)) {
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
sym_set_type(value, &PyLong_Type);
- res = sym_new_type(ctx, &PyBool_Type);
+ res = sym_new_truthiness(ctx, value, true);
}
}
value = stack_pointer[-1];
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
sym_set_type(value, &PyLong_Type);
- res = sym_new_type(ctx, &PyBool_Type);
+ res = sym_new_truthiness(ctx, value, true);
}
stack_pointer[-1] = res;
break;
else if (type == &PyBool_Type) {
_Py_uop_sym_set_const(ctx, value, Py_False);
}
+ else if (type == &PyLong_Type) {
+ _Py_uop_sym_set_const(ctx, value, Py_GetConstant(Py_CONSTANT_ZERO));
+ }
// TODO: More types (GH-130415)!
make_const(sym, const_val);
return;