]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Redundant-Get elimination: only do the substitution when the types
authorJulian Seward <jseward@acm.org>
Tue, 7 Dec 2004 19:00:57 +0000 (19:00 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 7 Dec 2004 19:00:57 +0000 (19:00 +0000)
match.  Not doing so leads to incorrectly typed IR.

git-svn-id: svn://svn.valgrind.org/vex/trunk@631

VEX/priv/ir/iropt.c

index 56073f86eb54228e12bd3cc8c93e05fa4383a1f1..cd4c9e61e26766eb9c60619d9569b1afdf63e4b2 100644 (file)
@@ -1190,13 +1190,21 @@ static void redundant_get_removal_BB ( IRBB* bb )
                                      get->Iex.Get.ty );
          if (lookupHHW(env, &val, (HWord)key)) {
             /* found it */
-            if (DEBUG_IROPT) {
+            /* Note, we could do better here.  If the types are
+               different we don't do the substitution, since doing so
+               could lead to invalidly-typed IR.  An improvement would
+               be to stick in a reinterpret-style cast, although that
+               would make maintaining flatness more difficult. */
+            IRExpr* valE    = (IRExpr*)val;
+            Bool    typesOK = typeOfIRExpr(bb->tyenv,valE) 
+                              == st->Ist.Tmp.data->Iex.Get.ty;
+            if (typesOK && DEBUG_IROPT) {
                vex_printf("rGET: "); ppIRExpr(get);
-               vex_printf("  ->  "); ppIRExpr((IRExpr*)val);
+               vex_printf("  ->  "); ppIRExpr(valE);
                vex_printf("\n");
             }
-            bb->stmts[i] = IRStmt_Tmp(st->Ist.Tmp.tmp,
-                                      (IRExpr*)val);
+            if (typesOK)
+               bb->stmts[i] = IRStmt_Tmp(st->Ist.Tmp.tmp, valE);
          } else {
             /* Not found, but at least we know that t and the Get(...)
                are now associated.  So add a binding to reflect that