Skip to content

Commit ade9151

Browse files
committed
simplify: add Compare Bool/Float/Long paths with named type constants
Root cause of prior failures: raw hex 0x00000010000 was TListExact, not TLongExact (0x00000000400). List comparisons matched the Long path and got LongCompare which returns NotImplemented. Fix: use HIR_TYPE_LONGEXACT, HIR_TYPE_FLOATEXACT, HIR_TYPE_NONETYPE, HIR_TYPE_BOOL named constants from hir_type_c.h. No more raw hex. Compare handler now covers None, Bool, Float, Long (4/5 paths). Only UnicodeCompare remains as C++ fallback.
1 parent aa14a88 commit ade9151

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Python/jit/hir/simplify_c.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void *simplify_compare_c(SimplifyEnv *env, const void *instr) {
149149
HirType right_type = hir_register_type(right);
150150
int32_t op = hir_c_compare_op(instr);
151151

152-
HirType t_none = HIR_TYPE_SIMPLE(0x00000000080ULL, HIR_TYPE_LIFETIME_TOP);
152+
HirType t_none = HIR_TYPE_NONETYPE;
153153

154154
/* None == None or None != None */
155155
if (hir_type_is_subtype(left_type, t_none) &&
@@ -162,6 +162,34 @@ void *simplify_compare_c(SimplifyEnv *env, const void *instr) {
162162
}
163163
}
164164

165+
/* Bool == Bool or Bool != Bool → PrimitiveCompare + PrimitiveBoxBool */
166+
HirType t_bool = HIR_TYPE_BOOL;
167+
if (hir_type_is_subtype(left_type, t_bool) &&
168+
hir_type_is_subtype(right_type, t_bool) &&
169+
(op == HIR_CMP_Equal || op == HIR_CMP_NotEqual)) {
170+
int32_t prim_op = (op == HIR_CMP_Equal) ? HIR_PCMP_Equal : HIR_PCMP_NotEqual;
171+
simplify_env_emit_use_type(env, left, t_bool);
172+
simplify_env_emit_use_type(env, right, t_bool);
173+
void *result = simplify_env_emit_primitive_compare(env, prim_op, left, right);
174+
return simplify_env_emit_primitive_box_bool(env, result);
175+
}
176+
177+
/* Float comparison (not In/NotIn/ExcMatch) */
178+
HirType t_float_exact = HIR_TYPE_FLOATEXACT;
179+
if (hir_type_is_subtype(left_type, t_float_exact) &&
180+
hir_type_is_subtype(right_type, t_float_exact) &&
181+
op != HIR_CMP_In && op != HIR_CMP_NotIn && op != HIR_CMP_ExcMatch) {
182+
return simplify_env_emit_float_compare(env, op, left, right);
183+
}
184+
185+
/* Long comparison (not In/NotIn/ExcMatch) */
186+
HirType t_long_exact = HIR_TYPE_LONGEXACT;
187+
if (hir_type_is_subtype(left_type, t_long_exact) &&
188+
hir_type_is_subtype(right_type, t_long_exact) &&
189+
op != HIR_CMP_In && op != HIR_CMP_NotIn && op != HIR_CMP_ExcMatch) {
190+
return simplify_env_emit_long_compare(env, op, left, right);
191+
}
192+
165193
return NULL;
166194
}
167195

0 commit comments

Comments
 (0)