From: Julian Seward Date: Sun, 14 May 2006 18:46:55 +0000 (+0000) Subject: Add an IR folding rule to convert Add32(x,x) into Shl32(x,1). This X-Git-Tag: svn/VALGRIND_3_2_3^2~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f28bf5bdc542545bdb3453f40e1ce2dcd425ba4d;p=thirdparty%2Fvalgrind.git Add an IR folding rule to convert Add32(x,x) into Shl32(x,1). This fixes #118466 and it also gets rid of a bunch of false positives for KDE 3.5.2 built by gcc-4.0.2 on x86, of the form shown below. Use of uninitialised value of size 4 at 0x4BFC342: QIconSet::pixmap(QIconSet::Size, QIconSet::Mode, QIconSet::State) const (qiconset.cpp:530) by 0x4555BE7: KToolBarButton::drawButton(QPainter*) (ktoolbarbutton.cpp:536) by 0x4CB8A0A: QButton::paintEvent(QPaintEvent*) (qbutton.cpp:887) git-svn-id: svn://svn.valgrind.org/vex/trunk@1617 --- diff --git a/VEX/priv/ir/iropt.c b/VEX/priv/ir/iropt.c index fd981ab503..94462d4021 100644 --- a/VEX/priv/ir/iropt.c +++ b/VEX/priv/ir/iropt.c @@ -1405,6 +1405,20 @@ static IRExpr* fold_Expr ( IRExpr* e ) e2 = e->Iex.Binop.arg1; } else + /* Add32(t,t) ==> t << 1. Memcheck doesn't understand that + x+x produces a defined least significant bit, and it seems + simplest just to get rid of the problem by rewriting it + out, since the opportunity to do so exists. */ + if (e->Iex.Binop.op == Iop_Add32 + && e->Iex.Binop.arg1->tag == Iex_Tmp + && e->Iex.Binop.arg2->tag == Iex_Tmp + && e->Iex.Binop.arg1->Iex.Tmp.tmp + == e->Iex.Binop.arg2->Iex.Tmp.tmp) { + e2 = IRExpr_Binop(Iop_Shl32, + e->Iex.Binop.arg1, + IRExpr_Const(IRConst_U8(1))); + } else + /* Or64/Add64(x,0) ==> x */ if ((e->Iex.Binop.op == Iop_Add64 || e->Iex.Binop.op == Iop_Or64) && e->Iex.Binop.arg2->tag == Iex_Const