From: Florian Krohm Date: Sat, 23 Jul 2011 00:23:02 +0000 (+0000) Subject: Comparing a boolean value for != 0 yields a result that is identical X-Git-Tag: svn/VALGRIND_3_7_0^2~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=573babe9dca517a5469315c3e64132ca1e45aa4d;p=thirdparty%2Fvalgrind.git Comparing a boolean value for != 0 yields a result that is identical to the value being compared. So we can simplify e.g CmpNE32( 1Uto32(CmpEQ64(p,q)), 0 ) --> CmpEQ64(p,q). And likewise for CmpNEZ operations. This revision adds tree patterns to optimise some of those comparisons. This is particularly beneficial for s390x where moving the condition code into a GPR is an expensive operation. With this optimisation an up to 8% reduction in generated code was observed. git-svn-id: svn://svn.valgrind.org/vex/trunk@2183 --- diff --git a/VEX/priv/ir_opt.c b/VEX/priv/ir_opt.c index 8da10ff778..d662d407a7 100644 --- a/VEX/priv/ir_opt.c +++ b/VEX/priv/ir_opt.c @@ -4061,6 +4061,14 @@ static IRExpr* fold_IRExpr_Binop ( IROp op, IRExpr* a1, IRExpr* a2 ) IRExpr_Binop( Iop_Or32, a1->Iex.Unop.arg, a2->Iex.Unop.arg ) ); break; + + case Iop_CmpNE32: + /* Since X has type Ity_I1 we can simplify: + CmpNE32(1Uto32(X),0)) ==> X */ + if (is_Unop(a1, Iop_1Uto32) && isZeroU32(a2)) + return a1->Iex.Unop.arg; + break; + default: break; } @@ -4103,6 +4111,14 @@ static IRExpr* fold_IRExpr_Unop ( IROp op, IRExpr* aa ) /* CmpNEZ32( Left32(x) ) --> CmpNEZ32(x) */ if (is_Unop(aa, Iop_Left32)) return IRExpr_Unop(Iop_CmpNEZ32, aa->Iex.Unop.arg); + /* CmpNEZ32( 1Uto32(X) ) --> X */ + if (is_Unop(aa, Iop_1Uto32)) + return aa->Iex.Unop.arg; + break; + case Iop_CmpNEZ8: + /* CmpNEZ8( 1Uto8(X) ) --> X */ + if (is_Unop(aa, Iop_1Uto8)) + return aa->Iex.Unop.arg; break; case Iop_Left32: /* Left32( Left32(x) ) --> Left32(x) */