]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
* constant fold Shr32
authorJulian Seward <jseward@acm.org>
Fri, 20 Aug 2004 01:01:04 +0000 (01:01 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 20 Aug 2004 01:01:04 +0000 (01:01 +0000)
* fix up types on folding rules for Shr32/Shl32/Sar32

git-svn-id: svn://svn.valgrind.org/vex/trunk@188

VEX/priv/ir/iropt.c

index c680d679efef6bfb8b64c74da1541862e1eb60d4..e65f7a4c69387e155aa34db78db053c01ba3cb30 100644 (file)
@@ -357,7 +357,8 @@ static IRExpr* fold_Expr ( IRExpr* e )
                         | e->Iex.Binop.arg2->Iex.Const.con->Ico.U32)));
                break;
             case Iop_Shl32:
-               shift = (Int)(e->Iex.Binop.arg2->Iex.Const.con->Ico.U32);
+               vassert(e->Iex.Binop.arg2->Iex.Const.con->tag == Ico_U8);
+               shift = (Int)(e->Iex.Binop.arg2->Iex.Const.con->Ico.U8);
               if (shift >= 0 && shift <= 31)
                   e2 = IRExpr_Const(IRConst_U32(
                           (e->Iex.Binop.arg1->Iex.Const.con->Ico.U32
@@ -366,14 +367,27 @@ static IRExpr* fold_Expr ( IRExpr* e )
             case Iop_Sar32: {
                /* paranoid ... */
                /*signed*/ Int s32;
+               vassert(e->Iex.Binop.arg2->Iex.Const.con->tag == Ico_U8);
                s32   = (Int)(e->Iex.Binop.arg1->Iex.Const.con->Ico.U32);
-               shift = (Int)(e->Iex.Binop.arg2->Iex.Const.con->Ico.U32);
+               shift = (Int)(e->Iex.Binop.arg2->Iex.Const.con->Ico.U8);
                if (shift >= 0 && shift <= 31) {
                   s32 >>=/*signed*/ shift;
                   e2 = IRExpr_Const(IRConst_U32((UInt)s32));
                }
                break;
             }
+            case Iop_Shr32: {
+               /* paranoid ... */
+               /*unsigned*/ UInt s32;
+               vassert(e->Iex.Binop.arg2->Iex.Const.con->tag == Ico_U8);
+               s32   = (Int)(e->Iex.Binop.arg1->Iex.Const.con->Ico.U32);
+               shift = (Int)(e->Iex.Binop.arg2->Iex.Const.con->Ico.U8);
+               if (shift >= 0 && shift <= 31) {
+                  s32 >>=/*unsigned*/ shift;
+                  e2 = IRExpr_Const(IRConst_U32((UInt)s32));
+               }
+               break;
+            }
             case Iop_CmpEQ32:
                e2 = IRExpr_Const(IRConst_Bit(
                        (e->Iex.Binop.arg1->Iex.Const.con->Ico.U32