]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Constant folding for various binary IRops. (BZ 506211)
authorFlorian Krohm <flo2030@eich-krohm.de>
Wed, 16 Jul 2025 20:01:54 +0000 (20:01 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Wed, 16 Jul 2025 20:01:54 +0000 (20:01 +0000)
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

VEX/priv/ir_opt.c
none/tests/iropt-test/binary.c
none/tests/iropt-test/irops.tab

index c37ff08a775ceeb306ebd7ed6d22d95790c43eee..91b266aa1d1a5189e9647b7a13fb317d5400c219 100644 (file)
@@ -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:
index ec4fa21d1c50e81767c1a51d78a53a6d44adebed..894213a5695d4d234ad4ce0832b76974bd3ce85c 100644 (file)
@@ -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;
index 02afa6423a4441117ddfdadccca82b4854e2b0f1..a9f57a4ce149889f1bb5511dca271a25ca5df60f 100644 (file)
 
    // 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 },
 
    { 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 },
 
    { 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 },