From: Florian K. <fk...@so...> - 2025-07-16 20:02:20
|
https://sourceware.org/cgit/valgrind/commit/?id=943e7070f3b8dd6f903779640f4f75db6b972e83 commit 943e7070f3b8dd6f903779640f4f75db6b972e83 Author: Florian Krohm <fl...@ei...> Date: Wed Jul 16 20:01:54 2025 +0000 Constant folding for various binary IRops. (BZ 506211) Iop_Add16, Iop_Sub16, Iop_CmpEQ8/16, Iop_CasCmpEQ8/16/32/64, Iop_CmpNE16, Iop_CasCmpNE16, Iop_ExpCmpNE16 Part of fixing https://bugs.kde.org/show_bug.cgi?id=506211 Diff: --- VEX/priv/ir_opt.c | 31 +++++++++++++++++++++++++++++++ none/tests/iropt-test/binary.c | 14 +++++++------- none/tests/iropt-test/irops.tab | 22 +++++++++++----------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/VEX/priv/ir_opt.c b/VEX/priv/ir_opt.c index c37ff08a77..91b266aa1d 100644 --- a/VEX/priv/ir_opt.c +++ b/VEX/priv/ir_opt.c @@ -2019,6 +2019,11 @@ static IRExpr* fold_Expr_WRK ( IRExpr** env, IRExpr* e ) (e->Iex.Binop.arg1->Iex.Const.con->Ico.U8 + e->Iex.Binop.arg2->Iex.Const.con->Ico.U8)))); break; + case Iop_Add16: + e2 = IRExpr_Const(IRConst_U16(toUShort( + (e->Iex.Binop.arg1->Iex.Const.con->Ico.U16 + + e->Iex.Binop.arg2->Iex.Const.con->Ico.U16)))); + break; case Iop_Add32: e2 = IRExpr_Const(IRConst_U32( (e->Iex.Binop.arg1->Iex.Const.con->Ico.U32 @@ -2036,6 +2041,11 @@ static IRExpr* fold_Expr_WRK ( IRExpr** env, IRExpr* e ) (e->Iex.Binop.arg1->Iex.Const.con->Ico.U8 - e->Iex.Binop.arg2->Iex.Const.con->Ico.U8)))); break; + case Iop_Sub16: + e2 = IRExpr_Const(IRConst_U16(toUShort( + (e->Iex.Binop.arg1->Iex.Const.con->Ico.U16 + - e->Iex.Binop.arg2->Iex.Const.con->Ico.U16)))); + break; case Iop_Sub32: e2 = IRExpr_Const(IRConst_U32( (e->Iex.Binop.arg1->Iex.Const.con->Ico.U32 @@ -2153,12 +2163,26 @@ static IRExpr* fold_Expr_WRK ( IRExpr** env, IRExpr* e ) } /* -- CmpEQ -- */ + case Iop_CmpEQ8: + case Iop_CasCmpEQ8: + e2 = IRExpr_Const(IRConst_U1(toBool( + (e->Iex.Binop.arg1->Iex.Const.con->Ico.U8 + == e->Iex.Binop.arg2->Iex.Const.con->Ico.U8)))); + break; + case Iop_CmpEQ16: + case Iop_CasCmpEQ16: + e2 = IRExpr_Const(IRConst_U1(toBool( + (e->Iex.Binop.arg1->Iex.Const.con->Ico.U16 + == e->Iex.Binop.arg2->Iex.Const.con->Ico.U16)))); + break; case Iop_CmpEQ32: + case Iop_CasCmpEQ32: e2 = IRExpr_Const(IRConst_U1(toBool( (e->Iex.Binop.arg1->Iex.Const.con->Ico.U32 == e->Iex.Binop.arg2->Iex.Const.con->Ico.U32)))); break; case Iop_CmpEQ64: + case Iop_CasCmpEQ64: e2 = IRExpr_Const(IRConst_U1(toBool( (e->Iex.Binop.arg1->Iex.Const.con->Ico.U64 == e->Iex.Binop.arg2->Iex.Const.con->Ico.U64)))); @@ -2172,6 +2196,13 @@ static IRExpr* fold_Expr_WRK ( IRExpr** env, IRExpr* e ) ((0xFF & e->Iex.Binop.arg1->Iex.Const.con->Ico.U8) != (0xFF & e->Iex.Binop.arg2->Iex.Const.con->Ico.U8))))); break; + case Iop_CmpNE16: + case Iop_CasCmpNE16: + case Iop_ExpCmpNE16: + e2 = IRExpr_Const(IRConst_U1(toBool( + (e->Iex.Binop.arg1->Iex.Const.con->Ico.U16 + != e->Iex.Binop.arg2->Iex.Const.con->Ico.U16)))); + break; case Iop_CmpNE32: case Iop_CasCmpNE32: case Iop_ExpCmpNE32: diff --git a/none/tests/iropt-test/binary.c b/none/tests/iropt-test/binary.c index ec4fa21d1c..894213a569 100644 --- a/none/tests/iropt-test/binary.c +++ b/none/tests/iropt-test/binary.c @@ -199,23 +199,23 @@ check_result(const irop_t *op, const test_data_t *data) case Iop_CmpEQ16: case Iop_CmpEQ32: case Iop_CmpEQ64: -// case Iop_CasCmpEQ8: -// case Iop_CasCmpEQ16: -// case Iop_CasCmpEQ32: -// case Iop_CasCmpEQ64: + case Iop_CasCmpEQ8: + case Iop_CasCmpEQ16: + case Iop_CasCmpEQ32: + case Iop_CasCmpEQ64: expected = opnd_l == opnd_r; break; case Iop_CmpNE8: -// case Iop_CmpNE16: + case Iop_CmpNE16: case Iop_CmpNE32: case Iop_CmpNE64: case Iop_CasCmpNE8: -// case Iop_CasCmpNE16: + case Iop_CasCmpNE16: case Iop_CasCmpNE32: case Iop_CasCmpNE64: case Iop_ExpCmpNE8: -// case Iop_ExpCmpNE16: + case Iop_ExpCmpNE16: case Iop_ExpCmpNE32: case Iop_ExpCmpNE64: expected = opnd_l != opnd_r; diff --git a/none/tests/iropt-test/irops.tab b/none/tests/iropt-test/irops.tab index 02afa6423a..a9f57a4ce1 100644 --- a/none/tests/iropt-test/irops.tab +++ b/none/tests/iropt-test/irops.tab @@ -111,12 +111,12 @@ // BINARY { OPNAME(Add8), Ity_I8, 2, Ity_I8, Ity_I8 }, -// { OPNAME(Add16), Ity_I16, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(Add16), Ity_I16, 2, Ity_I16, Ity_I16 }, { OPNAME(Add32), Ity_I32, 2, Ity_I32, Ity_I32 }, { OPNAME(Add64), Ity_I64, 2, Ity_I64, Ity_I64 }, { OPNAME(Sub8), Ity_I8, 2, Ity_I8, Ity_I8 }, -// { OPNAME(Sub16), Ity_I16, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(Sub16), Ity_I16, 2, Ity_I16, Ity_I16 }, { OPNAME(Sub32), Ity_I32, 2, Ity_I32, Ity_I32 }, { OPNAME(Sub64), Ity_I64, 2, Ity_I64, Ity_I64 }, @@ -197,13 +197,13 @@ { OPNAME(Xor32), Ity_I32, 2, Ity_I32, Ity_I32 }, { OPNAME(Xor64), Ity_I64, 2, Ity_I64, Ity_I64 }, -// { OPNAME(CmpEQ8), Ity_I1, 2, Ity_I8, Ity_I8 }, // no folding yet -// { OPNAME(CmpEQ16), Ity_I1, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(CmpEQ8), Ity_I1, 2, Ity_I8, Ity_I8 }, + { OPNAME(CmpEQ16), Ity_I1, 2, Ity_I16, Ity_I16 }, { OPNAME(CmpEQ32), Ity_I1, 2, Ity_I32, Ity_I32 }, { OPNAME(CmpEQ64), Ity_I1, 2, Ity_I64, Ity_I64 }, { OPNAME(CmpNE8), Ity_I1, 2, Ity_I8, Ity_I8 }, -// { OPNAME(CmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(CmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, { OPNAME(CmpNE32), Ity_I1, 2, Ity_I32, Ity_I32 }, { OPNAME(CmpNE64), Ity_I1, 2, Ity_I64, Ity_I64 }, @@ -219,18 +219,18 @@ { OPNAME(CmpLE32S), Ity_I1, 2, Ity_I32, Ity_I32 }, { OPNAME(CmpLE64S), Ity_I1, 2, Ity_I64, Ity_I64 }, -// { OPNAME(CasCmpEQ8), Ity_I1, 2, Ity_I8, Ity_I8 }, // no folding yet -// { OPNAME(CasCmpEQ16), Ity_I1, 2, Ity_I16, Ity_I16 }, // no folding yet -// { OPNAME(CasCmpEQ32), Ity_I1, 2, Ity_I32, Ity_I32 }, // no folding yet -// { OPNAME(CasCmpEQ64), Ity_I1, 2, Ity_I64, Ity_I64 }, // no folding yet + { OPNAME(CasCmpEQ8), Ity_I1, 2, Ity_I8, Ity_I8 }, + { OPNAME(CasCmpEQ16), Ity_I1, 2, Ity_I16, Ity_I16 }, + { OPNAME(CasCmpEQ32), Ity_I1, 2, Ity_I32, Ity_I32 }, + { OPNAME(CasCmpEQ64), Ity_I1, 2, Ity_I64, Ity_I64 }, { OPNAME(CasCmpNE8), Ity_I1, 2, Ity_I8, Ity_I8 }, -// { OPNAME(CasCmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(CasCmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, { OPNAME(CasCmpNE32), Ity_I1, 2, Ity_I32, Ity_I32 }, { OPNAME(CasCmpNE64), Ity_I1, 2, Ity_I64, Ity_I64 }, { OPNAME(ExpCmpNE8), Ity_I1, 2, Ity_I8, Ity_I8 }, -// { OPNAME(ExpCmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, // no folding yet + { OPNAME(ExpCmpNE16), Ity_I1, 2, Ity_I16, Ity_I16 }, { OPNAME(ExpCmpNE32), Ity_I1, 2, Ity_I32, Ity_I32 }, { OPNAME(ExpCmpNE64), Ity_I1, 2, Ity_I64, Ity_I64 }, |