|
From: <sv...@va...> - 2011-07-23 00:27:51
|
Author: florian
Date: 2011-07-23 01:23:02 +0100 (Sat, 23 Jul 2011)
New Revision: 2183
Log:
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.
Modified:
trunk/priv/ir_opt.c
Modified: trunk/priv/ir_opt.c
===================================================================
--- trunk/priv/ir_opt.c 2011-07-22 02:12:28 UTC (rev 2182)
+++ trunk/priv/ir_opt.c 2011-07-23 00:23:02 UTC (rev 2183)
@@ -4061,6 +4061,14 @@
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,7 +4111,15 @@
/* 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) */
if (is_Unop(aa, Iop_Left32))
|