Skip to content

Commit da2d057

Browse files
committed
simplify: fully port CondBranch to C (const-fold + IntConvert fwd)
Adds IntConvert forwarding path: if CondBranch condition comes from a widening IntConvert, forward the source register directly. Uses hir_type_size_in_bytes for size comparison. No C++ fallback needed — both paths (const-fold + IntConvert forwarding) now in C.
1 parent 2cd03da commit da2d057

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Python/jit/hir/simplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,8 +2763,7 @@ Register* simplifyInstr(Env& env, const Instr* instr) {
27632763
SimplifyEnv cenv = make_c_env();
27642764
auto *r = static_cast<Register*>(simplify_cond_branch_const_c(&cenv, instr));
27652765
sync_c_env(cenv);
2766-
if (r) return r;
2767-
return simplifyCondBranch(env, instr);
2766+
return r;
27682767
}
27692768
case Opcode::kCondBranchCheckType: {
27702769
SimplifyEnv cenv = make_c_env();

Python/jit/hir/simplify_c.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ void *simplify_cond_branch_const_c(SimplifyEnv *env, const void *instr) {
482482
void *branch = hir_c_create_branch_cpp(target);
483483
return simplify_env_emit(env, branch);
484484
}
485+
/* IntConvert forwarding: if cond is from a widening IntConvert, use src */
486+
extern void *hir_reg_instr(void *reg);
487+
void *cond_def = hir_reg_instr(cond);
488+
if (cond_def != NULL && hir_c_opcode(cond_def) == HIR_OP_IntConvert) {
489+
void *src = hir_c_get_operand(cond_def, 0);
490+
HirType convert_type = ((const HirIntConvert *)cond_def)->type;
491+
HirType src_type = hir_register_type(src);
492+
if (hir_type_size_in_bytes(&convert_type) >= hir_type_size_in_bytes(&src_type)) {
493+
extern void *hir_c_create_cond_branch_cpp(void *cond_reg, void *true_bb, void *false_bb);
494+
void *true_bb = hir_c_successor(instr, 0);
495+
void *false_bb = hir_c_successor(instr, 1);
496+
void *new_cb = hir_c_create_cond_branch_cpp(src, true_bb, false_bb);
497+
return simplify_env_emit(env, new_cb);
498+
}
499+
}
485500
return NULL;
486501
}
487502

0 commit comments

Comments
 (0)