Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Update IR
  • Loading branch information
dstogov committed Feb 24, 2025
2 parents 9ed83e1 + 819b198 commit 1a10b99
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 125 deletions.
148 changes: 56 additions & 92 deletions ext/opcache/jit/ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2407,20 +2407,67 @@ void _ir_BEGIN(ir_ctx *ctx, ir_ref src)
}
}

ir_ref _ir_fold_condition(ir_ctx *ctx, ir_ref ref)
static ir_ref _ir_fold_condition(ir_ctx *ctx, ir_ref ref)
{
ir_insn *insn = &ctx->ir_base[ref];

if (insn->op == IR_NE && IR_IS_CONST_REF(insn->op2)) {
ir_insn *op2_insn = &ctx->ir_base[insn->op2];

if (IR_IS_TYPE_INT(op2_insn->type) && op2_insn->val.u64 == 0) {
return insn->op1;
ref = insn->op1;
insn = &ctx->ir_base[ref];
}
} else if (insn->op == IR_EQ && insn->op2 == IR_TRUE) {
ref = insn->op1;
insn = &ctx->ir_base[ref];
}
// while (insn->op == IR_SEXT || insn->op == IR_ZEXT || insn->op == IR_BITCAST) {
// ref = insn->op1;
// insn = &ctx->ir_base[ref];
// }
return ref;
}

IR_ALWAYS_INLINE ir_ref ir_check_dominating_predicates_i(ir_ctx *ctx, ir_ref ref, ir_ref condition, ir_ref limit)
{
ir_insn *prev = NULL;
ir_insn *insn;

while (ref > limit) {
insn = &ctx->ir_base[ref];
if (insn->op == IR_GUARD_NOT) {
if (insn->op2 == condition) {
return IR_FALSE;
}
} else if (insn->op == IR_GUARD) {
if (insn->op2 == condition) {
return IR_TRUE;
}
} else if (insn->op == IR_IF) {
if (insn->op2 == condition) {
if (prev->op == IR_IF_TRUE) {
return IR_TRUE;
} else if (prev->op == IR_IF_FALSE) {
return IR_FALSE;
}
}
} else if (insn->op == IR_START || insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) {
break;
}
prev = insn;
ref = insn->op1;
}

return condition;
}

ir_ref ir_check_dominating_predicates(ir_ctx *ctx, ir_ref ref, ir_ref condition)
{
IR_ASSERT(!IR_IS_CONST_REF(condition));
return ir_check_dominating_predicates_i(ctx, ref, condition, (condition < ref) ? condition : 1);
}

ir_ref _ir_IF(ir_ctx *ctx, ir_ref condition)
{
ir_ref if_ref;
Expand All @@ -2436,38 +2483,7 @@ ir_ref _ir_IF(ir_ctx *ctx, ir_ref condition)
if (IR_IS_CONST_REF(condition)) {
condition = ir_ref_is_true(ctx, condition) ? IR_TRUE : IR_FALSE;
} else {
ir_insn *prev = NULL;
ir_ref ref = ctx->control;
ir_insn *insn;

while (ref > condition) {
insn = &ctx->ir_base[ref];
if (insn->op == IR_GUARD_NOT) {
if (insn->op2 == condition) {
condition = IR_FALSE;
break;
}
} else if (insn->op == IR_GUARD) {
if (insn->op2 == condition) {
condition = IR_TRUE;
break;
}
} else if (insn->op == IR_IF) {
if (insn->op2 == condition) {
if (prev->op == IR_IF_TRUE) {
condition = IR_TRUE;
break;
} else if (prev->op == IR_IF_FALSE) {
condition = IR_FALSE;
break;
}
}
} else if (insn->op == IR_START || insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) {
break;
}
prev = insn;
ref = insn->op1;
}
condition = ir_check_dominating_predicates_i(ctx, ctx->control, condition, condition);
}
if_ref = ir_emit2(ctx, IR_IF, ctx->control, condition);
ctx->control = IR_UNUSED;
Expand Down Expand Up @@ -2986,35 +3002,9 @@ void _ir_GUARD(ir_ctx *ctx, ir_ref condition, ir_ref addr)
}
condition = IR_FALSE;
} else if (EXPECTED(ctx->flags & IR_OPT_FOLDING)) {
ir_insn *prev = NULL;
ir_ref ref = ctx->control;
ir_insn *insn;

while (ref > condition) {
insn = &ctx->ir_base[ref];
if (insn->op == IR_GUARD) {
if (insn->op2 == condition) {
return;
}
} else if (insn->op == IR_GUARD_NOT) {
if (insn->op2 == condition) {
condition = IR_FALSE;
break;
}
} else if (insn->op == IR_IF) {
if (insn->op2 == condition) {
if (prev->op == IR_IF_TRUE) {
return;
} else if (prev->op == IR_IF_FALSE) {
condition = IR_FALSE;
break;
}
}
} else if (insn->op == IR_START || insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) {
break;
}
prev = insn;
ref = insn->op1;
condition = ir_check_dominating_predicates_i(ctx, ctx->control, condition, condition);
if (condition == IR_TRUE) {
return;
}
}
if (ctx->snapshot_create) {
Expand All @@ -3032,35 +3022,9 @@ void _ir_GUARD_NOT(ir_ctx *ctx, ir_ref condition, ir_ref addr)
}
condition = IR_TRUE;
} else if (EXPECTED(ctx->flags & IR_OPT_FOLDING)) {
ir_insn *prev = NULL;
ir_ref ref = ctx->control;
ir_insn *insn;

while (ref > condition) {
insn = &ctx->ir_base[ref];
if (insn->op == IR_GUARD_NOT) {
if (insn->op2 == condition) {
return;
}
} else if (insn->op == IR_GUARD) {
if (insn->op2 == condition) {
condition = IR_TRUE;
break;
}
} else if (insn->op == IR_IF) {
if (insn->op2 == condition) {
if (prev->op == IR_IF_TRUE) {
condition = IR_TRUE;
break;
} else if (prev->op == IR_IF_FALSE) {
return;
}
}
} else if (insn->op == IR_START || insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) {
break;
}
prev = insn;
ref = insn->op1;
condition = ir_check_dominating_predicates_i(ctx, ctx->control, condition, condition);
if (condition == IR_FALSE) {
return;
}
}
if (ctx->snapshot_create) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/ir/ir_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ extern "C" {

#define ir_ALLOCA(_size) _ir_ALLOCA(_ir_CTX, (_size))
#define ir_AFREE(_size) _ir_AFREE(_ir_CTX, (_size))
#define ir_VADDR(_var) ir_emit1(_ir_CTX, IR_OPT(IR_VADDR, IR_ADDR), (_var))
#define ir_VADDR(_var) ir_fold1(_ir_CTX, IR_OPT(IR_VADDR, IR_ADDR), (_var))
#define ir_VLOAD(_type, _var) _ir_VLOAD(_ir_CTX, (_type), (_var))
#define ir_VLOAD_B(_var) _ir_VLOAD(_ir_CTX, IR_BOOL, (_var))
#define ir_VLOAD_U8(_var) _ir_VLOAD(_ir_CTX, IR_U8, (_var))
Expand Down
3 changes: 3 additions & 0 deletions ext/opcache/jit/ir/ir_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,9 @@ ir_ref ir_find_aliasing_vload(ir_ctx *ctx, ir_ref ref, ir_type type, ir_ref var)
ir_ref ir_find_aliasing_store(ir_ctx *ctx, ir_ref ref, ir_ref addr, ir_ref val);
ir_ref ir_find_aliasing_vstore(ir_ctx *ctx, ir_ref ref, ir_ref addr, ir_ref val);

/*** Predicates (see ir.c) ***/
ir_ref ir_check_dominating_predicates(ir_ctx *ctx, ir_ref ref, ir_ref condition);

/*** IR Live Info ***/
typedef ir_ref ir_live_pos;
typedef struct _ir_use_pos ir_use_pos;
Expand Down
Loading

0 comments on commit 1a10b99

Please sign in to comment.