]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
ir_opt.c: Algebraic simplification for Iop_Shl/Shr/Sar.
authorFlorian Krohm <flo2030@eich-krohm.de>
Wed, 3 Sep 2025 15:07:52 +0000 (15:07 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Wed, 3 Sep 2025 15:07:52 +0000 (15:07 +0000)
The simplification rules for 32-bit and 64-bit operands also apply for
8-bit and 16-bit operands.

VEX/priv/ir_opt.c

index b362be007efa636d8e2d5e56b6688a6c786443ab..f38a7be64b144270fc5b004a84c382a32de3ba84 100644 (file)
@@ -2571,31 +2571,34 @@ static IRExpr* fold_Expr_WRK ( IRExpr** env, IRExpr* e )
          /* other cases (identities, etc) */
          switch (e->Iex.Binop.op) {
 
+            case Iop_Shl8:
+            case Iop_Shl16:
             case Iop_Shl32:
             case Iop_Shl64:
+            case Iop_Shr8:
+            case Iop_Shr16:
+            case Iop_Shr32:
             case Iop_Shr64:
+            case Iop_Sar8:
+            case Iop_Sar16:
+            case Iop_Sar32:
             case Iop_Sar64:
-               /* Shl32/Shl64/Shr64/Sar64(x,0) ==> x */
+               /* Shl8/Shl16/Shl32/Shl64(x,0) ==> x
+                  Shr8/Shr16/Shr32/Shr64(x,0) ==> x
+                  Sar8/Sar16/Sar32/Sar64(x,0) ==> x */
                if (isZeroU(e->Iex.Binop.arg2)) {
                   e2 = e->Iex.Binop.arg1;
                   break;
                }
-               /* Shl32/Shl64/Shr64(0,x) ==> 0 */
+               /* Shl8/Shl16/Shl32/Shl64(0,x) ==> 0
+                  Shr8/Shr16/Shr32/Shr64(0,x) ==> 0
+                  Sar8/Sar16/Sar32/Sar64(0,x) ==> 0 */
                if (isZeroU(e->Iex.Binop.arg1)) {
                   e2 = e->Iex.Binop.arg1;
                   break;
                }
                break;
 
-            case Iop_Sar32:
-            case Iop_Shr32:
-               /* Shr32/Sar32(x,0) ==> x */
-               if (isZeroU(e->Iex.Binop.arg2)) {
-                  e2 = e->Iex.Binop.arg1;
-                  break;
-               }
-               break;
-
             case Iop_Or8:
             case Iop_Or16:
             case Iop_Or32: