]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Comparing a boolean value for != 0 yields a result that is identical
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 23 Jul 2011 00:23:02 +0000 (00:23 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 23 Jul 2011 00:23:02 +0000 (00:23 +0000)
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

VEX/priv/ir_opt.c

index 8da10ff7786b7e07786cfe07737a430886511ec8..d662d407a7767d230f642e91734b406e6a292092 100644 (file)
@@ -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) */