Skip to content

Commit fd45430

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Update IR
2 parents cff76a9 + 2b98408 commit fd45430

File tree

3 files changed

+130
-38
lines changed

3 files changed

+130
-38
lines changed

ext/opcache/jit/ir/ir_fold.h

+33-2
Original file line numberDiff line numberDiff line change
@@ -1859,8 +1859,39 @@ IR_FOLD(SUB(ADD, ADD))
18591859
}
18601860

18611861
// IR_FOLD(SUB(NEG, CONST)) TODO: -a - b => -b - a
1862-
// IR_FOLD(MUL(NEG, CONST)) TODO: -a * b => a * -b
1863-
// IR_FOLD(DIV(NEG, CONST)) TODO: -a / b => a / -b
1862+
1863+
IR_FOLD(MUL(NEG, C_I8))
1864+
IR_FOLD(MUL(NEG, C_I16))
1865+
IR_FOLD(MUL(NEG, C_I32))
1866+
IR_FOLD(MUL(NEG, C_I64))
1867+
IR_FOLD(DIV(NEG, C_I8))
1868+
IR_FOLD(DIV(NEG, C_I16))
1869+
IR_FOLD(DIV(NEG, C_I32))
1870+
IR_FOLD(DIV(NEG, C_I64))
1871+
{
1872+
op1 = op1_insn->op1;
1873+
val.i64 = -op2_insn->val.i64;
1874+
op2 = ir_const(ctx, val, op2_insn->type);
1875+
IR_FOLD_RESTART;
1876+
}
1877+
1878+
IR_FOLD(MUL(NEG, C_FLOAT))
1879+
IR_FOLD(DIV(NEG, C_FLOAT))
1880+
{
1881+
op1 = op1_insn->op1;
1882+
val.f = -op2_insn->val.f;
1883+
op2 = ir_const(ctx, val, op2_insn->type);
1884+
IR_FOLD_RESTART;
1885+
}
1886+
1887+
IR_FOLD(MUL(NEG, C_DOUBLE))
1888+
IR_FOLD(DIV(NEG, C_DOUBLE))
1889+
{
1890+
op1 = op1_insn->op1;
1891+
val.d = -op2_insn->val.d;
1892+
op2 = ir_const(ctx, val, op2_insn->type);
1893+
IR_FOLD_RESTART;
1894+
}
18641895

18651896
IR_FOLD(MUL(_, C_U8))
18661897
IR_FOLD(MUL(_, C_U16))

ext/opcache/jit/ir/ir_sccp.c

+30-27
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ static bool ir_may_promote_f2d(ir_ctx *ctx, ir_ref ref)
15171517
return 0;
15181518
}
15191519

1520-
static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
1520+
static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_bitqueue *worklist)
15211521
{
15221522
ir_insn *insn = &ctx->ir_base[ref];
15231523
uint32_t count;
@@ -1526,6 +1526,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
15261526
if (IR_IS_CONST_REF(ref)) {
15271527
return ir_const_float(ctx, (float)insn->val.d);
15281528
} else {
1529+
ir_bitqueue_add(worklist, ref);
15291530
switch (insn->op) {
15301531
case IR_FP2FP:
15311532
count = ctx->use_lists[ref].count;
@@ -1555,7 +1556,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
15551556
// return ref;
15561557
case IR_NEG:
15571558
case IR_ABS:
1558-
insn->op1 = ir_promote_d2f(ctx, insn->op1, ref);
1559+
insn->op1 = ir_promote_d2f(ctx, insn->op1, ref, worklist);
15591560
insn->type = IR_FLOAT;
15601561
return ref;
15611562
case IR_ADD:
@@ -1565,10 +1566,10 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
15651566
case IR_MIN:
15661567
case IR_MAX:
15671568
if (insn->op1 == insn->op2) {
1568-
insn->op2 = insn->op1 = ir_promote_d2f(ctx, insn->op1, ref);
1569+
insn->op2 = insn->op1 = ir_promote_d2f(ctx, insn->op1, ref, worklist);
15691570
} else {
1570-
insn->op1 = ir_promote_d2f(ctx, insn->op1, ref);
1571-
insn->op2 = ir_promote_d2f(ctx, insn->op2, ref);
1571+
insn->op1 = ir_promote_d2f(ctx, insn->op1, ref, worklist);
1572+
insn->op2 = ir_promote_d2f(ctx, insn->op2, ref, worklist);
15721573
}
15731574
insn->type = IR_FLOAT;
15741575
return ref;
@@ -1580,7 +1581,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
15801581
return ref;
15811582
}
15821583

1583-
static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
1584+
static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_bitqueue *worklist)
15841585
{
15851586
ir_insn *insn = &ctx->ir_base[ref];
15861587
uint32_t count;
@@ -1590,6 +1591,7 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
15901591
if (IR_IS_CONST_REF(ref)) {
15911592
return ir_const_double(ctx, (double)insn->val.f);
15921593
} else {
1594+
ir_bitqueue_add(worklist, ref);
15931595
switch (insn->op) {
15941596
case IR_FP2FP:
15951597
count = ctx->use_lists[ref].count;
@@ -1628,7 +1630,7 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
16281630
return ref;
16291631
case IR_NEG:
16301632
case IR_ABS:
1631-
insn->op1 = ir_promote_f2d(ctx, insn->op1, ref);
1633+
insn->op1 = ir_promote_f2d(ctx, insn->op1, ref, worklist);
16321634
insn->type = IR_DOUBLE;
16331635
return ref;
16341636
case IR_ADD:
@@ -1638,10 +1640,10 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
16381640
case IR_MIN:
16391641
case IR_MAX:
16401642
if (insn->op1 == insn->op2) {
1641-
insn->op2 = insn->op1 = ir_promote_f2d(ctx, insn->op1, ref);
1643+
insn->op2 = insn->op1 = ir_promote_f2d(ctx, insn->op1, ref, worklist);
16421644
} else {
1643-
insn->op1 = ir_promote_f2d(ctx, insn->op1, ref);
1644-
insn->op2 = ir_promote_f2d(ctx, insn->op2, ref);
1645+
insn->op1 = ir_promote_f2d(ctx, insn->op1, ref, worklist);
1646+
insn->op2 = ir_promote_f2d(ctx, insn->op2, ref, worklist);
16451647
}
16461648
insn->type = IR_DOUBLE;
16471649
return ref;
@@ -1707,7 +1709,7 @@ static bool ir_may_promote_trunc(ir_ctx *ctx, ir_type type, ir_ref ref)
17071709
}
17081710
}
17091711
}
1710-
for (p = insn->ops + 1, n = insn->inputs_count - 1; n > 0; p++, n--) {
1712+
for (p = insn->ops + 2, n = insn->inputs_count - 1; n > 0; p++, n--) {
17111713
input = *p;
17121714
if (input != ref) {
17131715
if (!ir_may_promote_trunc(ctx, type, input)) {
@@ -1723,7 +1725,7 @@ static bool ir_may_promote_trunc(ir_ctx *ctx, ir_type type, ir_ref ref)
17231725
return 0;
17241726
}
17251727

1726-
static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
1728+
static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use, ir_bitqueue *worklist)
17271729
{
17281730
ir_insn *insn = &ctx->ir_base[ref];
17291731
uint32_t count;
@@ -1732,6 +1734,7 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
17321734
if (IR_IS_CONST_REF(ref)) {
17331735
return ir_const(ctx, insn->val, type);
17341736
} else {
1737+
ir_bitqueue_add(worklist, ref);
17351738
switch (insn->op) {
17361739
case IR_ZEXT:
17371740
case IR_SEXT:
@@ -1776,7 +1779,7 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
17761779
case IR_NEG:
17771780
case IR_ABS:
17781781
case IR_NOT:
1779-
insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref);
1782+
insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref, worklist);
17801783
insn->type = type;
17811784
return ref;
17821785
case IR_ADD:
@@ -1789,10 +1792,10 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
17891792
case IR_XOR:
17901793
case IR_SHL:
17911794
if (insn->op1 == insn->op2) {
1792-
insn->op2 = insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref);
1795+
insn->op2 = insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref, worklist);
17931796
} else {
1794-
insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref);
1795-
insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref);
1797+
insn->op1 = ir_promote_i2i(ctx, type, insn->op1, ref, worklist);
1798+
insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref, worklist);
17961799
}
17971800
insn->type = type;
17981801
return ref;
@@ -1804,18 +1807,18 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
18041807
// TODO: ???
18051808
case IR_COND:
18061809
if (insn->op2 == insn->op3) {
1807-
insn->op3 = insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref);
1810+
insn->op3 = insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref, worklist);
18081811
} else {
1809-
insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref);
1810-
insn->op3 = ir_promote_i2i(ctx, type, insn->op3, ref);
1812+
insn->op2 = ir_promote_i2i(ctx, type, insn->op2, ref, worklist);
1813+
insn->op3 = ir_promote_i2i(ctx, type, insn->op3, ref, worklist);
18111814
}
18121815
insn->type = type;
18131816
return ref;
18141817
case IR_PHI:
1815-
for (p = insn->ops + 1, n = insn->inputs_count - 1; n > 0; p++, n--) {
1818+
for (p = insn->ops + 2, n = insn->inputs_count - 1; n > 0; p++, n--) {
18161819
input = *p;
18171820
if (input != ref) {
1818-
*p = ir_promote_i2i(ctx, type, input, ref);
1821+
*p = ir_promote_i2i(ctx, type, input, ref, worklist);
18191822
}
18201823
}
18211824
insn->type = type;
@@ -1906,7 +1909,7 @@ static uint32_t _ir_estimated_control(ir_ctx *ctx, ir_ref val)
19061909
}
19071910

19081911
IR_ASSERT(ir_op_flags[insn->op] & IR_OP_FLAG_DATA);
1909-
if (IR_OPND_KIND(ir_op_flags[insn->op], 1) & IR_OPND_CONTROL_DEP) {
1912+
if (IR_OPND_KIND(ir_op_flags[insn->op], 1) == IR_OPND_CONTROL_DEP) {
19101913
return insn->op1;
19111914
}
19121915

@@ -3479,14 +3482,14 @@ void ir_iter_opt(ir_ctx *ctx, ir_bitqueue *worklist)
34793482
case IR_FP2FP:
34803483
if (insn->type == IR_FLOAT) {
34813484
if (ir_may_promote_d2f(ctx, insn->op1)) {
3482-
ir_ref ref = ir_promote_d2f(ctx, insn->op1, i);
3485+
ir_ref ref = ir_promote_d2f(ctx, insn->op1, i, worklist);
34833486
insn->op1 = ref;
34843487
ir_iter_replace_insn(ctx, i, ref, worklist);
34853488
break;
34863489
}
34873490
} else {
34883491
if (ir_may_promote_f2d(ctx, insn->op1)) {
3489-
ir_ref ref = ir_promote_f2d(ctx, insn->op1, i);
3492+
ir_ref ref = ir_promote_f2d(ctx, insn->op1, i, worklist);
34903493
insn->op1 = ref;
34913494
ir_iter_replace_insn(ctx, i, ref, worklist);
34923495
break;
@@ -3496,17 +3499,17 @@ void ir_iter_opt(ir_ctx *ctx, ir_bitqueue *worklist)
34963499
case IR_FP2INT:
34973500
if (ctx->ir_base[insn->op1].type == IR_DOUBLE) {
34983501
if (ir_may_promote_d2f(ctx, insn->op1)) {
3499-
insn->op1 = ir_promote_d2f(ctx, insn->op1, i);
3502+
insn->op1 = ir_promote_d2f(ctx, insn->op1, i, worklist);
35003503
}
35013504
} else {
35023505
if (ir_may_promote_f2d(ctx, insn->op1)) {
3503-
insn->op1 = ir_promote_f2d(ctx, insn->op1, i);
3506+
insn->op1 = ir_promote_f2d(ctx, insn->op1, i, worklist);
35043507
}
35053508
}
35063509
goto folding;
35073510
case IR_TRUNC:
35083511
if (ir_may_promote_trunc(ctx, insn->type, insn->op1)) {
3509-
ir_ref ref = ir_promote_i2i(ctx, insn->type, insn->op1, i);
3512+
ir_ref ref = ir_promote_i2i(ctx, insn->type, insn->op1, i, worklist);
35103513
insn->op1 = ref;
35113514
ir_iter_replace_insn(ctx, i, ref, worklist);
35123515
break;

0 commit comments

Comments
 (0)