Skip to content

Commit 2cd03da

Browse files
committed
simplify: fully port GuardType to C (identity + TNoneType→GuardIs)
Replaces partial identity-only C handler with full implementation. If input already has target type → return input (identity). If target is TNoneType → emit GuardIs(Py_None) via hir_c_create_guard_is. No C++ fallback needed — all paths covered.
1 parent 6751652 commit 2cd03da

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Python/jit/hir/simplify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,9 +2741,10 @@ Register* simplifyInstr(Env& env, const Instr* instr) {
27412741
return r;
27422742
}
27432743
case Opcode::kGuardType: {
2744-
auto *r = static_cast<Register*>(simplify_guard_type_identity_c(instr));
2745-
if (r) return r;
2746-
return simplifyGuardType(env, static_cast<const GuardType*>(instr));
2744+
SimplifyEnv cenv = make_c_env();
2745+
auto *r = static_cast<Register*>(simplify_guard_type_c(&cenv, instr));
2746+
sync_c_env(cenv);
2747+
return r;
27472748
}
27482749
case Opcode::kRefineType:
27492750
return static_cast<Register*>(simplify_refine_type_c(instr));

Python/jit/hir/simplify_c.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,22 @@ void *simplify_refine_type_c(const void *instr) {
6565
return NULL;
6666
}
6767

68-
/* ---- simplifyGuardType (partial — type-already-matches path) ----
69-
* If input already has the guarded type, GuardType is redundant. */
70-
void *simplify_guard_type_identity_c(const void *instr) {
68+
/* ---- simplifyGuardType ----
69+
* If input already has the guarded type, redundant.
70+
* If target is NoneType, convert to GuardIs(Py_None). */
71+
void *simplify_guard_type_c(SimplifyEnv *env, const void *instr) {
7172
void *input = hir_c_get_operand(instr, 0);
7273
HirType input_type = hir_register_type(input);
7374
HirType target = hir_c_guard_type_target(instr);
7475
if (hir_type_is_subtype(input_type, target)) {
7576
return input;
7677
}
78+
HirType t_none = HIR_TYPE_NONETYPE;
79+
if (hir_type_equal(&target, &t_none)) {
80+
extern void *hir_c_create_guard_is(void *func, void *target_obj, void *src);
81+
void *guard = hir_c_create_guard_is(env->func, Py_None, input);
82+
return simplify_env_emit(env, guard);
83+
}
7784
return NULL;
7885
}
7986

Python/jit/hir/simplify_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void *simplify_env_emit_use_type(SimplifyEnv *env, void *val, HirType type);
2828
/* Env-free handlers (return existing register or NULL) */
2929
void *simplify_check_c(const void *instr);
3030
void *simplify_refine_type_c(const void *instr);
31-
void *simplify_guard_type_identity_c(const void *instr);
31+
void *simplify_guard_type_c(SimplifyEnv *env, const void *instr);
3232
void *simplify_primitive_compare_box_true_c(const void *instr);
3333
void *simplify_unbox_box_c(const void *instr);
3434
void *simplify_cond_branch_check_type_c(SimplifyEnv *env, const void *instr);

0 commit comments

Comments
 (0)