--in-reply-to 
<cafiyyc3tepgber2jqc8-x_ij4ghtjjoxfzffcnyzhxhgqbe...@mail.gmail.com>

On 26/10/15 08:58, Richard Biener wrote:
>
> On Fri, Oct 23, 2015 at 5:15 PM, Alan Lawrence <alan.lawre...@arm.com> wrote:
>> +      chrec2 = fold_build2 (LSHIFT_EXPR, TREE_TYPE (rhs1),
>> +                           build_int_cst (TREE_TYPE (rhs1), 1),
>
> 'type' instead of TREE_TYPE (rhs1)

I presume you mean the first of the two (allowing removal of the chrec_convert),
and that I keep the second TREE_TYPE (rhs1), consistent with your previous
observation that I should do the multiply in the type of rhs1. (This appears
correct looking at e.g. gcc.target/i386/avx2-vpsllwi-2.c)

Hence, I've committed the attached as r229437.

Thanks, Alan
---
 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 ++++++++++++++++++++++++
 gcc/tree-scalar-evolution.c                      | 14 ++++++++++
 2 files changed, 47 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..8e95ddd 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -1840,6 +1840,20 @@ 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, type,
+                           build_int_cst (TREE_TYPE (rhs1), 1),
+                           chrec2);
+      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

Reply via email to