Blame SOURCES/valgrind-3.18.1-amd64-more-spec-rules.patch

6e98bf
commit 595341b150312d2407bd43304449bf39ec3e1fa8
6e98bf
Author: Julian Seward <jseward@acm.org>
6e98bf
Date:   Sat Nov 13 19:59:07 2021 +0100
6e98bf
6e98bf
    amd64 front end: add more spec rules:
6e98bf
    
6e98bf
       S  after SHRQ
6e98bf
       Z  after SHLQ
6e98bf
       NZ after SHLQ
6e98bf
       Z  after SHLL
6e98bf
       S  after SHLL
6e98bf
    
6e98bf
    The lack of at least one of these was observed to cause occasional false
6e98bf
    positives in Memcheck.
6e98bf
    
6e98bf
    Plus add commented-out cases so as to complete the set of 12 rules
6e98bf
    {Z,NZ,S,NS} after {SHRQ,SHLQ,SHLL}.  The commented-out ones are commented
6e98bf
    out because I so far didn't find any use cases for them.
6e98bf
6e98bf
diff --git a/VEX/priv/guest_amd64_helpers.c b/VEX/priv/guest_amd64_helpers.c
6e98bf
index 9d61e7a0f..ba71c1b62 100644
6e98bf
--- a/VEX/priv/guest_amd64_helpers.c
6e98bf
+++ b/VEX/priv/guest_amd64_helpers.c
6e98bf
@@ -1823,16 +1823,26 @@ IRExpr* guest_amd64_spechelper ( const HChar* function_name,
6e98bf
       /*---------------- SHRQ ----------------*/
6e98bf
 
6e98bf
       if (isU64(cc_op, AMD64G_CC_OP_SHRQ) && isU64(cond, AMD64CondZ)) {
6e98bf
-         /* SHRQ, then Z --> test dep1 == 0 */
6e98bf
+         /* SHRQ, then Z --> test result[63:0] == 0 */
6e98bf
          return unop(Iop_1Uto64,
6e98bf
                      binop(Iop_CmpEQ64, cc_dep1, mkU64(0)));
6e98bf
       }
6e98bf
       if (isU64(cc_op, AMD64G_CC_OP_SHRQ) && isU64(cond, AMD64CondNZ)) {
6e98bf
-         /* SHRQ, then NZ --> test dep1 != 0 */
6e98bf
+         /* SHRQ, then NZ --> test result[63:0] != 0 */
6e98bf
          return unop(Iop_1Uto64,
6e98bf
                      binop(Iop_CmpNE64, cc_dep1, mkU64(0)));
6e98bf
       }
6e98bf
 
6e98bf
+      if (isU64(cc_op, AMD64G_CC_OP_SHRQ) && isU64(cond, AMD64CondS)) {
6e98bf
+         /* SHRQ, then S --> (ULong)result[63] (result is in dep1) */
6e98bf
+         return binop(Iop_Shr64, cc_dep1, mkU8(63));
6e98bf
+      }
6e98bf
+      // No known test case for this, hence disabled:
6e98bf
+      //if (isU64(cc_op, AMD64G_CC_OP_SHRQ) && isU64(cond, AMD64CondNS)) {
6e98bf
+      //   /* SHRQ, then NS --> (ULong) ~ result[63] */
6e98bf
+      //   vassert(0);
6e98bf
+      //}
6e98bf
+
6e98bf
       /*---------------- SHRL ----------------*/
6e98bf
 
6e98bf
       if (isU64(cc_op, AMD64G_CC_OP_SHRL) && isU64(cond, AMD64CondZ)) {
6e98bf
@@ -1881,6 +1891,52 @@ IRExpr* guest_amd64_spechelper ( const HChar* function_name,
6e98bf
       //                     mkU32(0)));
6e98bf
       //}
6e98bf
 
6e98bf
+      /*---------------- SHLQ ----------------*/
6e98bf
+
6e98bf
+      if (isU64(cc_op, AMD64G_CC_OP_SHLQ) && isU64(cond, AMD64CondZ)) {
6e98bf
+         /* SHLQ, then Z --> test dep1 == 0 */
6e98bf
+         return unop(Iop_1Uto64,
6e98bf
+                     binop(Iop_CmpEQ64, cc_dep1, mkU64(0)));
6e98bf
+      }
6e98bf
+      if (isU64(cc_op, AMD64G_CC_OP_SHLQ) && isU64(cond, AMD64CondNZ)) {
6e98bf
+         /* SHLQ, then NZ --> test dep1 != 0 */
6e98bf
+         return unop(Iop_1Uto64,
6e98bf
+                     binop(Iop_CmpNE64, cc_dep1, mkU64(0)));
6e98bf
+      }
6e98bf
+
6e98bf
+      //if (isU64(cc_op, AMD64G_CC_OP_SHLQ) && isU64(cond, AMD64CondS)) {
6e98bf
+      //   /* SHLQ, then S --> (ULong)result[63] */
6e98bf
+      //   vassert(0);
6e98bf
+      //}
6e98bf
+      //if (isU64(cc_op, AMD64G_CC_OP_SHLQ) && isU64(cond, AMD64CondNS)) {
6e98bf
+      //   /* SHLQ, then NS --> (ULong) ~ result[63] */
6e98bf
+      //   vassert(0);
6e98bf
+      //}
6e98bf
+
6e98bf
+      /*---------------- SHLL ----------------*/
6e98bf
+
6e98bf
+      if (isU64(cc_op, AMD64G_CC_OP_SHLL) && isU64(cond, AMD64CondZ)) {
6e98bf
+         /* SHLL, then Z --> test result[31:0] == 0 */
6e98bf
+         return unop(Iop_1Uto64,
6e98bf
+                     binop(Iop_CmpEQ32, unop(Iop_64to32, cc_dep1),
6e98bf
+                           mkU32(0)));
6e98bf
+      }
6e98bf
+      //if (isU64(cc_op, AMD64G_CC_OP_SHLL) && isU64(cond, AMD64CondNZ)) {
6e98bf
+      //   /* SHLL, then NZ --> test dep1 != 0 */
6e98bf
+      //   vassert(0);
6e98bf
+      //}
6e98bf
+
6e98bf
+      if (isU64(cc_op, AMD64G_CC_OP_SHLL) && isU64(cond, AMD64CondS)) {
6e98bf
+         /* SHLL, then S --> (ULong)result[31] */
6e98bf
+         return binop(Iop_And64,
6e98bf
+                      binop(Iop_Shr64, cc_dep1, mkU8(31)),
6e98bf
+                      mkU64(1));
6e98bf
+      }
6e98bf
+      //if (isU64(cc_op, AMD64G_CC_OP_SHLL) && isU64(cond, AMD64CondNS)) {
6e98bf
+      //   /* SHLL, then NS --> (ULong) ~ result[31] */
6e98bf
+      //   vassert(0);
6e98bf
+      //}
6e98bf
+
6e98bf
       /*---------------- COPY ----------------*/
6e98bf
       /* This can happen, as a result of amd64 FP compares: "comisd ... ;
6e98bf
          jbe" for example. */