tree-scalar-evolution.c (interpret_rhs_expr): Handle BIT_AND_EXPR.
authorBin Cheng <bin.cheng@arm.com>
Wed, 20 Apr 2016 11:42:36 +0000 (11:42 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Wed, 20 Apr 2016 11:42:36 +0000 (11:42 +0000)
* tree-scalar-evolution.c (interpret_rhs_expr): Handle BIT_AND_EXPR.

* gcc.dg/tree-ssa/scev-11.c: New test.
* gcc.dg/tree-ssa/scev-12.c: New test.

From-SVN: r235269

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/scev-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/scev-12.c [new file with mode: 0644]
gcc/tree-scalar-evolution.c

index 576560a..2cca3a2 100644 (file)
@@ -1,3 +1,7 @@
+2016-04-20  Bin Cheng  <bin.cheng@arm.com>
+
+       * tree-scalar-evolution.c (interpret_rhs_expr): Handle BIT_AND_EXPR.
+
 2016-04-20  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/70725
index b73790e..f869541 100644 (file)
@@ -1,3 +1,8 @@
+2016-04-20  Bin Cheng  <bin.cheng@arm.com>
+
+       * gcc.dg/tree-ssa/scev-11.c: New test.
+       * gcc.dg/tree-ssa/scev-12.c: New test.
+
 2016-04-20  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/70725
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/scev-11.c b/gcc/testsuite/gcc.dg/tree-ssa/scev-11.c
new file mode 100644 (file)
index 0000000..a7181b2
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+
+int a[128];
+extern int b[];
+
+int bar (int *);
+
+int
+foo (int n)
+{
+  int i;
+
+  for (i = 0; i < n; i++)
+    {
+      unsigned char uc = (unsigned char)i;
+      a[i] = i;
+      b[uc] = 0;
+    }
+
+  bar (a);
+  return 0;
+}
+
+/* Address of array reference to b is scev.  */
+/* { dg-final { scan-tree-dump-times "use \[0-9\]\n  address" 2 "ivopts" } } */
+
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/scev-12.c b/gcc/testsuite/gcc.dg/tree-ssa/scev-12.c
new file mode 100644 (file)
index 0000000..6915ba8
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+
+int a[128];
+extern int b[];
+
+int bar (int *);
+
+int
+foo (int x, int n)
+{
+  int i;
+
+  for (i = 0; i < n; i++)
+    {
+      unsigned char uc = (unsigned char)i;
+      if (x)
+       a[i] = i;
+      b[uc] = 0;
+    }
+
+  bar (a);
+  return 0;
+}
+
+/* Address of array reference to b is not scev.  */
+/* { dg-final { scan-tree-dump-times "use \[0-9\]\n  address" 1 "ivopts" } } */
+
+
+
index 88a0eaa..d6f2a2f 100644 (file)
@@ -1937,6 +1937,36 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt,
       res = chrec_convert (type, chrec1, at_stmt);
       break;
 
+    case BIT_AND_EXPR:
+      /* Given int variable A, handle A&0xffff as (int)(unsigned short)A.
+        If A is SCEV and its value is in the range of representable set
+        of type unsigned short, the result expression is a (no-overflow)
+        SCEV.  */
+      res = chrec_dont_know;
+      if (tree_fits_uhwi_p (rhs2))
+       {
+         int precision;
+         unsigned HOST_WIDE_INT val = tree_to_uhwi (rhs2);
+
+         val ++;
+         /* Skip if value of rhs2 wraps in unsigned HOST_WIDE_INT or
+            it's not the maximum value of a smaller type than rhs1.  */
+         if (val != 0
+             && (precision = exact_log2 (val)) > 0
+             && (unsigned) precision < TYPE_PRECISION (TREE_TYPE (rhs1)))
+           {
+             tree utype = build_nonstandard_integer_type (precision, 1);
+
+             if (TYPE_PRECISION (utype) < TYPE_PRECISION (TREE_TYPE (rhs1)))
+               {
+                 chrec1 = analyze_scalar_evolution (loop, rhs1);
+                 chrec1 = chrec_convert (utype, chrec1, at_stmt);
+                 res = chrec_convert (TREE_TYPE (rhs1), chrec1, at_stmt);
+               }
+           }
+       }
+      break;
+
     default:
       res = chrec_dont_know;
       break;