From: Julian Seward Date: Fri, 20 Aug 2004 01:01:04 +0000 (+0000) Subject: * constant fold Shr32 X-Git-Tag: svn/VALGRIND_3_0_1^2~1146 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bf26224ad497797df21209332aee76548cbc7b5;p=thirdparty%2Fvalgrind.git * constant fold Shr32 * fix up types on folding rules for Shr32/Shl32/Sar32 git-svn-id: svn://svn.valgrind.org/vex/trunk@188 --- diff --git a/VEX/priv/ir/iropt.c b/VEX/priv/ir/iropt.c index c680d679ef..e65f7a4c69 100644 --- a/VEX/priv/ir/iropt.c +++ b/VEX/priv/ir/iropt.c @@ -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