Fix PR middle-end/71654 (missed shortening of a compare)
authorPatrick Palka <ppalka@gcc.gnu.org>
Fri, 12 Aug 2016 16:07:40 +0000 (16:07 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Fri, 12 Aug 2016 16:07:40 +0000 (16:07 +0000)
gcc/ChangeLog:

PR middle-end/71654
* match.pd ((T)A CMP (T)B -> A CMP B): Allow (T)A to be a
sign-changing cast from a shorter unsigned type to a wider
signed type.

gcc/testsuite/ChangeLog:

PR middle-end/71654
* gcc.dg/c-c++-common/pr71654.c: New test.
* gcc.dg/tree-ssa/vrp23: Add -fno-tree-forwprop to
dg-options.
* gcc.dg/tree-ssa/vrp24: Likewise.

From-SVN: r239421

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr71654.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/vrp23.c
gcc/testsuite/gcc.dg/tree-ssa/vrp24.c

index 6a4f4bf194c52148ba0284212ce7db5a8dc63430..7a1d691d9729bccfd739fc91947a817d064c46cd 100644 (file)
@@ -1,3 +1,10 @@
+2016-08-12  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR middle-end/71654
+       * match.pd ((T)A CMP (T)B -> A CMP B): Allow (T)A to be a
+       sign-changing cast from a shorter unsigned type to a wider
+       signed type.
+
 2016-08-12  Jakub Jelinek  <jakub@redhat.com>
 
        * config/i386/sse.md (avx512dq_vextract<shuffletype>64x2_1_maskm,
index ac7cfff0ae25106819e330f0a16d6bac71e72952..da87b027b626158dc2844ddb90a6b9e80f47610b 100644 (file)
@@ -2350,7 +2350,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     (if (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE (@00)))
      /* If possible, express the comparison in the shorter mode.  */
      (if ((cmp == EQ_EXPR || cmp == NE_EXPR
-          || TYPE_UNSIGNED (TREE_TYPE (@0)) == TYPE_UNSIGNED (TREE_TYPE (@00)))
+          || TYPE_UNSIGNED (TREE_TYPE (@0)) == TYPE_UNSIGNED (TREE_TYPE (@00))
+          || (!TYPE_UNSIGNED (TREE_TYPE (@0))
+              && TYPE_UNSIGNED (TREE_TYPE (@00))))
          && (types_match (TREE_TYPE (@10), TREE_TYPE (@00))
              || ((TYPE_PRECISION (TREE_TYPE (@00))
                   >= TYPE_PRECISION (TREE_TYPE (@10)))
index 8040f34e775c33243101bb5e1cda2d597290b9c3..89071d2882f9503241ed75fe3222b323f0cdebe0 100644 (file)
@@ -1,3 +1,11 @@
+2016-08-12  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR middle-end/71654
+       * gcc.dg/c-c++-common/pr71654.c: New test.
+       * gcc.dg/tree-ssa/vrp23: Add -fno-tree-forwprop to
+       dg-options.
+       * gcc.dg/tree-ssa/vrp24: Likewise.
+
 2016-08-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/67410
diff --git a/gcc/testsuite/c-c++-common/pr71654.c b/gcc/testsuite/c-c++-common/pr71654.c
new file mode 100644 (file)
index 0000000..2942493
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR middle-end/71654  */
+/* { dg-do link }  */
+/* { dg-options "-O2" }  */
+
+unsigned char i0, i1;
+
+void foo (void);
+
+int
+main (void)
+{
+  int j = i0;
+  if (j < 4)
+    {
+      if (i0 & 4)
+        foo ();
+    }
+
+  unsigned int k = i1;
+  if (k < 8)
+    {
+      if (i1 & 8)
+        foo ();
+    }
+
+  return 0;
+}
+
index b877ccc607b76a19cc7c407bbc82c7b430471e63..ae68c090f77b4b006a07e6408c068918a4223768 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details" } */
 
 void aa (void);
 void aos (void);
index e7405750f41f294b6ae92e2e3f3cdbbe77e45920..853ee21bb8f515099c1205f1b21266129b250606 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details" } */
 
 
 struct rtx_def;