This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] tree-scalar-evolution.c: Handle LSHIFT by constant


On 19/10/15 12:49, Richard Biener wrote:

> Err, you should always do the shift in the type of rhs1.  You should also
> avoid the chrec_convert of rhs2 above for shifts.

Err, yes, indeed.  Needed to keep the chrec_convert before the
chrec_fold_multiply, and the rest followed.  How's this?

Bootstrapped+check-gcc,g++ on x86, ARM, AArch64.

gcc/ChangeLog (as before):

	PR tree-optimization/65963
	* tree-scalar-evolution.c (interpret_rhs_expr): Handle some LSHIFT_EXPRs
	as equivalent MULT_EXPRs.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/vect-strided-shift-1.c: New.
---
 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 ++++++++++++++++++++++++
 gcc/tree-scalar-evolution.c                      | 15 +++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c
new file mode 100644
index 0000000..b1ce2ec
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c
@@ -0,0 +1,33 @@
+/* PR tree-optimization/65963.  */
+#include "tree-vect.h"
+
+#define N 512
+
+int in[2*N], out[N];
+
+__attribute__ ((noinline)) void
+loop (void)
+{
+  for (int i = 0; i < N; i++)
+    out[i] = in[i << 1] + 7;
+}
+
+int
+main (int argc, char **argv)
+{
+  check_vect ();
+  for (int i = 0; i < 2*N; i++)
+    {
+      in[i] = i;
+      __asm__ volatile ("" : : : "memory");
+    }
+  loop ();
+  __asm__ volatile ("" : : : "memory");
+  for (int i = 0; i < N; i++)
+    {
+      if (out[i] != i*2 + 7)
+	abort ();
+    }
+  return 0;
+}
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 1 "vect" { target { vect_strided2 } } } } */
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index 0753bf3..129682f 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -1840,6 +1840,21 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt,
       res = chrec_fold_multiply (type, chrec1, chrec2);
       break;
 
+    case LSHIFT_EXPR:
+      /* Handle A<<B as A * (1<<B).  */
+      chrec1 = analyze_scalar_evolution (loop, rhs1);
+      chrec2 = analyze_scalar_evolution (loop, rhs2);
+      chrec1 = chrec_convert (type, chrec1, at_stmt);
+      chrec1 = instantiate_parameters (loop, chrec1);
+      chrec2 = instantiate_parameters (loop, chrec2);
+
+      chrec2 = fold_build2 (LSHIFT_EXPR, TREE_TYPE (rhs1),
+			    build_int_cst (TREE_TYPE (rhs1), 1),
+			    chrec2);
+      chrec2 = chrec_convert (type, chrec2, at_stmt);
+      res = chrec_fold_multiply (type, chrec1, chrec2);
+      break;
+
     CASE_CONVERT:
       /* In case we have a truncation of a widened operation that in
          the truncated type has undefined overflow behavior analyze
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]