Skip to content

Commit 2289af8

Browse files
committed
Update IR
IR commit: ab6ebce1cc25f7d2c634bd13af043f76d6ef524e
1 parent a3620cd commit 2289af8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

ext/opcache/jit/ir/ir_aarch64.dasc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,7 @@ static void ir_emit_sdiv_pwr2(ir_ctx *ctx, ir_ref def, ir_insn *insn)
21172117
uint32_t shift = IR_LOG2(ctx->ir_base[insn->op2].val.u64);
21182118
int64_t offset = ctx->ir_base[insn->op2].val.u64 - 1;
21192119

2120+
IR_ASSERT(shift != 0);
21202121
IR_ASSERT(IR_IS_CONST_REF(insn->op2));
21212122
IR_ASSERT(!IR_IS_SYM_CONST(ctx->ir_base[insn->op2].op));
21222123
IR_ASSERT(def_reg != IR_REG_NONE && op1_reg != IR_REG_NONE && def_reg != op1_reg);
@@ -2173,6 +2174,7 @@ static void ir_emit_smod_pwr2(ir_ctx *ctx, ir_ref def, ir_insn *insn)
21732174
// uint32_t shift = IR_LOG2(ctx->ir_base[insn->op2].val.u64);
21742175
uint64_t mask = ctx->ir_base[insn->op2].val.u64 - 1;
21752176

2177+
IR_ASSERT(mask != 0);
21762178
IR_ASSERT(IR_IS_CONST_REF(insn->op2));
21772179
IR_ASSERT(!IR_IS_SYM_CONST(ctx->ir_base[insn->op2].op));
21782180
IR_ASSERT(def_reg != IR_REG_NONE && tmp_reg != IR_REG_NONE && def_reg != tmp_reg);

ext/opcache/jit/ir/ir_fold.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,22 @@ IR_FOLD(DIV(_, C_I64))
16081608
IR_FOLD_NEXT;
16091609
}
16101610

1611+
IR_FOLD(MOD(_, C_U8))
1612+
IR_FOLD(MOD(_, C_U16))
1613+
IR_FOLD(MOD(_, C_U32))
1614+
IR_FOLD(MOD(_, C_U64))
1615+
IR_FOLD(MOD(_, C_I8))
1616+
IR_FOLD(MOD(_, C_I16))
1617+
IR_FOLD(MOD(_, C_I32))
1618+
IR_FOLD(MOD(_, C_I64))
1619+
{
1620+
if (op2_insn->val.i64 == 1) {
1621+
/* a % 1 => 0 */
1622+
IR_FOLD_CONST_U(0);
1623+
}
1624+
IR_FOLD_NEXT;
1625+
}
1626+
16111627
IR_FOLD(DIV(_, C_DOUBLE))
16121628
{
16131629
if (op2_insn->val.d == 1.0) {

ext/opcache/jit/ir/ir_x86.dasc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,7 @@ static void ir_emit_sdiv_pwr2(ir_ctx *ctx, ir_ref def, ir_insn *insn)
37873787
uint32_t shift = IR_LOG2(ctx->ir_base[insn->op2].val.u64);
37883788
int64_t offset = ctx->ir_base[insn->op2].val.u64 - 1;
37893789

3790+
IR_ASSERT(shift != 0);
37903791
IR_ASSERT(IR_IS_CONST_REF(insn->op2));
37913792
IR_ASSERT(!IR_IS_SYM_CONST(ctx->ir_base[insn->op2].op));
37923793
IR_ASSERT(op1_reg != IR_REG_NONE && def_reg != IR_REG_NONE && op1_reg != def_reg);
@@ -3849,6 +3850,7 @@ static void ir_emit_smod_pwr2(ir_ctx *ctx, ir_ref def, ir_insn *insn)
38493850
uint32_t shift = IR_LOG2(ctx->ir_base[insn->op2].val.u64);
38503851
uint64_t mask = ctx->ir_base[insn->op2].val.u64 - 1;
38513852

3853+
IR_ASSERT(shift != 0);
38523854
IR_ASSERT(IR_IS_CONST_REF(insn->op2));
38533855
IR_ASSERT(!IR_IS_SYM_CONST(ctx->ir_base[insn->op2].op));
38543856
IR_ASSERT(def_reg != IR_REG_NONE && tmp_reg != IR_REG_NONE && def_reg != tmp_reg);
@@ -3868,8 +3870,13 @@ static void ir_emit_smod_pwr2(ir_ctx *ctx, ir_ref def, ir_insn *insn)
38683870
ir_emit_mov(ctx, type, tmp_reg, def_reg);
38693871
}
38703872

3871-
| ASM_REG_IMM_OP sar, type, tmp_reg, (ir_type_size[type]*8-1)
3872-
| ASM_REG_IMM_OP shr, type, tmp_reg, (ir_type_size[type]*8-shift)
3873+
3874+
if (shift == 1) {
3875+
| ASM_REG_IMM_OP shr, type, tmp_reg, (ir_type_size[type]*8-1)
3876+
} else {
3877+
| ASM_REG_IMM_OP sar, type, tmp_reg, (ir_type_size[type]*8-1)
3878+
| ASM_REG_IMM_OP shr, type, tmp_reg, (ir_type_size[type]*8-shift)
3879+
}
38733880
| ASM_REG_REG_OP add, type, def_reg, tmp_reg
38743881

38753882
|.if X64

0 commit comments

Comments
 (0)