diff mbox

tree-scalar-evolution.c: Handle LSHIFT by constant

Message ID 1445949611-16406-1-git-send-email-alan.lawrence@arm.com
State New
Headers show

Commit Message

Alan Lawrence Oct. 27, 2015, 12:40 p.m. UTC
--in-reply-to <CAFiYyc3TePGbER2Jqc8-X_ij4GHtjjoxfzFFcNYzHxhGQbE0iQ@mail.gmail.com>

On 26/10/15 08:58, Richard Biener wrote:
>
> On Fri, Oct 23, 2015 at 5:15 PM, Alan Lawrence <alan.lawrence@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

Comments

H.J. Lu Oct. 27, 2015, 10:27 p.m. UTC | #1
On Tue, Oct 27, 2015 at 5:40 AM, Alan Lawrence <alan.lawrence@arm.com> wrote:
> --in-reply-to <CAFiYyc3TePGbER2Jqc8-X_ij4GHtjjoxfzFFcNYzHxhGQbE0iQ@mail.gmail.com>
>
> On 26/10/15 08:58, Richard Biener wrote:
>>
>> On Fri, Oct 23, 2015 at 5:15 PM, Alan Lawrence <alan.lawrence@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.
>

It caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68112
diff mbox

Patch

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