Re: SLS Mitigation patches backported for GCC9

2020-11-12 Thread Sebastian Pop via Gcc-patches
Hi,

could the SLS Mitigation patches be back-ported to the gcc-8 branch?

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=dc586a74922 aarch64:
Introduce SLS mitigation for RET and BR instructions
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=20da13e395b aarch64:
New Straight Line Speculation (SLS) mitigation flags

Thanks,
Sebastian

On Tue, Aug 4, 2020 at 3:34 AM Kyrylo Tkachov  wrote:
>
> Hi Matthew,
>
> > -Original Message-
> > From: Matthew Malcomson 
> > Sent: 24 July 2020 17:03
> > To: Kyrylo Tkachov ; gcc-patches@gcc.gnu.org
> > Cc: Richard Earnshaw ; Ross Burton
> > ; Richard Sandiford 
> > Subject: Re: SLS Mitigation patches backported for GCC9
> >
> > On 24/07/2020 12:01, Kyrylo Tkachov wrote:
> > > Hi Matthew,
> > >
> > >> -Original Message-
> > >> From: Matthew Malcomson 
> > >> Sent: 21 July 2020 16:16
> > >> To: gcc-patches@gcc.gnu.org
> > >> Cc: Richard Earnshaw ; Kyrylo Tkachov
> > >> ; Ross Burton 
> > >> Subject: SLS Mitigation patches backported for GCC9
> > >>
> > >> Hello,
> > >>
> > >> Eventually we will want to backport the SLS patches to older branches.
> > >>
> > >> When the GCC10 release is unfrozen we will work on getting the same
> > >> patches
> > >> already posted backported to that branch.  The patches already posted on
> > >> the
> > >> mailing list apply cleanly to the current releases/gcc-10 branch.
> > >>
> > >> I've heard interest in having the GCC 9 patches, so I'm posting the
> > modified
> > >> versions upstream sooner than otherwise.
> > >
> > > I'd say let's go ahead with the GCC 10 patches (assuming testing works out
> > well on there).
> > > For the GCC 9 patches it would be useful if you included a bit of text of 
> > > how
> > they differ from the GCC 10/11 patches.
> > > This would speed up the technical review.
> > > Thanks,
> > > Kyrill
> > >
> > >>
> > >> Cheers,
> > >> Matthew
> > >>
> > >> Entire patch series attached to cover letter.
> >
> > Below were the only two "interesting" hunks that failed to apply after
> > `patch -p1`.
> >
> > The differences causing these were:
> > - in GCC-9 the `retab` instruction wasn't in the "do_return" pattern.
> > - `simple_return` had "aarch64_use_simple_return_insn_p ()" as a
> > condition.
> >
> >
>
> Thanks, the backports to GCC 10 and GCC 9 are okay, let's go ahead with them.
> Kyrill
>
> >
> >
> > --- gcc/config/aarch64/aarch64.md
> > +++ gcc/config/aarch64/aarch64.md
> > @@ -863,18 +882,23 @@
> > [(return)]
> > ""
> > {
> > +const char *ret = NULL;
> >   if (aarch64_return_address_signing_enabled ()
> >  && TARGET_ARMV8_3
> >  && !crtl->calls_eh_return)
> > {
> >  if (aarch64_ra_sign_key == AARCH64_KEY_B)
> > - return "retab";
> > + ret = "retab";
> >  else
> > - return "retaa";
> > + ret = "retaa";
> > }
> > -return "ret";
> > +else
> > +  ret = "ret";
> > +output_asm_insn (ret, operands);
> > +return aarch64_sls_barrier (aarch64_harden_sls_retbr_p ());
> > }
> > -  [(set_attr "type" "branch")]
> > +  [(set_attr "type" "branch")
> > +   (set_attr "sls_length" "retbr")]
> >   )
> >
> >   (define_expand "return"
> > @@ -886,8 +910,12 @@
> >   (define_insn "simple_return"
> > [(simple_return)]
> > ""
> > -  "ret"
> > -  [(set_attr "type" "branch")]
> > +  {
> > +output_asm_insn ("ret", operands);
> > +return aarch64_sls_barrier (aarch64_harden_sls_retbr_p ());
> > +  }
> > +  [(set_attr "type" "branch")
> > +   (set_attr "sls_length" "retbr")]
> >   )
> >
> >   (define_insn "*cb1"


Re: [gcc r9-8794] aarch64: Clear canary value after stack_protect_test [PR96191]

2020-11-12 Thread Sebastian Pop via Gcc-patches
Hi,

On Fri, Aug 7, 2020 at 6:18 AM Richard Sandiford  wrote:
>
> https://gcc.gnu.org/g:5380912a17ea09a8996720fb62b1a70c16c8f9f2
>
> commit r9-8794-g5380912a17ea09a8996720fb62b1a70c16c8f9f2
> Author: Richard Sandiford 
> Date:   Fri Aug 7 12:17:37 2020 +0100

could you please also apply this change to the gcc-8 branch?

Thanks,
Sebastian

>
> aarch64: Clear canary value after stack_protect_test [PR96191]
>
> The stack_protect_test patterns were leaving the canary value in the
> temporary register, meaning that it was often still in registers on
> return from the function.  An attacker might therefore have been
> able to use it to defeat stack-smash protection for a later function.
>
> gcc/
> PR target/96191
> * config/aarch64/aarch64.md (stack_protect_test_): Set the
> CC register directly, instead of a GPR.  Replace the original GPR
> destination with an extra scratch register.  Zero out operand 3
> after use.
> (stack_protect_test): Update accordingly.
>
> gcc/testsuite/
> PR target/96191
> * gcc.target/aarch64/stack-protector-1.c: New test.
> * gcc.target/aarch64/stack-protector-2.c: Likewise.
>
> (cherry picked from commit fe1a26429038d7cd17abc53f96a6f3e2639b605f)
>
> Diff:
> ---
>  gcc/config/aarch64/aarch64.md  | 34 -
>  .../gcc.target/aarch64/stack-protector-1.c | 89 
> ++
>  .../gcc.target/aarch64/stack-protector-2.c |  6 ++
>  3 files changed, 110 insertions(+), 19 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index ed8cf8ecea1..9598bac387f 100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -6985,10 +6985,8 @@
> (match_operand 2)]
>""
>  {
> -  rtx result;
>machine_mode mode = GET_MODE (operands[0]);
>
> -  result = gen_reg_rtx(mode);
>if (aarch64_stack_protector_guard != SSP_GLOBAL)
>{
>  /* Generate access through the system register. The
> @@ -7013,29 +7011,27 @@
>  operands[1] = gen_rtx_MEM (mode, tmp_reg);
>}
>emit_insn ((mode == DImode
> - ? gen_stack_protect_test_di
> - : gen_stack_protect_test_si) (result,
> -   operands[0],
> -   operands[1]));
> -
> -  if (mode == DImode)
> -emit_jump_insn (gen_cbranchdi4 (gen_rtx_EQ (VOIDmode, result, 
> const0_rtx),
> -   result, const0_rtx, operands[2]));
> -  else
> -emit_jump_insn (gen_cbranchsi4 (gen_rtx_EQ (VOIDmode, result, 
> const0_rtx),
> -   result, const0_rtx, operands[2]));
> +? gen_stack_protect_test_di
> +: gen_stack_protect_test_si) (operands[0], operands[1]));
> +
> +  rtx cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
> +  emit_jump_insn (gen_condjump (gen_rtx_EQ (VOIDmode, cc_reg, const0_rtx),
> +   cc_reg, operands[2]));
>DONE;
>  })
>
> +;; DO NOT SPLIT THIS PATTERN.  It is important for security reasons that the
> +;; canary value does not live beyond the end of this sequence.
>  (define_insn "stack_protect_test_"
> -  [(set (match_operand:PTR 0 "register_operand" "=r")
> -   (unspec:PTR [(match_operand:PTR 1 "memory_operand" "m")
> -(match_operand:PTR 2 "memory_operand" "m")]
> -UNSPEC_SP_TEST))
> +  [(set (reg:CC CC_REGNUM)
> +   (unspec:CC [(match_operand:PTR 0 "memory_operand" "m")
> +   (match_operand:PTR 1 "memory_operand" "m")]
> +  UNSPEC_SP_TEST))
> +   (clobber (match_scratch:PTR 2 "="))
> (clobber (match_scratch:PTR 3 "="))]
>""
> -  "ldr\t%3, %1\;ldr\t%0, %2\;eor\t%0, %3, %0"
> -  [(set_attr "length" "12")
> +  "ldr\t%2, %0\;ldr\t%3, %1\;subs\t%2, %2, %3\;mov\t%3, 0"
> +  [(set_attr "length" "16")
> (set_attr "type" "multiple")])
>
>  ;; Write Floating-point Control Register.
> diff --git a/gcc/testsuite/gcc.target/aarch64/stack-protector-1.c 
> b/gcc/testsuite/gcc.target/aarch64/stack-protector-1.c
> new file mode 100644
> index 000..73e83bc413f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/stack-protector-1.c
> @@ -0,0 +1,89 @@
> +/* { dg-do run } */
> +/* { dg-require-effective-target fstack_protector } */
> +/* { dg-options "-fstack-protector-all -O2" } */
> +
> +extern volatile long *stack_chk_guard_ptr;
> +
> +volatile long *
> +get_ptr (void)
> +{
> +  return stack_chk_guard_ptr;
> +}
> +
> +void __attribute__ ((noipa))
> +f (void)
> +{
> +  volatile int x;
> +  x = 1;
> +  x += 1;
> +}
> +
> +#define CHECK(REG) "\tcmp\tx0, " #REG "\n\tbeq\t1f\n"
> +
> +asm (
> +"  .pushsection .data\n"
> +"  .align  3\n"
> +"  .globl  stack_chk_guard_ptr\n"
> +"stack_chk_guard_ptr:\n"
> +#if __ILP32__
> +"  .word   __stack_chk_guard\n"
> +#else
> +"  

Re: [PATCH][GRAPHITE] Consistently use region analysis

2017-10-14 Thread Sebastian Pop
On Fri, Oct 13, 2017 at 8:02 AM, Richard Biener  wrote:

>
> Now that SCEV instantiation handles regions properly (see hunk below
> for a minor fix) we can use it consistently from GRAPHITE and thus
> simplify scalar_evolution_in_region greatly.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> A lot of the parameter renaming stuff looks dead but a more "complete"
> patch causes some more SPEC miscompares and also a bootstrap issue
> (warning only, but an uninitialized use of 'int tem = 0;' ...).
>
> This is probably all latent issues coming up more easily now.
>
> Note that formerly we'd support invariant "parameters" defined in
> the region by copying those out but now SCEV instantiation should
> lead chrec_dont_know for stuff we cannot gobble up (anythin not
> affine).  This probably only worked for the outermost scop in the
> region and it means we need some other way to handle those.


How important is it to move defs out the region?
Can we postpone handling those cases until we have an interesting case?

The
> original issue is probably that "parameters" cannot occur in
> dependences and thus an array index cannot "depend" on the computation
> of a parameter (and array indexes coming from "data" cannot be handled
> anyway?).


Correct.  Parameters can occur in array indexes as long as they cancel out.
For example, the following dependence can be computed:

A[p] vs. A[p+3]

and the following dependence cannot be computed

A[p] vs. A[0]

as the value of the parameter p is not known at compilation time.

We don't seem to have any functional testcase for those
> parameters that are not parameters.
>
>
Ok.  Let's wait for a testcase that needs this functionality.


> Richard.
>
> 2017-10-13  Richard Biener  
>
> * graphite-scop-detection.c
> (scop_detection::stmt_has_simple_data_refs_p): Always use
> the full nest as region.
> (try_generate_gimple_bb): Likewise.
> (build_scops): First split edges, then compute RPO order.
> * sese.c (scalar_evolution_in_region): Simplify now that
> SCEV can handle instantiation in regions.
> * tree-scalar-evolution.c (instantiate_scev_name): Also instantiate
> in the non-loop part of a function if requested.
>

Looks good.
Thanks.


>
> Index: gcc/graphite-scop-detection.c
> ===
> --- gcc/graphite-scop-detection.c   (revision 253721)
> +++ gcc/graphite-scop-detection.c   (working copy)
> @@ -1005,15 +1005,10 @@ scop_detection::graphite_can_represent_e
>  bool
>  scop_detection::stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt)
>  {
> -  edge nest;
> +  edge nest = scop.entry;;
>loop_p loop = loop_containing_stmt (stmt);
>if (!loop_in_sese_p (loop, scop))
> -{
> -  nest = scop.entry;
> -  loop = NULL;
> -}
> -  else
> -nest = loop_preheader_edge (outermost_loop_in_sese (scop, gimple_bb
> (stmt)));
> +loop = NULL;
>
>auto_vec drs;
>if (! graphite_find_data_references_in_stmt (nest, loop, stmt, ))
> @@ -1381,15 +1350,10 @@ try_generate_gimple_bb (scop_p scop, bas
>vec reads = vNULL;
>
>sese_l region = scop->scop_info->region;
> -  edge nest;
> +  edge nest = region.entry;
>loop_p loop = bb->loop_father;
>if (!loop_in_sese_p (loop, region))
> -{
> -  nest = region.entry;
> -  loop = NULL;
> -}
> -  else
> -nest = loop_preheader_edge (outermost_loop_in_sese (region, bb));
> +loop = NULL;
>
>for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
> gsi_next ())
> @@ -1696,6 +1660,13 @@ build_scops (vec *scops)
>/* Now create scops from the lightweight SESEs.  */
>vec scops_l = sb.get_scops ();
>
> +  /* For our out-of-SSA we need a block on s->entry, similar to how
> + we include the LCSSA block in the region.  */
> +  int i;
> +  sese_l *s;
> +  FOR_EACH_VEC_ELT (scops_l, i, s)
> +s->entry = single_pred_edge (split_edge (s->entry));
> +
>/* Domwalk needs a bb to RPO mapping.  Compute it once here.  */
>int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
>int postorder_num = pre_and_rev_post_order_compute (NULL, postorder,
> true);
> @@ -1704,14 +1675,8 @@ build_scops (vec *scops)
>  bb_to_rpo[postorder[i]] = i;
>free (postorder);
>
> -  int i;
> -  sese_l *s;
>FOR_EACH_VEC_ELT (scops_l, i, s)
>  {
> -  /* For our out-of-SSA we need a block on s->entry, similar to how
> - we include the LCSSA block in the region.  */
> -  s->entry = single_pred_edge (split_edge (s->entry));
> -
>scop_p scop = new_scop (s->entry, s->exit);
>
>/* Record all basic blocks and their conditions in REGION.  */
> Index: gcc/sese.c
> ===
> --- gcc/sese.c  (revision 253721)
> +++ gcc/sese.c  (working copy)
> @@ -459,41 +447,16 @@ scev_analyzable_p (tree 

Re: [PATCH][GRAPHITE] Fix PR82525

2017-10-12 Thread Sebastian Pop
On Oct 12, 2017 4:36 AM, "Richard Biener"  wrote:


The following avoids code-generation errors for modulo operations
resulting from our own constraints ending up as no-ops because
the type we code-generate in already imposes the modulo operation.

For the case in SPEC 2k6 triggering this we'd even know the
modulo constraint isn't necessary - we have

 int64_t lower, upper;
 if (lower < upper)
   uint64_t niter = (uint64_t)upper - (uint64_t)lower;

but there's no way to represent in GIMPLE that subtracting
the two signed values will yield a positive value fitting
in the corresponding unsigned type...  We'd need sth
like a MINUSU_EXPR (like the often proposed ABSU_EXPR or
the proposed POINTER_DIFF_EXPR).

This fixes the last code generation errors with SPEC CPU 2006
and -fgraphite-identity -floop-nest-optimize.

loop nest optimized: 483
loop nest not optimized, code generation error: 0
loop nest not optimized, optimized schedule is identical to original
schedule: 173
loop nest not optimized, optimization timed out: 60
loop nest not optimized, ISL signalled an error: 9
loop nest: 725

Note that we still (with and without this patch) get miscompares
in 465.tonto, 416.gamess and 403.gcc (we have those "wrong"
constraint thing leading to empty domains if you remember).

Bootstrap and regtest running on x86_64-unknown-linux-gnu, ok?

Thanks,
Richard.

2017-10-12  Richard Biener  

PR tree-optimization/82525
* graphite-isl-ast-to-gimple.c
(translate_isl_ast_to_gimple::widest_int_from_isl_expr_int): Split
out from ...
(translate_isl_ast_to_gimple::gcc_expression_from_isl_expr_int):
Here.
Fail code generation when we cannot represent the isl integer.
(binary_op_to_tree): Elide modulo operations that are no-ops
in the type we code generate.  Remove now superfluous code
generation errors.

* gcc.dg/graphite/id-30.c: New testcase.
* gfortran.dg/graphite/id-28.f90: Likewise.


Looks good.


Index: gcc/graphite-isl-ast-to-gimple.c
===
--- gcc/graphite-isl-ast-to-gimple.c(revision 253645)
+++ gcc/graphite-isl-ast-to-gimple.c(working copy)
@@ -177,6 +177,7 @@ class translate_isl_ast_to_gimple
   tree gcc_expression_from_isl_ast_expr_id (tree type,
__isl_keep isl_ast_expr
*expr_id,
ivs_params );
+  widest_int widest_int_from_isl_expr_int (__isl_keep isl_ast_expr *expr);
   tree gcc_expression_from_isl_expr_int (tree type,
 __isl_take isl_ast_expr *expr);
   tree gcc_expression_from_isl_expr_op (tree type,
@@ -265,29 +266,46 @@ gcc_expression_from_isl_ast_expr_id (tre
   return fold_convert (type, *val);
 }

-/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
-   type TYPE.  */
+/* Converts an isl_ast_expr_int expression E to a widest_int.
+   Raises a code generation error when the constant doesn't fit.  */

-tree translate_isl_ast_to_gimple::
-gcc_expression_from_isl_expr_int (tree type, __isl_take isl_ast_expr *expr)
+widest_int translate_isl_ast_to_gimple::
+widest_int_from_isl_expr_int (__isl_keep isl_ast_expr *expr)
 {
   gcc_assert (isl_ast_expr_get_type (expr) == isl_ast_expr_int);
   isl_val *val = isl_ast_expr_get_val (expr);
   size_t n = isl_val_n_abs_num_chunks (val, sizeof (HOST_WIDE_INT));
   HOST_WIDE_INT *chunks = XALLOCAVEC (HOST_WIDE_INT, n);
-  tree res;
-  if (isl_val_get_abs_num_chunks (val, sizeof (HOST_WIDE_INT), chunks) ==
-1)
-res = NULL_TREE;
-  else
+  if (n > WIDE_INT_MAX_ELTS
+  || isl_val_get_abs_num_chunks (val, sizeof (HOST_WIDE_INT), chunks)
== -1)
 {
-  widest_int wi = widest_int::from_array (chunks, n, true);
-  if (isl_val_is_neg (val))
-   wi = -wi;
-  res = wide_int_to_tree (type, wi);
+  isl_val_free (val);
+  set_codegen_error ();
+  return 0;
 }
+  widest_int wi = widest_int::from_array (chunks, n, true);
+  if (isl_val_is_neg (val))
+wi = -wi;
   isl_val_free (val);
+  return wi;
+}
+
+/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
+   type TYPE.  Raises a code generation error when the constant doesn't
fit.  */
+
+tree translate_isl_ast_to_gimple::
+gcc_expression_from_isl_expr_int (tree type, __isl_take isl_ast_expr *expr)
+{
+  widest_int wi = widest_int_from_isl_expr_int (expr);
   isl_ast_expr_free (expr);
-  return res;
+  if (codegen_error_p ())
+return NULL_TREE;
+  if (wi::min_precision (wi, TYPE_SIGN (type)) > TYPE_PRECISION (type))
+{
+  set_codegen_error ();
+  return NULL_TREE;
+}
+  return wide_int_to_tree (type, wi);
 }

 /* Converts a binary isl_ast_expr_op expression E to a GCC expression tree
of
@@ -296,14 +314,25 @@ gcc_expression_from_isl_expr_int (tree t
 tree translate_isl_ast_to_gimple::
 binary_op_to_tree (tree type, 

Re: [PATCH][GRAPHITE] Fix PR69728 in "another" way

2017-10-12 Thread Sebastian Pop
On Oct 12, 2017 9:08 AM, "Richard Biener"  wrote:


I made scheduling to fail when we end up with an empty domain but as
I forgot to actually check the return value of build_original_schedule
the fix was equivalent to just doing nothing to the schedule when
it has an empty domain.  I verified that for the testcase it DCEs
the relevant stmt and that this is a valid transform.

Bootstrapped and tested on x86_64-unknown-linux-gnu, SPEC 2k6 is also
happy with this.

Committed as obvious (since no functional change).

Richard.

2017-10-12  Richard Biener  

PR tree-optimization/69728
Revert
2017-09-19  Richard Biener  

PR tree-optimization/69728
* graphite-sese-to-poly.c (schedule_error): New global.
(add_loop_schedule): Handle empty domain by failing the
schedule.
(build_original_schedule): Handle schedule_error.

* graphite-sese-to-poly.c (add_loop_schedule): Handle empty
domain by returning an unchanged schedule.

* gcc.dg/graphite/pr69728.c: Adjust to reflect we can handle
the loop now.  Remove unrelated undefined behavior.


Looks good.


Index: gcc/graphite-sese-to-poly.c
===
--- gcc/graphite-sese-to-poly.c (revision 253645)
+++ gcc/graphite-sese-to-poly.c (working copy)
@@ -1066,8 +1051,6 @@ outer_projection_mupa (__isl_take isl_un
   return isl_multi_union_pw_aff_from_union_pw_multi_aff (data.res);
 }

-static bool schedule_error;
-
 /* Embed SCHEDULE in the constraints of the LOOP domain.  */

 static isl_schedule *
@@ -1082,11 +1065,9 @@ add_loop_schedule (__isl_take isl_schedu
 return empty < 0 ? isl_schedule_free (schedule) : schedule;

   isl_union_set *domain = isl_schedule_get_domain (schedule);
-  /* We cannot apply an empty domain to pbbs in this loop so fail.
- ??? Somehow drop pbbs in the loop instead.  */
+  /* We cannot apply an empty domain to pbbs in this loop so return
early.  */
   if (isl_union_set_is_empty (domain))
 {
-  schedule_error = true;
   isl_union_set_free (domain);
   return schedule;
 }
@@ -1216,8 +1197,6 @@ build_schedule_loop_nest (scop_p scop, i
 static bool
 build_original_schedule (scop_p scop)
 {
-  schedule_error = false;
-
   int i = 0;
   int n = scop->pbbs.length ();
   while (i < n)
@@ -1232,14 +1211,6 @@ build_original_schedule (scop_p scop)
   scop->original_schedule = add_in_sequence (scop->original_schedule,
s);
 }

-  if (schedule_error)
-{
-  if (dump_file)
-   fprintf (dump_file, "[sese-to-poly] failed to build "
-"original schedule\n");
-  return false;
-}
-
   if (dump_file)
 {
   fprintf (dump_file, "[sese-to-poly] original schedule:\n");
Index: gcc/testsuite/gcc.dg/graphite/pr69728.c
===
--- gcc/testsuite/gcc.dg/graphite/pr69728.c (revision 253645)
+++ gcc/testsuite/gcc.dg/graphite/pr69728.c (working copy)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -floop-nest-optimize" } */
+/* { dg-options "-O3 -floop-nest-optimize -fdump-tree-graphite-details" }
*/

-int a[1];
+int a[9];
 int b, c, d, e;
 void
 fn1 ()
@@ -19,3 +19,9 @@ fn1 ()
}
 }
 }
+
+/* At the moment only ISL figures that if (d) is always true.  We've
+   run into scheduling issues before here, not being able to handle
+   empty domains.  */
+
+/* { dg-final { scan-tree-dump "loop nest optimized" "graphite" } }  */


Re: [PATCH][GRAPHITE] Lift some IV restrictions

2017-10-12 Thread Sebastian Pop
On Oct 12, 2017 9:29 AM, "Richard Biener"  wrote:


The type check seems premature (we're checking CHRECs already) and
we certainly can handle POINTER IVs just fine.

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

SPEC CPU 2k6 sees ~100 more loop nest optimizations that way.

Ok?

[I'd rather have problematical testcases for those weird
restrictions]


Sounds good.
Thanks.


Thanks,
Richard.

2017-10-12  Richard Biener  

* graphite-scop-detection.c (loop_ivs_can_be_represented): Remove.
(scop_detection::harmful_loop_in_region): Remove premature
IV type restriction.
(scop_detection::graphite_can_represent_scev): We can handle
pointer IVs just fine.

Index: gcc/graphite-scop-detection.c
===
--- gcc/graphite-scop-detection.c   (revision 253676)
+++ gcc/graphite-scop-detection.c   (working copy)
@@ -254,28 +254,6 @@ dot_cfg ()
   scops.release ();
 }

-/* Can all ivs be represented by a signed integer?
-   As isl might generate negative values in its expressions, signed loop
ivs
-   are required in the backend.  */
-
-static bool
-loop_ivs_can_be_represented (loop_p loop)
-{
-  unsigned type_long_long = TYPE_PRECISION (long_long_integer_type_node);
-  for (gphi_iterator psi = gsi_start_phis (loop->header); !gsi_end_p (psi);
-   gsi_next ())
-{
-  gphi *phi = psi.phi ();
-  tree res = PHI_RESULT (phi);
-  tree type = TREE_TYPE (res);
-
-  if (TYPE_UNSIGNED (type) && TYPE_PRECISION (type) >= type_long_long)
-   return false;
-}
-
-  return true;
-}
-
 /* Returns a COND_EXPR statement when BB has a single predecessor, the
edge between BB and its predecessor is not a loop exit edge, and
the last statement of the single predecessor is a COND_EXPR.  */
@@ -822,13 +800,6 @@ scop_detection::harmful_loop_in_region (
  return true;
}

-  if (! loop_ivs_can_be_represented (loop))
-   {
- DEBUG_PRINT (dp << "[scop-detection-fail] loop_" << loop->num
-  << "IV cannot be represented.\n");
- return true;
-   }
-
   /* Check if all loop nests have at least one data reference.
 ???  This check is expensive and loops premature at this point.
 If important to retain we can pre-compute this for all innermost
@@ -968,14 +939,6 @@ scop_detection::graphite_can_represent_s
   if (chrec_contains_undetermined (scev))
 return false;

-  /* We disable the handling of pointer types, because it’s currently not
- supported by Graphite with the isl AST generator. SSA_NAME nodes are
- the only nodes, which are disabled in case they are pointers to object
- types, but this can be changed.  */
-
-  if (POINTER_TYPE_P (TREE_TYPE (scev)) && TREE_CODE (scev) == SSA_NAME)
-return false;
-
   switch (TREE_CODE (scev))
 {
 case NEGATE_EXPR:


Re: [PATCH][GRAPHITE] Fix PR82451 (and PR82355 in a different way)

2017-10-12 Thread Sebastian Pop
On Oct 11, 2017 9:43 AM, "Richard Biener"  wrote:


For PR82355 I introduced a fake dimension to ISL to allow CHRECs
having an evolution in a loop that isn't fully part of the SESE
region we are processing.  That was easier than fending off those
CHRECs (without simply giving up on SESE regions with those).

But it didn't fully solve the issue as PR82451 shows where we run
into the issue that we eventually have to code-gen those
evolutions and thus in theory need a canonical IV of that containing loop.

So I decided (after Micha pressuring me a bit...) to revisit the
original issue and make SCEV analysis "properly" handle SE regions.
It turns out that it is mostly instantiate_scev lacking proper support
plus the necessary interfacing change (really just cosmetic in some sense)
from a instantiate_before basic-block to a instantiate_before edge.


Very nice.


data-ref interfaces have been similarly adjusted, here changing
the "loop nest" loop parameter to the entry edge for the SE region
and passing that down accordingly.

I've for now tried to keep other high-level loop-based interfaces the
same by simply using the loop preheader edge as entry where appropriate
(needing loop_preheader_edge cope with the loop root tree for simplicity).

In the process I ran into issues with us too overly aggressive
instantiating random trees and thus I cut those down.  That part
doesn't successfully test separately (when I remove the strange
ARRAY_REF instantiation), so it's part of this patch.  I've also
run into an SSA verification fail (the id-27.f90 testcase) which
shows we _do_ need to clear the SCEV cache after introducing
the versioned CFG (and added a comment before it).

On the previously failing testcases I've verified we produce
sensible instantiations for those pesky refs residing in "no" loop
in the SCOP and that we get away with the result in terms of
optimizing.

SPEC 2k6 testing shows

loop nest optimized: 311
loop nest not optimized, code generation error: 0
loop nest not optimized, optimized schedule is identical to original
schedule: 173
loop nest not optimized, optimization timed out: 59
loop nest not optimized, ISL signalled an error: 9
loop nest: 552

for SPEC 2k6 and -floop-nest-optimize while adding -fgraphite-identity
still reveals some codegen errors:

loop nest optimized: 437
loop nest not optimized, code generation error: 25
loop nest not optimized, optimized schedule is identical to original
schedule: 169
loop nest not optimized, optimization timed out: 60
loop nest not optimized, ISL signalled an error: 9
loop nest: 700

Bootstrap and regtest in progress on x86_64-unknown-linux-gnu
(with and without -fgraphite-identity -floop-nest-optimize).

Ok?


Looks good to me.
Thanks.


Thanks,
Richard.

2017-10-11  Richard Biener  

PR tree-optimization/82451
Revert
2017-10-02  Richard Biener  

PR tree-optimization/82355
* graphite-isl-ast-to-gimple.c (build_iv_mapping): Also build
a mapping for the enclosing loop but avoid generating one for
the loop tree root.
(copy_bb_and_scalar_dependences): Remove premature codegen
error on PHIs in blocks duplicated into multiple places.
* graphite-scop-detection.c
(scop_detection::stmt_has_simple_data_refs_p): For a loop not
in the region use it as loop and nest to analyze the DR in.
(try_generate_gimple_bb): Likewise.
* graphite-sese-to-poly.c (extract_affine_chrec): Adjust.
(add_loop_constraints): For blocks in a loop not in the region
create a dimension with a single iteration.
* sese.h (gbb_loop_at_index): Remove assert.

* cfgloop.c (loop_preheader_edge): For the loop tree root
return the single successor of the entry block.
* graphite-isl-ast-to-gimple.c (graphite_regenerate_ast_isl):
Reset the SCEV hashtable and niters.
* graphite-scop-detection.c
(scop_detection::graphite_can_represent_scev): Add SCOP parameter,
assert that we only have POLYNOMIAL_CHREC that vary in loops
contained in the region.
(scop_detection::graphite_can_represent_expr): Adjust.
(scop_detection::stmt_has_simple_data_refs_p): For loops
not in the region set loop to NULL.  The nest is now the
entry edge to the region.
(try_generate_gimple_bb): Likewise.
* sese.c (scalar_evolution_in_region): Adjust for
instantiate_scev change.
* tree-data-ref.h (graphite_find_data_references_in_stmt):
Make nest parameter the edge into the region.
(create_data_ref): Likewise.
* tree-data-ref.c (dr_analyze_indices): Make nest parameter an
entry edge into a region and adjust instantiate_scev calls.
(create_data_ref): Likewise.
(graphite_find_data_references_in_stmt): Likewise.
(find_data_references_in_stmt): Pass the loop preheader 

Re: [PATCH][GRAPHITE] Fix PR82449

2017-10-11 Thread Sebastian Pop
On Oct 9, 2017 8:48 AM, "Richard Biener" <rguent...@suse.de> wrote:

On Mon, 9 Oct 2017, Richard Biener wrote:

> On Fri, 6 Oct 2017, Sebastian Pop wrote:
>
> > On Fri, Oct 6, 2017 at 8:33 AM, Richard Biener <rguent...@suse.de>
wrote:
> >
> > > On Fri, 6 Oct 2017, Sebastian Pop wrote:
> > >
> > > > On Fri, Oct 6, 2017 at 6:56 AM, Richard Biener <rguent...@suse.de>
> > > wrote:
> > > >
> > > > >
> > > > > The following fences off a few more SCEVs through
scev_analyzable_p
> > > given
> > > > > at the end we need those pass chrec_apply when getting a rename
through
> > > > > SCEV.
> > > > >
> > > > > The SCEV in question is
> > > > >
> > > > >   {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
> > > > >
> > > > > which fails to chrec_apply in the CHREC_LEFT part because that
part
> > > > > is not affine (and we're usually not replacing a IV with a
constant
> > > > > where chrec_apply might handle one or the other case).
> > > > >
> > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> > > > >
> > > > > This fixes three out of the remaining 8 codegen errors in SPEC CPU
> > > 2006.
> > > > >
> > > > > Ok?
> > > > >
> > > > > Thanks,
> > > > > Richard.
> > > > >
> > > > > 2017-10-06  Richard Biener  <rguent...@suse.de>
> > > > >
> > > > > PR tree-optimization/82449
> > > > > * sese.c (can_chrec_apply): New function.
> > > > > (scev_analyzable_p): Check we can call chrec_apply on the
SCEV.
> > > > >
> > > > > * gfortran.dg/graphite/pr82449.f: New testcase.
> > >
> > > >
> > > > > Index: gcc/sese.c
> > > > > 
===
> > > > > --- gcc/sese.c  (revision 253477)
> > > > > +++ gcc/sese.c  (working copy)
> > > > > @@ -421,6 +421,27 @@ invariant_in_sese_p_rec (tree t, const s
> > > > >return true;
> > > > >  }
> > > > >
> > > > > +/* Check whether we can call chrec_apply on CHREC with arbitrary
X and
> > > > > VAR.  */
> > >
> > > > +
> > > > > +static bool
> > > > > +can_chrec_apply (tree chrec)
> > >
> >
> > Could we use scev_is_linear_expression ?
> > It seems like can_chrec_apply has the same semantics.
>
> Looks like that works.
>
> >
> > > > > +{
> > > > > +  if (automatically_generated_chrec_p (chrec))
> > > > > +return false;
> > > > > +  switch (TREE_CODE (chrec))
> > > > > +{
> > > > > +case POLYNOMIAL_CHREC:
> > > > > +  if (evolution_function_is_affine_p (chrec))
> > > > > +   return (can_chrec_apply (CHREC_LEFT (chrec))
> > > > > +   && can_chrec_apply (CHREC_RIGHT (chrec)));
> > > > > +  return false;
> > > > > +CASE_CONVERT:
> > > > > +  return can_chrec_apply (TREE_OPERAND (chrec, 0));
> > > > > +default:;
> > > > > +  return tree_does_not_contain_chrecs (chrec);
> > > > > +}
> > > > > +}
> > > > > +
> > > > >  /* Return true when DEF can be analyzed in REGION by the scalar
> > > > > evolution analyzer.  */
> > > > >
> > > > > @@ -449,6 +470,7 @@ scev_analyzable_p (tree def, sese_l 
> > > > > || !defined_in_sese_p (scev, region))
> > > > >  && (tree_does_not_contain_chrecs (scev)
> > > > > || evolution_function_is_affine_p (scev))
> > > > >
> > > >
> > > > Why isn't evolution_function_is_affine_p returning false on {0, +,
{1, +,
> > > > 1}_1}_1?
> > > > This is quadratic.
> > >
> > > It returns false on that but the CHREC we ask it on is
> > >
> > > {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
> > >
> > > only the initial value is "quadratic".
> > >
> >
> > Right.
> > If I understand correctly, the scop is the body of loop_1,
> > and we do not need to repre

Re: [PATCH][GRAPHITE] Fix PR82449

2017-10-06 Thread Sebastian Pop
On Fri, Oct 6, 2017 at 8:33 AM, Richard Biener <rguent...@suse.de> wrote:

> On Fri, 6 Oct 2017, Sebastian Pop wrote:
>
> > On Fri, Oct 6, 2017 at 6:56 AM, Richard Biener <rguent...@suse.de>
> wrote:
> >
> > >
> > > The following fences off a few more SCEVs through scev_analyzable_p
> given
> > > at the end we need those pass chrec_apply when getting a rename through
> > > SCEV.
> > >
> > > The SCEV in question is
> > >
> > >   {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
> > >
> > > which fails to chrec_apply in the CHREC_LEFT part because that part
> > > is not affine (and we're usually not replacing a IV with a constant
> > > where chrec_apply might handle one or the other case).
> > >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> > >
> > > This fixes three out of the remaining 8 codegen errors in SPEC CPU
> 2006.
> > >
> > > Ok?
> > >
> > > Thanks,
> > > Richard.
> > >
> > > 2017-10-06  Richard Biener  <rguent...@suse.de>
> > >
> > > PR tree-optimization/82449
> > > * sese.c (can_chrec_apply): New function.
> > > (scev_analyzable_p): Check we can call chrec_apply on the SCEV.
> > >
> > > * gfortran.dg/graphite/pr82449.f: New testcase.
>
> >
> > > Index: gcc/sese.c
> > > ===
> > > --- gcc/sese.c  (revision 253477)
> > > +++ gcc/sese.c  (working copy)
> > > @@ -421,6 +421,27 @@ invariant_in_sese_p_rec (tree t, const s
> > >return true;
> > >  }
> > >
> > > +/* Check whether we can call chrec_apply on CHREC with arbitrary X and
> > > VAR.  */
>
> > +
> > > +static bool
> > > +can_chrec_apply (tree chrec)
>

Could we use scev_is_linear_expression ?
It seems like can_chrec_apply has the same semantics.


> > > +{
> > > +  if (automatically_generated_chrec_p (chrec))
> > > +return false;
> > > +  switch (TREE_CODE (chrec))
> > > +{
> > > +case POLYNOMIAL_CHREC:
> > > +  if (evolution_function_is_affine_p (chrec))
> > > +   return (can_chrec_apply (CHREC_LEFT (chrec))
> > > +   && can_chrec_apply (CHREC_RIGHT (chrec)));
> > > +  return false;
> > > +CASE_CONVERT:
> > > +  return can_chrec_apply (TREE_OPERAND (chrec, 0));
> > > +default:;
> > > +  return tree_does_not_contain_chrecs (chrec);
> > > +}
> > > +}
> > > +
> > >  /* Return true when DEF can be analyzed in REGION by the scalar
> > > evolution analyzer.  */
> > >
> > > @@ -449,6 +470,7 @@ scev_analyzable_p (tree def, sese_l 
> > > || !defined_in_sese_p (scev, region))
> > >  && (tree_does_not_contain_chrecs (scev)
> > > || evolution_function_is_affine_p (scev))
> > >
> >
> > Why isn't evolution_function_is_affine_p returning false on {0, +, {1, +,
> > 1}_1}_1?
> > This is quadratic.
>
> It returns false on that but the CHREC we ask it on is
>
> {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
>
> only the initial value is "quadratic".
>

Right.
If I understand correctly, the scop is the body of loop_1,
and we do not need to represent the quadratic evolution
of the initial value.


Re: [PATCH][GRAPHITE] Fix PR82449

2017-10-06 Thread Sebastian Pop
On Fri, Oct 6, 2017 at 6:56 AM, Richard Biener  wrote:

>
> The following fences off a few more SCEVs through scev_analyzable_p given
> at the end we need those pass chrec_apply when getting a rename through
> SCEV.
>
> The SCEV in question is
>
>   {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
>
> which fails to chrec_apply in the CHREC_LEFT part because that part
> is not affine (and we're usually not replacing a IV with a constant
> where chrec_apply might handle one or the other case).
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> This fixes three out of the remaining 8 codegen errors in SPEC CPU 2006.
>
> Ok?
>
> Thanks,
> Richard.
>
> 2017-10-06  Richard Biener  
>
> PR tree-optimization/82449
> * sese.c (can_chrec_apply): New function.
> (scev_analyzable_p): Check we can call chrec_apply on the SCEV.
>
> * gfortran.dg/graphite/pr82449.f: New testcase.
>
> Index: gcc/sese.c
> ===
> --- gcc/sese.c  (revision 253477)
> +++ gcc/sese.c  (working copy)
> @@ -421,6 +421,27 @@ invariant_in_sese_p_rec (tree t, const s
>return true;
>  }
>
> +/* Check whether we can call chrec_apply on CHREC with arbitrary X and
> VAR.  */
> +
> +static bool
> +can_chrec_apply (tree chrec)
> +{
> +  if (automatically_generated_chrec_p (chrec))
> +return false;
> +  switch (TREE_CODE (chrec))
> +{
> +case POLYNOMIAL_CHREC:
> +  if (evolution_function_is_affine_p (chrec))
> +   return (can_chrec_apply (CHREC_LEFT (chrec))
> +   && can_chrec_apply (CHREC_RIGHT (chrec)));
> +  return false;
> +CASE_CONVERT:
> +  return can_chrec_apply (TREE_OPERAND (chrec, 0));
> +default:;
> +  return tree_does_not_contain_chrecs (chrec);
> +}
> +}
> +
>  /* Return true when DEF can be analyzed in REGION by the scalar
> evolution analyzer.  */
>
> @@ -449,6 +470,7 @@ scev_analyzable_p (tree def, sese_l 
> || !defined_in_sese_p (scev, region))
>  && (tree_does_not_contain_chrecs (scev)
> || evolution_function_is_affine_p (scev))
>

Why isn't evolution_function_is_affine_p returning false on {0, +, {1, +,
1}_1}_1?
This is quadratic.



> +&& can_chrec_apply (scev)
>  && (! loop
> || ! loop_in_sese_p (loop, region)
> || ! chrec_contains_symbols_defined_in_loop (scev, loop->num));
> Index: gcc/testsuite/gfortran.dg/graphite/pr82449.f
> ===
> --- gcc/testsuite/gfortran.dg/graphite/pr82449.f(nonexistent)
> +++ gcc/testsuite/gfortran.dg/graphite/pr82449.f(working copy)
> @@ -0,0 +1,11 @@
> +! { dg-do compile }
> +! { dg-options "-O2 -floop-nest-optimize" }
> +
> +  SUBROUTINE JDFIDX(MKL,KGSH)
> +  DIMENSION MKL(6,6)
> +  NKL=0
> +  400 DO 40 KG = 1,KGSH
> +  DO 40 LG = 1,KG
> +  NKL = NKL + 1
> +   40 MKL(LG,KG) = NKL
> +  END
>


Re: [PATCH] [graphite] translate reads and writes in a single traversal of memory ops

2017-10-06 Thread Sebastian Pop
On Fri, Oct 6, 2017 at 6:27 AM, Richard Biener 
wrote:
>
> > Richard, could you please commit this patch, as I will need to figure out
> > why my
> > ssh keys don't let me to commit the code.  I will probably need to update
> > the key.
>
> Done.  You probably still have a v1 key which were rejected after some
> point.
> I would guess you'll need to contact overseers to replace your key.
>

Thanks!


Re: [PATCH][GRAPHITE] Rewrite PHI handling in code-gen

2017-10-05 Thread Sebastian Pop
On Thu, Oct 5, 2017 at 9:20 AM, Sebastian Pop <seb...@gmail.com> wrote:
>
> We also need to tag commutative and associative reductions
> in the dependence graph.  Now that the code generation will
> nicely handle scalar dependences, we may want to add back
> some of the code from this commit:
> https://gcc.gnu.org/viewcvs/gcc?view=revision=228255
>
>
The above patch is for tagging the assoc/comm reductions.
Here is the patch that removes reduction dependences
that can be ignored to compute a new schedule:
https://gcc.gnu.org/viewcvs/gcc?view=revision=228530


Re: [PATCH] [graphite] translate reads and writes in a single traversal of memory ops

2017-10-05 Thread Sebastian Pop
On Mon, Oct 2, 2017 at 4:18 AM, Richard Biener <richard.guent...@gmail.com>
wrote:

> On Mon, Oct 2, 2017 at 6:53 AM, Sebastian Pop <sebpop.l...@gmail.com>
> wrote:
> > The patch moves the code that translates reads and writes to isl
> representation
> > in a same loop.  This is to avoid traversing the scop blocks and arrays
> with
> > memory operations 3 times.
>
> LGTM.
>

Richard, could you please commit this patch, as I will need to figure out
why my
ssh keys don't let me to commit the code.  I will probably need to update
the key.

Thanks,
Sebastian


Re: [PATCH] Fix typos in graphite testcases

2017-10-05 Thread Sebastian Pop
On Thu, Oct 5, 2017 at 2:44 AM, Richard Biener 
wrote:

> Causing some UNRESOLVED.
>
> Committed.
>

Looks good.  Thanks!


Re: [PATCH][GRAPHITE] Adjust CASE_CONVERT in extract_affine

2017-10-05 Thread Sebastian Pop
On Wed, Oct 4, 2017 at 2:45 AM, Richard Biener  wrote:

>
> While my last change involving signed types was correct it wasn't optimal.
> We can avoid the modulo constraints if the conversion is widening
> (thus all values fit in the new type).
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?


> Thanks,
> Richard.
>
> 2017-10-04  Richard Biener  
>
> * graphite-sese-to-poly.c (extract_affine): For casts increasing
> precision do not perform modulo reduction.
>

Looks good.
Thanks!


Re: [PATCH][GRAPHITE] Rewrite PHI handling in code-gen

2017-10-05 Thread Sebastian Pop
On Thu, Oct 5, 2017 at 6:43 AM, Richard Biener  wrote:

> On Wed, 4 Oct 2017, Richard Biener wrote:
>
> >
> > The following patch completely re-does PHI handling during
> > code-generation.  PHI handling is currently responsible for 99% of
> > all code-generation issues.  With the patch the number of code-generation
> > issues in SPEC 2k6 decreases from 180 to 5, similar adjustments happen
> > to the testsuite - only gfortran.dg/graphite has some expected code-gen
> > issues left.
>
> So I messed up the testsuite update and it turns out all code-gen
> issues are fixed in all graphite.exp testsuites.  Yay.
>
> > The current idea of categorizing PHIs and doing code-gen based on
> > pattern matching with the original GIMPLE IL isn't feasible given
> > ISL can do transforms like peeling, optimizing away conditions and
> > creating arbitrary number of GBB copies.  The current code fences
> > off a lot of cases by simply giving up.
> >
> > To fix the current code one would need to basically replicate the
> > update-SSA machinery we already have (and pointlessly exercise
> > from the graphite code-gen at the moment).
> >
> > Thus the patch rips out all manual handling of PHIs during
> code-generation
> > and leaves all cross-BB scalar updates to update-SSA.
> >
> > This means "going out-of-SSA" again, but instead of applying out-of-SSA
> > on the original GIMPLE IL I'm just doing this on-the-fly during
> > scalar dependence generation and code generation.
>

Sounds good!


> >
> >  bb3:
> >   goto bb5;
> >
> >  bb4:
> >
> >  bb5:
> >   _2 = PHI <_3(3), _4(4)>
> >
> > becomes (for an identity rewrite) before update-SSA:
> >
> >  bb3':
> >   D.1234 = _3;
> >
> >  bb4':
> >   D.1234 = _4;
> >
> >  bb5':
> >   _5 = D.1234;
> >
> > with _5 being a new def for _2.  update-SSA then re-writes the
> > _3 and _4 uses with available new defs we have registered during
> > code generation of the _3 and _4 def copies and rewrites D.1234
> > into SSA, inserting PHIs where necessary.
> >
> > This scheme of course relies on ISL outputting a correct schedule
> > which of course relies on us setting proper dependence constraints.
> > I've fixed quite a few issues there, for example missing constraints
> > for the SESE liveout variables.
> >
> > One awkward thing is that to not confuse ISL with PHI edge copies
> > placed in latch blocks, like
> >
> >   for (int c0 = 0; c0 < P_22; c0 += 1) {
> > S_6(0, c0);
> > if (P_22 >= c0 + 2)
> >   S_7(0, c0);
> >   }
> >
> > and ISL then happilly peeling off the last iteration where the latch S_7
> > containing only the out-of-SSA copy is not needed.  So I'm trying to
> > detect empty latches and instead insert the out-of-SSA copy in its
> > predecessor instead (I know it doesn't matter if we execute the stmt
> > in the last iteration).
> >
> > The patch as-is ends up with quite some useless SSA copies which
> > is cleaned up by the copyprop pass inside the graphite pipeline
> > but can also be improved by teaching the into-SSA rewrite to
> > eliminate copies.
> >
> > I do expect issues with the patch (I'm seeing CE 416.gamess, but not
> > sure why and 403.gcc miscompare), but it's already become somewhat too
> big
> > to handle.
>
> The CE was on purpose, std=legacy brings it back, now it seems to
> miscompare.
>
> > Currently re-bootstrapping and testing after some cosmetic changes,
> > testsuites ran successfully, SPEC CPU 2006 built and run (with test
> data).
> > Statistics (with all graphite params set to unlimited) are
> >
> > loop nest optimized: 119
> > loop nest not optimized, code generation error: 5
> > loop nest not optimized, optimized schedule is identical to original
> > schedule: 110
> > loop nest not optimized, optimization timed out: 31
> > loop nest not optimized, ISL signalled an error: 6
> > loop nest: 271
> >
> > Ok for trunk?
>
> Thus the following updated patch (only the testsuite part changed).
>
> Bootstrapped with -fgraphite-identity -floop-nest-optimize and tested
> on x86_64-unknown-linux-gnu.
>
> Ok?
>

Yes, the patch looks good.  Thanks!


>
> There are two parts worth working on after this - one is creating
> a versioning condition to fend off alias-set compute fails, the
> other one is working on the proximity constraints.
>

Right.
We also need to tag commutative and associative reductions
in the dependence graph.  Now that the code generation will
nicely handle scalar dependences, we may want to add back
some of the code from this commit:
https://gcc.gnu.org/viewcvs/gcc?view=revision=228255


Re: [PATCH][GRAPHITE] Test for code generation errors

2017-10-02 Thread Sebastian Pop
On Mon, Oct 2, 2017 at 4:58 AM, Richard Biener  wrote:
>
> The following patch adjust GRAPHITE testing to check that existing
> code generation issues occur and makes code generation ICE with
> -fchecking --param graphite-allow-codegen-errors=0.  The param
> is really a testsuite artifact so we can have testcases with
> issues where we have papered over GRAPHITE issues with aborting
> code generation.
>
> This avoids regressing testcases that do not show code generation
> issues and it allows detecting testcases that no longer show
> code generation issues (so we can avoid regressing that feat later).
>
> I'm now working on code-generation issues so that's an important
> feature for me.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> Richard.
>
> 2017-10-02  Richard Biener  
>
> * graphite-isl-ast-to-gimple.c (set_codegen_error): With
> -fchecking and --param graphite-allow-codegen-errors=0 ICE.
> * params.def (PARAM_GRAPHITE_ALLOW_CODEGEN_ERRORS): New param.
>
> * gcc.dg/graphite/graphite.exp: Add -fdump-tree-graphite-details.
> * gcc.dg/graphite/id-16.c: Adjust for existing codegen errors.
> * gcc.dg/graphite/pr46168.c: Likewise.
> * gcc.dg/graphite/pr68756.c: Likewise.
> * gcc.dg/graphite/pr69728.c: Likewise.
> * gcc.dg/graphite/pr71575-2.c: Likewise.
> * gcc.dg/graphite/pr77362.c: Likewise.
> * gcc.dg/graphite/pr81373.c: Likewise.
> * gcc.dg/graphite/run-id-pr67700-1.c: Likewise.
> * gfortran.dg/graphite/interchange-1.f: Likewise.
> * gfortran.dg/graphite/pr29581.f90: Likewise.
> * gfortran.dg/graphite/pr42334-1.f: Likewise.
> * gfortran.dg/graphite/pr42393-1.f90: Likewise.
> * gfortran.dg/graphite/pr42393.f90: Likewise.
> * gfortran.dg/graphite/pr47019.f: Likewise.

Looks good.


[PATCH] [graphite] translate reads and writes in a single traversal of memory ops

2017-10-01 Thread Sebastian Pop
The patch moves the code that translates reads and writes to isl representation
in a same loop.  This is to avoid traversing the scop blocks and arrays with
memory operations 3 times.

* graphite-dependences.c (scop_get_reads): Move code to...
(scop_get_must_writes): Move code to...
(scop_get_may_writes): Move code to...
(scop_get_reads_and_writes): ... here.
(scop_get_dependences): Call scop_get_reads_and_writes.
---
 gcc/graphite-dependences.c | 78 +-
 1 file changed, 21 insertions(+), 57 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index 4ed9d00..2066b2e 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -63,20 +63,21 @@ add_pdr_constraints (poly_dr_p pdr, poly_bb_p pbb)
   return constrain_domain (x, isl_set_copy (pbb->domain));
 }
 
-/* Returns all the memory reads in SCOP.  */
+/* Returns an isl description of all memory operations in SCOP.  The memory
+   reads are returned in READS and writes in MUST_WRITES and MAY_WRITES.  */
 
-static isl_union_map *
-scop_get_reads (scop_p scop)
+static void
+scop_get_reads_and_writes (scop_p scop, isl_union_map *reads,
+  isl_union_map *must_writes,
+  isl_union_map *may_writes)
 {
   int i, j;
   poly_bb_p pbb;
   poly_dr_p pdr;
-  isl_space *space = isl_set_get_space (scop->param_context);
-  isl_union_map *res = isl_union_map_empty (space);
 
   FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
 {
-  FOR_EACH_VEC_ELT (PBB_DRS (pbb), j, pdr)
+  FOR_EACH_VEC_ELT (PBB_DRS (pbb), j, pdr) {
if (pdr_read_p (pdr))
  {
if (dump_file)
@@ -86,33 +87,14 @@ scop_get_reads (scop_p scop)
  }
isl_union_map *um
  = isl_union_map_from_map (add_pdr_constraints (pdr, pbb));
-   res = isl_union_map_union (res, um);
+   reads = isl_union_map_union (reads, um);
if (dump_file)
  {
fprintf (dump_file, "Reads depedence graph: ");
-   print_isl_union_map (dump_file, res);
+   print_isl_union_map (dump_file, reads);
  }
  }
-}
-
-  return isl_union_map_coalesce (res);
-}
-
-/* Returns all the memory must writes in SCOP.  */
-
-static isl_union_map *
-scop_get_must_writes (scop_p scop)
-{
-  int i, j;
-  poly_bb_p pbb;
-  poly_dr_p pdr;
-  isl_space *space = isl_set_get_space (scop->param_context);
-  isl_union_map *res = isl_union_map_empty (space);
-
-  FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
-{
-  FOR_EACH_VEC_ELT (PBB_DRS (pbb), j, pdr)
-   if (pdr_write_p (pdr))
+   else if (pdr_write_p (pdr))
  {
if (dump_file)
  {
@@ -121,33 +103,14 @@ scop_get_must_writes (scop_p scop)
  }
isl_union_map *um
  = isl_union_map_from_map (add_pdr_constraints (pdr, pbb));
-   res = isl_union_map_union (res, um);
+   must_writes = isl_union_map_union (must_writes, um);
if (dump_file)
  {
fprintf (dump_file, "Must writes depedence graph: ");
-   print_isl_union_map (dump_file, res);
+   print_isl_union_map (dump_file, must_writes);
  }
  }
-}
-
-  return isl_union_map_coalesce (res);
-}
-
-/* Returns all the memory may writes in SCOP.  */
-
-static isl_union_map *
-scop_get_may_writes (scop_p scop)
-{
-  int i, j;
-  poly_bb_p pbb;
-  poly_dr_p pdr;
-  isl_space *space = isl_set_get_space (scop->param_context);
-  isl_union_map *res = isl_union_map_empty (space);
-
-  FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
-{
-  FOR_EACH_VEC_ELT (PBB_DRS (pbb), j, pdr)
-   if (pdr_may_write_p (pdr))
+   else if (pdr_may_write_p (pdr))
  {
if (dump_file)
  {
@@ -156,16 +119,15 @@ scop_get_may_writes (scop_p scop)
  }
isl_union_map *um
  = isl_union_map_from_map (add_pdr_constraints (pdr, pbb));
-   res = isl_union_map_union (res, um);
+   may_writes = isl_union_map_union (may_writes, um);
if (dump_file)
  {
fprintf (dump_file, "May writes depedence graph: ");
-   print_isl_union_map (dump_file, res);
+   print_isl_union_map (dump_file, may_writes);
  }
  }
+  }
 }
-
-  return isl_union_map_coalesce (res);
 }
 
 /* Helper function used on each MAP of a isl_union_map.  Computes the
@@ -300,9 +262,11 @@ scop_get_dependences (scop_p scop)
   if (scop->dependence)
 return;
 
-  isl_union_map *reads = scop_get_reads (scop);
-  isl_union_map *must_writes = scop_get_must_writes (scop);
-  isl_union_map *may_writes = scop_get_may_writes (scop);
+  isl_space *space = isl_set_get_space (scop->param_context);
+  isl_union_map *reads = isl_union_map_empty (isl_space_copy (space));
+  isl_union_map 

Re: isl scheduler and spatial locality (Re: [PATCH][GRAPHITE] More TLC)

2017-09-29 Thread Sebastian Pop
On Fri, Sep 29, 2017 at 2:37 PM, Sven Verdoolaege
 wrote:
> [Sorry for the resend; I used the wrong email address to CC Alex]
>
> On Wed, Sep 27, 2017 at 02:18:51PM +0200, Richard Biener wrote:
>> Ah, so I now see why we do not perform interchange on trivial cases like
>>
>> double A[1024][1024], B[1024][1024];
>>
>> void foo(void)
>> {
>>   for (int i = 0; i < 1024; ++i)
>> for (int j = 0; j < 1024; ++j)
>>   A[j][i] = B[j][i];
>> }
>
> I didn't see you mentioning _why_ you expect an interchange here.
> Are you prehaps interested in spatial locality?
> If so, then there are several approaches for taking
> that into account.
> - pluto performs an intra-tile loop interchange to
>   improve temporal and/or spatial locality.  It shouldn't
>   be too hard to do something similar on an isl generated
>   schedule
> - Alex (Oleksandr) has been working on an extension of
>   the isl scheduler that takes into account spatial locality.
>   I'm not sure if it's publicly available.
> - I've been working on a special case of spatial locality
>   (consecutivity).  The current version is available in
>   the consecutivity branch.  Note that it may get rebased and
>   it may not necessarily get merged into master.
>
> There are also other approaches, but they may not be that
> easy to combine with the isl scheduler.

Would the following work?
Add to the proximity relation the array accesses from two
successive iterations of the innermost loop:
A[j][i] -> A[j][i+1] and B[j][i] -> B[j][i+1]
With these two extra relations in the proximity map,
isl should be able to interchange the above loop.

Sebastian


Re: [PATCH][GRAPHITE] More TLC

2017-09-29 Thread Sebastian Pop
On Fri, Sep 29, 2017 at 6:17 AM, Richard Biener  wrote:
> I fixed the "hack patch" somewhat but realized it's not really possible
> ATM to get back at this form because the array descriptor contains only
> information to generate the linearized form.  So while I get now correct
> values they end up with runtime divisions which aren't handled by
> SCEV.

You are right, SCEV has some limits on representing and folding
those division expressions.

There is a proposal in LLVM from Johannes Doerfert
https://reviews.llvm.org/D38255
to use isl as a representation and expression folder instead of the
chains of recurrences for the scalar evolution analysis.  isl would
be able to handle some of the semantics of the div_exprs, and the
semantics of wrap-around variables, and of course it would have
some other limits to represent multiplications (as we spoke about
yesterday, i * N or M * N for example,) and thus that polyhedral
analysis would need to rely on the delinearization of array indices.


Re: [PATCH][GRAPHITE] Abstract away codegen_error setting

2017-09-29 Thread Sebastian Pop
On Fri, Sep 29, 2017 at 3:52 AM, Richard Biener  wrote:
>
> This moves it to a function to make it easy to enable ICEin on them
> in one place.
>
> Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.
>
> Richard.
>
> 2017-09-29  Richard Biener  
>
> * graphite-isl-ast-to-gimple.c
> (translate_isl_ast_to_gimple::set_codegen_error): New function.
> (binary_op_to_tree): Use it.
> (get_rename_from_scev): Likewise.
> (copy_loop_phi_nodes): Likewise.
> (copy_bb_and_scalar_dependences): Likewise.
> (translate_pending_phi_nodes): Likewise.

Looks good.  Thanks.


Re: [PATCH][GRAPHITE] Avoid CHRECs with evolution in loops not in the nest

2017-09-29 Thread Sebastian Pop
On Fri, Sep 29, 2017 at 6:18 AM, Richard Biener  wrote:
> The idea is that we'd transform the above to
> basically wrap each SCOP inside a loop that doesn't iterate.
>
> Does this look reasonable?

Yes, I think your solution looks good.

> 2017-09-29  Richard Biener  
>
> PR tree-optimization/82355
> * graphite-isl-ast-to-gimple.c (build_iv_mapping): Also build
> a mapping for the enclosing loop but avoid generating one for
> the loop tree root.
> (copy_bb_and_scalar_dependences): Remove premature codegen
> error on PHIs in blocks duplicated into multiple places.
> * graphite-scop-detection.c
> (scop_detection::stmt_has_simple_data_refs_p): For a loop not
> in the region use it as loop and nest to analyze the DR in.
> (try_generate_gimple_bb): Likewise.
> * graphite-sese-to-poly.c (extract_affine_chrec): Adjust.
> (add_loop_constraints): For blocks in a loop not in the region
> create a dimension with a single iteration.
> * sese.h (gbb_loop_at_index): Remove assert.
>
> * gcc.dg/graphite/fuse-1.c: Adjust.
> * gcc.dg/graphite/fuse-2.c: Likewise.
> * gcc.dg/graphite/pr82355.c: New testcase.

The change looks good to me.  Thank you!


Re: [PATCH][GRAPHITE] Make --param loop-block-tile-size=0 disable tiling

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 7:20 AM, Richard Biener  wrote:
>
> Currently ISL aborts on this special value and for debugging (and
> tuning?) it's nice to avoid all the clutter introduced by tiling.
>
> Committed as obvious.
>
> Richard.
>
> 2017-09-27  Richard Biener  
>
> * graphite-optimize-isl.c (get_schedule_for_node_st): Allow
> --param loop-block-tile-size=0 to disable tiling.

Looks good.


Re: [PATCH][GRAPHITE] Allow --param graphite-max-arrays-per-scop=0

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 6:51 AM, Richard Biener  wrote:
>
> The following is to allow making --param graphite-max-arrays-per-scop
> unbounded.  That's a little tricky because the bound is used when
> computing "alias-sets" for scalar constraints.  There's an easy way
> out though as we know the maximum alias-set assigned in the SCOP,
> we only have to remember it.  The advantage (if it matters at all)
> is that we avoid a constraint coefficient gap between that last
> used alias-set and the former PARAM_GRAPHITE_MAX_ARRAYS_PER_SCOP.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu, SPEC CPU 2006
> tested.  Will apply after testing finished.
>
> Richard.
>
> 2017-09-27  Richard Biener  
>
> * graphite.h (scop::max_alias_set): New member.
> * graphite-scop-detection.c: Remove references to non-existing
> --param in comments.
> (build_alias_sets): Record the maximum alias set used for drs.
> (build_scops): Support zero as unlimited for
> --param graphite-max-arrays-per-scop.
> * graphite-sese-to-poly.c (add_scalar_version_numbers): Remove
> and inline into ...
> (build_poly_sr_1): ... here.  Compute alias set based on the
> maximum alias set used for drs rather than
> PARAM_GRAPHITE_MAX_ARRAYS_PER_SCOP
>

Maybe we should keep this limit, and instead of failing to handle
huge scops, we could stop the scop detection to expand the
scop past this limit?


Re: [PATCH][GRAPHITE] Remove another small quadraticness

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 6:48 AM, Richard Biener  wrote:
>
> Turns out loop_nest recorded in scop-info isn't really necessary as
> we can simply process parameters in loop bounds during the gather_bbs
> walk where we encounter each loop (identified by its header) once.
>
> This avoids the linear search in record_loop_in_sese.
>
> Bootstrap / regtest running on x86_64-unknown-linux-gnu, will apply.
>
> Richard.
>
> 2017-09-27  Richard Biener  
>
> * graphite-scop-detection.c (find_scop_parameters): Move
> loop bound handling ...
> (gather_bbs::before_dom_children): ... here, avoiding the need
> to build scop_info->loop_nest.
> (record_loop_in_sese): Remove.
> * sese.h (sese_info_t::loop_nest): Remove.
> * sese.c (new_sese_info): Do not allocate loop_nest.
> (free_sese_info): Do not free loop_nest.

Looks good.  Thanks!


Re: [PATCH][GRAPHITE] Speedup SCOP detection some more, add region handling to domwalk

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 6:07 AM, Richard Biener  wrote:
>  /* Maximal number of array references in a scop.  */
>
DEFPARAM (PARAM_GRAPHITE_MAX_ARRAYS_PER_SCOP,
  "graphite-max-arrays-per-scop",
  "maximum number of arrays per scop.",
  100, 0, 0)

Let's also remove this param as we now have max-isl-operations.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Speedup SCOP detection some more, add region handling to domwalk

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 6:07 AM, Richard Biener  wrote:
>
> This removes another quadraticness from SCOP detection, gather_bbs
> domwalk.  This is done by enhancing domwalk to handle SEME regions
> via a special return value from before_dom_children.
>
> With this I'm now confident to remove the
> PARAM_GRAPHITE_MAX_BBS_PER_FUNCTION parameter and its associated limit.
> Being there I've adjusted PARAM_GRAPHITE_MAX_NB_SCOP_PARAMS to its
> documented default value which enables 90 more loos to be processed
> in SPEC CPU 2006.  I've also made a value of zero magic in disabling
> the limit (a trick commonly used in GCC).
>
> Statistics I have gathered a few patches before for SPEC CPU 2006:
>
> 1255 multi-loop SESEs in SCOP processing
> max. params 34, 3 scops >= 20, 15 scops >= 10, 33 scops >= 8
> max. drs per scop 869, 10 scops >= 100
> max. pbbs per scop 36, 12 scops >= 10
> 919 SCOPs fail in build_alias_sets
>
> which shows the default for PARAM_GRAPHITE_MAX_ARRAYS_PER_SCOP
> is reasonable (if tuned to SPEC CPU 2006).
>
> I've also included the hunk that allows -fgraphite-identity
> to work ontop of -floop-nest-optimize and for -floop-nest-optimize
> -ftree-parallelize-all also make sure to code-gen loops that
> end up not transformed.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, SPEC CPU 2006
> tested, applied to trunk.
>
> Richard.
>
> 2017-09-27  Richard Biener  
>
> * doc/invoke.texi (graphite-max-bbs-per-function): Remove.
> (graphite-max-nb-scop-params): Document special value zero.
> * domwalk.h (dom_walker::STOP): New symbolical constant.
> (dom_walker::dom_walker): Add optional parameter for bb to
> RPO mapping.
> (dom_walker::~dom_walker): Declare.
> (dom_walker::before_dom_children): Document STOP return value.
> (dom_walker::m_user_bb_to_rpo): New member.
> (dom_walker::m_bb_to_rpo): Likewise.
> * domwalk.c (dom_walker::dom_walker): Compute bb to RPO
> mapping here if not provided by the user.
> (dom_walker::~dom_walker): Free bb to RPO mapping if not
> provided by the user.
> (dom_walker::STOP): Define.
> (dom_walker::walk): Do not compute bb to RPO mapping here.
> Support STOP return value from before_dom_children to stop
> walking.
> * graphite-optimize-isl.c (optimize_isl): If the schedule
> is the same still generate code if -fgraphite-identity
> or -floop-parallelize-all are given.
> * graphite-scop-detection.c: Include cfganal.h.
> (gather_bbs::gather_bbs): Get and pass through bb to RPO
> mapping.
> (gather_bbs::before_dom_children): Return STOP for BBs
> not in the region.
> (build_scops): Compute bb to RPO mapping and pass it to
> the domwalk.  Treat --param graphite-max-nb-scop-params=0
> as not limiting the number of params.
> * graphite.c (graphite_initialize): Remove limit on the
> number of basic-blocks in a function.
> * params.def (PARAM_GRAPHITE_MAX_BBS_PER_FUNCTION): Remove.
> (PARAM_GRAPHITE_MAX_NB_SCOP_PARAMS): Adjust to documented
> default value of 10.

The patch looks good.  Thanks!

>
> Index: gcc/doc/invoke.texi
> ===
> --- gcc/doc/invoke.texi (revision 253224)
> +++ gcc/doc/invoke.texi (working copy)
> @@ -10512,13 +10512,9 @@ sequence pairs.  This option only applie
>  @item graphite-max-nb-scop-params
>  To avoid exponential effects in the Graphite loop transforms, the
>  number of parameters in a Static Control Part (SCoP) is bounded.  The
> -default value is 10 parameters.

Now that we have "compute-out" functionality in all supported
versions of isl, let's remove this parameter.

We needed this in the past when isl was not able to stop an
exponential computation, and that happened when operating
on large dimension spaces.


Re: [PATCH][GRAPHITE] Simplify SCOP detection

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 2:21 AM, Richard Biener <rguent...@suse.de> wrote:
> On Tue, 26 Sep 2017, Sebastian Pop wrote:
>
>> On Tue, Sep 26, 2017 at 7:03 AM, Richard Biener <rguent...@suse.de> wrote:
>>
>> >
>> > The following is the result of me trying to understand SCOP detection
>> > and the validity checks spread around the machinery.  It removes several
>> > quadraticnesses by folding validity checks into
>> > scop_detection::harmful_loop_in_region where we already walk over all
>> > BBs in the region and process individual found loops.
>> >
>> > It also rewrites build_scop_depth/build_scop_breadth into something
>> > I can undestand.
>> >
>> > Bootstrap and regtest is running on x86_64-unknown-linux-gnu (graphite.exp
>> > for all langs is happy, so is SPEC CPU 2006 testing where the statistics
>> > agree before/after the patch).
>> >
>> > I'll apply this after the bootstrap finished.
>> >
>>
>> Have you tried to bootstrap with BOOT_CFLAGS="-O2 -fgraphite-identity"?
>
> I do "-O2 -g -floop-nest-optimize"

Very good.

> but I guess -fgraphite-identity
> should catch more issues?

It would systematically exercise the scop detection and code generation.
When isl scheduler does not find a better schedule, we would not bother
running the code gen part.

> Hmm, maybe -floop-nest-optimize and
> -fgraphite-identity should be combinable
>
> Index: gcc/graphite-optimize-isl.c
> ===
> --- gcc/graphite-optimize-isl.c (revision 253203)
> +++ gcc/graphite-optimize-isl.c (working copy)
> @@ -189,7 +189,7 @@ optimize_isl (scop_p scop)
> print_schedule_ast (dump_file, scop->original_schedule, scop);
>isl_schedule_free (scop->transformed_schedule);
>scop->transformed_schedule = isl_schedule_copy
> (scop->original_schedule);
> -  return false;
> +  return flag_graphite_identity || flag_loop_parallelize_all;

Yes.

>  }
>
>return true;
>
> I'll test/commit the above.

ok.

>
>>
>> > Richard.
>> >
>> > 2017-09-26  Richard Biener  <rguent...@suse.de>
>> >
>> > * graphite-scop-detection.c (scop_detection::build_scop_depth):
>> > Rewrite,
>> > fold in ...
>> > (scop_detection::build_scop_breadth): ... this.  Removed.
>> > (scop_detection::loop_is_valid_in_scop): Fold into single caller.
>> > (scop_detection::harmful_stmt_in_bb): Likewise.
>> > (scop_detection::graphite_can_represent_stmt): Likewise.
>> > (scop_detection::loop_body_is_valid_scop): Likewise.  Remove
>> > recursion.
>> > (scop_detection::can_represent_loop): Remove recursion, fold in
>> > ...
>> > (scop_detection::can_represent_loop_1): ... this.  Removed.
>> > (scop_detection::harmful_loop_in_region): Simplify after inlining
>> > the above and remove more quadraticness.
>> > (build_scops): Adjust.
>> > * tree-data-ref.c (loop_nest_has_data_refs): Remove pointless
>> > quadraticness.
>> >
>> >
>> This goes in the right direction: it cuts down compilation time.
>> As it is not a trivial change, I need some time to understand how
>> the scop detection works with this change.
>
> The only functional change should be that the SESE composition now
> works top-down instead of working its way bottom-up.  It's not clear
> whether we do more or less work that way

So we went from top-down to bottom-up,
and now with this change we go back to top-down.
I think both algorithms are equivalent in terms of number
of times we validate statements.

We explained the current implementation of the scop detection in:
http://impact.gforge.inria.fr/impact2016/papers/impact2016-kumar.pdf
http://impact.gforge.inria.fr/impact2016/papers/impact2016-kumar-slides.pdf

Here is what happens on an example:

loop_1 {
  loop_2 {
stmt_1
  }
  stmt_2
  loop_3 {
stmt_3
  }
}

- with a top down scop detection, we would start the analysis with loop_1,
and start validating that every stmt in its body (stmt_1, stmt_2,
and finally stmt_3) can be represented in the polyhedral representation.
If at any moment the analysis returns "cannot represent", it would go one
level down and try to validate the immediate sub loop loop_2.
Let's assume that stmt_1 can be represented, and so it would try to
extend the scop by validating stmt_2 and then its sibling loop_3, and say
we fail on validating stmt_3.  All done, max scop is stmt_1 in loop_2
fol

Re: [PATCH][GRAPHITE] More TLC

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 9:33 AM, Richard Biener  wrote:
> Looks like even when hacking the Fortran FE to produce nested
> ARRAY_REFs we run into the same issue for
>
> (gdb) p debug_data_reference (dr)
> #(Data Ref:
> #  bb: 17
> #  stmt:
> VIEW_CONVERT_EXPR(*y_117(D))[_24]{lb:
> 1 sz: _20 * 8}[_26]{lb: 1 sz: _21 * 8}[_28]{lb: 1 sz: _22 * 8}[_29]{lb: 1
> sz: 8} = 0.0;
> #  ref:
> VIEW_CONVERT_EXPR(*y_117(D))[_24]{lb:
> 1 sz: _20 * 8}[_26]{lb: 1 sz: _21 * 8}[_28]{lb: 1 sz: _22 * 8}[_29]{lb: 1
> sz: 8};
> #  base_object:
> VIEW_CONVERT_EXPR(*y_117(D));
> #  Access function 0: {1, +, 1}_4
> #  Access function 1: (integer(kind=8)) {(unsigned long) stride.88_92, +,
> (unsigned long) stride.88_92}_3;
> #  Access function 2: (integer(kind=8)) {(unsigned long) stride.90_96, +,
> (unsigned long) stride.90_96}_2;
> #  Access function 3: (integer(kind=8)) {(unsigned long) stride.92_100, +,
> (unsigned long) stride.92_100}_1;
>
> so it looks like simple strided (where stride is a parameter) access
> is not handled either.

Yes, this is the first option I was mentioning: it could work,
could you please make sure that you don't have a bug in the "hack patch"
where the outer dimension should not contain the parameter
(inner array dimension) times the access function.

Example in C:
int A[100][N];
A[i][j] is linearized as *(A + i * N * 4 + j * 4)
and you may have a bug if you delinearized it in the Fortran FE as A[i * N][j]
Could you please check that it would delinearize back to A[i][j]?

>
> GCCs dependence analysis can at least compute distances of two
> DRs when the difference of the access CHRECs is constant.  Within
> the polyhedral model those cases cannot be handled?

The difficulty for the polyhedral model is in the representation
of a multiplication of parameter times loop index variable.
The delinearization removes these difficulties by creating linear expressions.

Think about multiplication as something introducing exponentiality
and you realize that any such expression would not fit in the
linear model of polyhedra.
A parameter is nothing else than an outer loop index to which we don't
have access to that loop level as it may be outside the current function
in which we get that parameter in.

Sebastian


Re: [PATCH][GRAPHITE] More TLC

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 8:04 AM, Richard Biener  wrote:
>
> Another thing I notice is that we don't handle the multi-dimensional
> accesses the fortran frontend produces:
>
> (gdb) p debug_data_reference (dr)
> #(Data Ref:
> #  bb: 18
> #  stmt: _43 = *a_141(D)[_42];
> #  ref: *a_141(D)[_42];
> #  base_object: *a_141(D);
> #  Access function 0: {{(_38 + stride.88_115) + 1, +, 1}_4, +,
> stride.88_115}_5
>
> ultimatively we fail here because we try to build a constraint for
>
> {{(_38 + stride.88_115) + 1, +, 1}_4, +, stride.88_115}_5
>
> which ends up computing isl_pw_aff_mul (A, stride.88_115) with
> A being the non-constant constraint generated for
> {(_38 + stride.88_115) + 1, +, 1}_4 and stride.88_115 being
> a parameter.  ISL doesn't like that multiplication as the result
> isn't affine (well - it is, we just have parameters in there).
>
> I suppose ISL doesn't handle this form of accesses given the
> two "dimensions" in this scalarized form may overlap?  So we'd
> really need to turn those into references with different access
> functions (even if that's not 100% a valid semantic transformation
> as scalarization isn't reversible without extra information)?

You are right.
This multivariate memory access would be better handled in
delinearized form:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66981
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61000
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14741

There are two ways to handle this issue:
- fix the FORTRAN front-end to emit multi dimensions ARRAY_REFs,
- implement an array delinearization pass, as I implemented in LLVM
http://llvm.org/doxygen/Delinearization_8cpp_source.html
"On Recovering Multi-Dimensional Arrays in Polly"
http://impact.gforge.inria.fr/impact2015/papers/impact2015-grosser.pdf
"Optimistic Delinearization of Parametrically Sized Arrays"
https://dl.acm.org/citation.cfm?id=2751248
LLVM does not have an equivalent for multi-dim ARRAY_REF description
it only reasons about linearized memory accesses like in GCC's RTL:
gep = Get Element Pointer, so we had no other option than to delinearize.

Sebastian


Re: [PATCH][GRAPHITE] More TLC

2017-09-28 Thread Sebastian Pop
On Wed, Sep 27, 2017 at 7:18 AM, Richard Biener <rguent...@suse.de> wrote:

> On Tue, 26 Sep 2017, Sebastian Pop wrote:
>
> > On Mon, Sep 25, 2017 at 8:12 AM, Richard Biener <rguent...@suse.de>
> wrote:
> >
> > > On Fri, 22 Sep 2017, Sebastian Pop wrote:
> > >
> > > > On Fri, Sep 22, 2017 at 8:03 AM, Richard Biener <rguent...@suse.de>
> > > wrote:
> > > >
> > > > >
> > > > > This simplifies canonicalize_loop_closed_ssa and does other minimal
> > > > > TLC.  It also adds a testcase I reduced from a stupid mistake I
> made
> > > > > when reworking canonicalize_loop_closed_ssa.
> > > > >
> > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
> trunk.
> > > > >
> > > > > SPEC CPU 2006 is happy with it, current statistics on x86_64 with
> > > > > -Ofast -march=haswell -floop-nest-optimize are
> > > > >
> > > > >  61 loop nests "optimized"
> > > > >  45 loop nest transforms cancelled because of code generation
> issues
> > > > >  21 loop nest optimizations timed out the 35 ISL "operations"
> we
> > > allow
> > > > >
> > > > > I say "optimized" because the usual transform I've seen is static
> > > tiling
> > > > > as enforced by GRAPHITE according to --param loop-block-tile-size.
> > > > > There's no way to automagically figure what kind of transform ISL
> did
> > > > >
> > > >
> > > > Here is how to automate (without magic) the detection
> > > > of the transform that isl did.
> > > >
> > > > The problem solved by isl is the minimization of strides
> > > > in memory, and to do this, we need to tell the isl scheduler
> > > > the validity dependence graph, in graphite-optimize-isl.c
> > > > see the validity (RAW, WAR, WAW) and the proximity
> > > > (RAR + validity) maps.  The proximity does include the
> > > > read after read, as the isl scheduler needs to minimize
> > > > strides between consecutive reads.
>
> Ah, so I now see why we do not perform interchange on trivial cases like
>
> double A[1024][1024], B[1024][1024];
>
> void foo(void)
> {
>   for (int i = 0; i < 1024; ++i)
> for (int j = 0; j < 1024; ++j)
>   A[j][i] = B[j][i];
> }
>
> which is probably because
>
>   /* FIXME: proximity should not be validity.  */
>   isl_union_map *proximity = isl_union_map_copy (validity);
>
> falls apart when there is _no_ dependence?
>

You are right.  The proximity needs to account for spatial
locality as well if you want to interchange the loop.
To describe the spatial locality, I would recommend adding
to the proximity relation the array accesses from two
successive iterations of the innermost loop:
A[j][i] -> A[j][i+1] and B[j][i] -> B[j][i+1]
With these two extra relations in the proximity map,
isl should be able to interchange the above loop.


>
> I can trick GRAPHITE into performing the interchange for
>
> double A[1024][1024], B[1024][1024];
>
> void foo(void)
> {
>   for (int i = 1; i < 1023; ++i)
> for (int j = 0; j < 1024; ++j)
>   A[j][i] = B[j][i-1] + A[j][i+1];
> }
>
> because now there is a dependence.  Any idea on how to rewrite
> scop_get_dependences to avoid "simplifying"?  I suppose the
> validity constraints _do_ also specify kind-of a proximity
>

Correct: the validity map specifies a subset (it is missing
RAR dependences) of data reuse.


> we just may not prune / optimize them in the same way as
> dependences?
>

Validity constraints are there to "keep the wind blowing
in the same direction" after the transform (otherwise the
result of the transformed computation may be wrong.)

The proximity map should contain a description of
- reuse of memory (temporal locality)
- how close together the access elements are (spatial locality.)
isl will optimize for both if the proximity map has a description
of both.

For the moment the proximity map is initialized only with the
current validity constraints, as you quoted the FIXME comment,
which would only describe a subset of the temporal locality.

Sebastian


Re: [PATCH][GRAPHITE] More TLC

2017-09-28 Thread Sebastian Pop
Hi skimo,

On Tue, Sep 26, 2017 at 10:15 AM, Sven Verdoolaege <
sven.verdoola...@gmail.com> wrote:

> On Tue, Sep 26, 2017 at 09:19:50AM -0500, Sebastian Pop wrote:
> > Sven, is there already a function that computes the sum of all
> > strides in a proximity map?  Maybe you have code that does
> > something similar in pet or ppcg?
>
> What exactly do you want to sum?

If this involves any counting, then it cannot currently
>

I think that it does involve counting: we need to know
the distance between all pairs of array accesses, that is the
number of points in the dependence polyhedron.


> be done in pet or ppcg since isl does not support counting yet
> and the public version of barvinok is GPL licensed.
>
> Also, it's better to ask such questions on the isl mailing list
> isl-developm...@googlegroups.com
>
>
We are trying to find a metric that shows that isl's scheduler
did a useful transform.  Something like a diff tool that shows
before and after scheduling the strides of array accesses.

Could the isl scheduler output a description of what it did?
We would like to use that output to build testcases that match
the behavior of the compiler on different patterns.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Simplify SCOP detection

2017-09-26 Thread Sebastian Pop
On Tue, Sep 26, 2017 at 7:03 AM, Richard Biener  wrote:

>
> The following is the result of me trying to understand SCOP detection
> and the validity checks spread around the machinery.  It removes several
> quadraticnesses by folding validity checks into
> scop_detection::harmful_loop_in_region where we already walk over all
> BBs in the region and process individual found loops.
>
> It also rewrites build_scop_depth/build_scop_breadth into something
> I can undestand.
>
> Bootstrap and regtest is running on x86_64-unknown-linux-gnu (graphite.exp
> for all langs is happy, so is SPEC CPU 2006 testing where the statistics
> agree before/after the patch).
>
> I'll apply this after the bootstrap finished.
>

Have you tried to bootstrap with BOOT_CFLAGS="-O2 -fgraphite-identity"?


> Richard.
>
> 2017-09-26  Richard Biener  
>
> * graphite-scop-detection.c (scop_detection::build_scop_depth):
> Rewrite,
> fold in ...
> (scop_detection::build_scop_breadth): ... this.  Removed.
> (scop_detection::loop_is_valid_in_scop): Fold into single caller.
> (scop_detection::harmful_stmt_in_bb): Likewise.
> (scop_detection::graphite_can_represent_stmt): Likewise.
> (scop_detection::loop_body_is_valid_scop): Likewise.  Remove
> recursion.
> (scop_detection::can_represent_loop): Remove recursion, fold in
> ...
> (scop_detection::can_represent_loop_1): ... this.  Removed.
> (scop_detection::harmful_loop_in_region): Simplify after inlining
> the above and remove more quadraticness.
> (build_scops): Adjust.
> * tree-data-ref.c (loop_nest_has_data_refs): Remove pointless
> quadraticness.
>
>
This goes in the right direction: it cuts down compilation time.
As it is not a trivial change, I need some time to understand how
the scop detection works with this change.

Sebastian


Re: [PATCH][GRAPHITE] More TLC

2017-09-26 Thread Sebastian Pop
On Mon, Sep 25, 2017 at 8:12 AM, Richard Biener <rguent...@suse.de> wrote:

> On Fri, 22 Sep 2017, Sebastian Pop wrote:
>
> > On Fri, Sep 22, 2017 at 8:03 AM, Richard Biener <rguent...@suse.de>
> wrote:
> >
> > >
> > > This simplifies canonicalize_loop_closed_ssa and does other minimal
> > > TLC.  It also adds a testcase I reduced from a stupid mistake I made
> > > when reworking canonicalize_loop_closed_ssa.
> > >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> > >
> > > SPEC CPU 2006 is happy with it, current statistics on x86_64 with
> > > -Ofast -march=haswell -floop-nest-optimize are
> > >
> > >  61 loop nests "optimized"
> > >  45 loop nest transforms cancelled because of code generation issues
> > >  21 loop nest optimizations timed out the 35 ISL "operations" we
> allow
> > >
> > > I say "optimized" because the usual transform I've seen is static
> tiling
> > > as enforced by GRAPHITE according to --param loop-block-tile-size.
> > > There's no way to automagically figure what kind of transform ISL did
> > >
> >
> > Here is how to automate (without magic) the detection
> > of the transform that isl did.
> >
> > The problem solved by isl is the minimization of strides
> > in memory, and to do this, we need to tell the isl scheduler
> > the validity dependence graph, in graphite-optimize-isl.c
> > see the validity (RAW, WAR, WAW) and the proximity
> > (RAR + validity) maps.  The proximity does include the
> > read after read, as the isl scheduler needs to minimize
> > strides between consecutive reads.
> >
> > When you apply the schedule to the dependence graph,
> > one can tell from the result the strides in memory, a good
> > way to say whether a transform was beneficial is to sum up
> > all memory strides, and make sure that the sum of all strides
> > decreases after transform.  We could add a printf with the
> > sum of strides before and after transforms, and have the
> > testcases check for that.
>
> Interesting.  Can you perhaps show me in code how to do that?
>
>
Sven, is there already a function that computes the sum of all
strides in a proximity map?  Maybe you have code that does
something similar in pet or ppcg?

Thanks,
Sebastian


Re: [PATCH] Fix PR82321

2017-09-26 Thread Sebastian Pop
On Tue, Sep 26, 2017 at 6:02 AM, Richard Biener  wrote:

>
> Latent, exposed by me removing the "redundant"
> rewrite-into-loop-closed-ssa.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
>
> Richard.
>
> 2017-09-26  Richard Biener  
>
> PR tree-optimization/82321
> * graphite.c (canonicalize_loop_closed_ssa): Properly check
> for the def being inside the loop.
>
> * gcc.dg/graphite/pr82321.c: New testcase.
>
>
Looks good.
Thanks!


Re: [PATCH] Add helper to sort sibling loops, do so in GRAPHITE

2017-09-26 Thread Sebastian Pop
On Mon, Sep 25, 2017 at 8:18 AM, Richard Biener  wrote:

>
> The following adds a helper to sort the sibling loop list in RPO order
> as it can get messed up (we only ever add loops at the start of the list).
> GRAPHITE SCOP detection assumes this list is sorted naturally in RPO
> order (as a flow_loops_find would generate).
>
> Turns out it helps a few more loops in SPEC CPU 2006 to get optimized
> by GRAPHITE.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, SPEC 2k6 is happy
> with GRAPHITE.
>
> I've tested the variant below with the extra call in pass_tree_loop_init
> but as no pass cares about the sibling list order but graphite I'll not
> commit that hunk.
>
> Applied to trunk (w/o that hunk)
>
> Richard.
>
> 2017-09-25  Richard Biener  
>
> * cfgloop.h (sort_sibling_loops): Declare.
> * cfgloop.c (sort_sibling_loops_cmp): New helper.
> (sort_sibling_loops): New function sorting the sibling loop list
> in RPO order.
> * graphite.c (graphite_transform_loops): Sort sibling loops.
>
>
Looks good.  Thanks!


Re: [PATCH][GRAPHITE] More -fopt-info, do not abort from ISL

2017-09-26 Thread Sebastian Pop
On Mon, Sep 25, 2017 at 4:47 AM, Richard Biener  wrote:

>
> The following also dumps if the optimized schedule is equal to the
> original one.  It also makes all ISL operations (well, nearly) not
> abort on errors but instead propagate errors upward.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> Richard.
>
> 2017-09-25  Richard Biener  
>
> * graphite-optimize-isl.c (optimize_isl): Fail and dump if
> ISL errors other than isl_error_quota happen.  Dump if the
> schedule is the same.
> * graphite-sese-to-poly.c (build_poly_scop): Fail on ISL
> errors instead of aborting inside ISL.
>
>
Looks good.


Re: [PATCH][GRAPHITE] More TLC

2017-09-22 Thread Sebastian Pop
On Fri, Sep 22, 2017 at 8:03 AM, Richard Biener  wrote:

>
> This simplifies canonicalize_loop_closed_ssa and does other minimal
> TLC.  It also adds a testcase I reduced from a stupid mistake I made
> when reworking canonicalize_loop_closed_ssa.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> SPEC CPU 2006 is happy with it, current statistics on x86_64 with
> -Ofast -march=haswell -floop-nest-optimize are
>
>  61 loop nests "optimized"
>  45 loop nest transforms cancelled because of code generation issues
>  21 loop nest optimizations timed out the 35 ISL "operations" we allow
>
> I say "optimized" because the usual transform I've seen is static tiling
> as enforced by GRAPHITE according to --param loop-block-tile-size.
> There's no way to automagically figure what kind of transform ISL did
>

Here is how to automate (without magic) the detection
of the transform that isl did.

The problem solved by isl is the minimization of strides
in memory, and to do this, we need to tell the isl scheduler
the validity dependence graph, in graphite-optimize-isl.c
see the validity (RAW, WAR, WAW) and the proximity
(RAR + validity) maps.  The proximity does include the
read after read, as the isl scheduler needs to minimize
strides between consecutive reads.

When you apply the schedule to the dependence graph,
one can tell from the result the strides in memory, a good
way to say whether a transform was beneficial is to sum up
all memory strides, and make sure that the sum of all strides
decreases after transform.  We could add a printf with the
sum of strides before and after transforms, and have the
testcases check for that.

(usually none with the schedule identical check confused by FILTER
> stuff positioning).  This is also the issue with most GRAPHITE testcases.
> We can't really verify easily whether we performed loop interchange
> or not.  We can probably tell whether we applied loop fusion or
> splitting (by counting loops).
>
> I'm not aware of any remaining ICEs / wrong-code issues with GRAPHITE.
>
> I'm aware that the current "black-box" granularity hinders
> scheduling freedom (each GIMPLE BB is mapped to a ISL stmt, this
> is too coarse to schedule say two writes in a BB independently
> from each other).  Quick experiments could be done by simply
> splitting gimple BBs at some points.
>
> I'm aware that the SCOP detection algorithm assumes that it can
> walk loop->next and find loops "in order" -- but while that's
> true for the initial flow_loops_find result (DFS walk) it isn't
> true for any later created / discovered loops.  Sorting of
> loop siblings in DFS order should be easy (and a general cfgloopanal
> helper).
>
> Richard.
>
> 2017-09-22  Richard Biener  
>
> * graphite-isl-ast-to-gimple.c (graphite_verify): Inline into
> single caller.
> (graphite_regenerate_ast_isl): Do not reset SCEV.  Move debug
> print of no dependency loops ...
> * graphite.c (graphite_transform_loops): ... here.
> (canonicalize_loop_closed_ssa_form): Work from inner to outer
> loops.
> (same_close_phi_node, remove_duplicate_close_phi,
> make_close_phi_nodes_unique, defined_in_loop_p): Fold into ...
> (canonicalize_loop_closed_ssa): ... here and simplify.
> * graphite-optimize-isl.c: Include tree-vectorizer.h.
> (optimize_isl): Use dump_printf_loc to tell when we stopped
> optimizing because of an ISL timeout.
>
> * gcc.dg/graphite/scop-24.c: New testcase.
>
>
The change looks good to me.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Simplify move_sese_in_condition

2017-09-22 Thread Sebastian Pop
On Fri, Sep 22, 2017 at 4:37 AM, Richard Biener  wrote:

>
> This re-implements it avoding the need to recompute dominators and in
> a much simpler way.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress, SPEC CPU
> 2006 is happy.
>
> Richard.
>
> 2017-09-22  Richard Biener  
>
> * sese.c: Include cfganal.h.
> (if_region_set_false_region): Remove.
> (create_if_region_on_edge): Likewise.
> (move_sese_in_condition): Re-implement without destroying
> dominators.
>

This is an excellent cleanup.  Thanks!

Sebastian


Re: [PATCH][GRAPHITE] Fix PR71351

2017-09-21 Thread Sebastian Pop
On Thu, Sep 21, 2017 at 5:07 AM, Richard Biener  wrote:

>
> This PR is about code generation issues with us inserting "loop header
> copies" in the attempt to cover up cases where the loop doesn't run.
> But we are disregarding such cases early already.  Thus the simple
> fix is to not emit those - we have no idea what values to use
> for reduction results anyway.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> 2017-09-21  Richard Biener  
>
> PR tree-optimization/71351
> * graphite-isl-ast-to-gimple.c (translate_isl_ast_to_gimple::
> graphite_create_new_loop_guard): Remove, fold remaining parts
> into caller ...
> (translate_isl_ast_node_for): ... here and simplify.
>
> * gfortran.dg/graphite/pr71351.f90: New testcase.
> * gfortran.dg/graphite/interchange-3.f90: Adjust.
>
>
Looks good to me.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Fix IL after codegen errors

2017-09-21 Thread Sebastian Pop
On Thu, Sep 21, 2017 at 4:44 AM, Richard Biener  wrote:

>
> The following fixes the IL after code generation errors so we can
> continue processing SCOPs.  This increases the number of transformed
> loop nests in SPEC CPU 2006 by 50%.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Richard.
>
> 2017-09-21  Richard Biener  
>
> * graphite-isl-ast-to-gimple.c (graphite_regenerate_ast_isl):
> Restore valid IL after code generation errors.
> * graphite.c (graphite_transform_loops): Diagnose code
> generation issues as MSG_MISSED_OPTIMIZATION and continue
> with processing SCOPs.
>

The change looks good.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Fix affine constraint generation

2017-09-19 Thread Sebastian Pop
On Tue, Sep 19, 2017 at 3:30 AM, Richard Biener  wrote:

>
> The following plugs some holes in extract_affine which failed
> to modulo-reduce signed values in conversions, failed to
> interpret pointer-plus offsets as signed (yeah, stupid GIMPLE IL...)
> and mishandled BIT_NOT_EXPR.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Ok?
>
> Thanks,
> Richard.
>
> 2017-09-19  Richard Biener  
>
> * graphite-sese-to-poly.c (extract_affine): Properly handle
> POINTER_PLUS_EXPR, BIT_NOT_EXPR and conversion to signed.
>

This patch looks good to me.

Thanks,
Sebastian


Re: [PATCH] Fix PR81373

2017-09-19 Thread Sebastian Pop
On Tue, Sep 19, 2017 at 9:17 AM, Richard Biener  wrote:

>
> The following forces scev analyzable SESE liveouts to be handed as
> defs.  Otherwise we end up forgetting to code-generate them.  We
> naturally expect SCEV-cprop to handle them but that pass has cost
> cutoffs (and one can disable it).
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu, ok?
>
> Thanks,
> Richard.
>
> 2017-09-19  Richard Biener  
>
> PR tree-optimization/81373
> * graphite-scop-detection.c (build_cross_bb_scalars_def):
> Force SESE live-out defs to be handled even if they are
> scev_analyzable_p.
>
> * gcc.dg/graphite/pr81373.c: New testcase.
>
>
Looks good to me.

Thanks,
Sebastian


Re: [PATCH][GRAPHITE] Fix PR79483

2017-06-09 Thread Sebastian Pop
On Wed, Jun 7, 2017 at 4:46 AM, Richard Biener  wrote:
>
> When the order of visiting dominator children in domwalk changed
> GRAPHITE falls foul of relying on a particular order BBs are visited
> when computing the original schedule from the vector of pbbs.
>
> The following restores an order that I believe might work.
>
> In the end the original schedule should probably be computed
> not relying on the order of pbbs in the pbb array but by
> visiting the SESE region in an edge walk that "works"
> (build_original_schedule).  We seem to lack a BB -> pbb mapping
> though.
>
> So the patch somewhat feels like a hack - not fixing the real
> problem in the design of build_original_schedule, but it seems
> to work ...
>
> Boostrapped and tested on x86_64-unknown-linux-gnu, ok?
>
> Thanks,
> Richard.
>
> 2017-06-07  Richard Biener  
>
> PR tree-optimization/79483
> * graphite-scop-detection.c (order): New global.
> (get_order): Compute bb to order mapping that satisfies code
> generation constraints.
> (cmp_pbbs): New helper.
> (build_scops): Start domwalk at entry block, sort generated
> pbbs.

I think the change looks good.

Thanks,
Sebastian

>
> * gcc.dg/graphite/pr79483.c: New testcase.
>
> Index: gcc/graphite-scop-detection.c
> ===
> --- gcc/graphite-scop-detection.c   (revision 248914)
> +++ gcc/graphite-scop-detection.c   (working copy)
> @@ -1999,6 +1999,46 @@ gather_bbs::after_dom_children (basic_bl
>  }
>  }
>
> +
> +/* Compute sth like an execution order, dominator order with first executing
> +   edges that stay inside the current loop, delaying processing exit edges.  
> */
> +
> +static vec order;
> +
> +static void
> +get_order (scop_p scop, basic_block bb, vec *order, unsigned 
> *dfs_num)
> +{
> +  if (! bb_in_sese_p (bb, scop->scop_info->region))
> +return;
> +
> +  (*order)[bb->index] = (*dfs_num)++;
> +  for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
> +   son;
> +   son = next_dom_son (CDI_DOMINATORS, son))
> +if (flow_bb_inside_loop_p (bb->loop_father, son))
> +  get_order (scop, son, order, dfs_num);
> +  for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
> +   son;
> +   son = next_dom_son (CDI_DOMINATORS, son))
> +if (! flow_bb_inside_loop_p (bb->loop_father, son))
> +  get_order (scop, son, order, dfs_num);
> +}
> +
> +/* Helper for qsort, sorting after order above.  */
> +
> +static int
> +cmp_pbbs (const void *pa, const void *pb)
> +{
> +  poly_bb_p bb1 = *((const poly_bb_p *)pa);
> +  poly_bb_p bb2 = *((const poly_bb_p *)pb);
> +  if (order[bb1->black_box->bb->index] < order[bb2->black_box->bb->index])
> +return -1;
> +  else if (order[bb1->black_box->bb->index] > 
> order[bb2->black_box->bb->index])
> +return 1;
> +  else
> +return 0;
> +}
> +
>  /* Find Static Control Parts (SCoP) in the current function and pushes
> them to SCOPS.  */
>
> @@ -2022,7 +2062,18 @@ build_scops (vec *scops)
>scop_p scop = new_scop (s->entry, s->exit);
>
>/* Record all basic blocks and their conditions in REGION.  */
> -  gather_bbs (CDI_DOMINATORS, scop).walk (cfun->cfg->x_entry_block_ptr);
> +  gather_bbs (CDI_DOMINATORS, scop).walk (s->entry->dest);
> +
> +  /* domwalk does not fulfil our code-generations constraints on the
> + order of pbb which is to produce sth like execution order, delaying
> +exection of loop exit edges.  So compute such order and sort after
> +that.  */
> +  order.create (last_basic_block_for_fn (cfun));
> +  order.quick_grow (last_basic_block_for_fn (cfun));
> +  unsigned dfs_num = 0;
> +  get_order (scop, s->entry->dest, , _num);
> +  scop->pbbs.qsort (cmp_pbbs);
> +  order.release ();
>
>build_alias_set (scop);
>
> Index: gcc/testsuite/gcc.dg/graphite/pr79483.c
> ===
> --- gcc/testsuite/gcc.dg/graphite/pr79483.c (nonexistent)
> +++ gcc/testsuite/gcc.dg/graphite/pr79483.c (working copy)
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fgraphite-identity" } */
> +
> +int *a;
> +extern int b[];
> +int c;
> +void d ()
> +{
> +  double e[2][3] = {0.0, 0.0, 1.0};
> +  for (int f = 0; f < 2; ++f)
> +for (int g = 0; g < 6; ++g)
> +  b[0] = a[g] * e[f][2];
> +  c = b[0];
> +}


Re: [PATCH][GRAPHITE] Fix PR80906, code-gen IVs in loop-closed position

2017-05-30 Thread Sebastian Pop
On Tue, May 30, 2017 at 7:56 AM, Richard Biener  wrote:
>
> We currently ICE when code generating loop-closed PHIs that are after-loop
> used IVs.  I didn't manage to find the place during analysis that is
> supposed to reject such SCOPs thus the following patch "simply" makes
> us properly generate code for those (works fine on the testcase).
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?

The change looks good to me.  Thanks!

>
> If there's such rejection code it might be lifted now (and eventually
> unconver the bugs I introduce with this patch).
>

I don't think we have any filter in the front-end of graphite to
discard those cases.

Thanks,
Sebastian


Re: [PATCH] Fix PR80539

2017-04-27 Thread Sebastian Pop
The patch looks good to me.

Thanks,
Sebastian

On Thu, Apr 27, 2017 at 4:25 AM, Richard Biener  wrote:
>
> SCEV analysis requires us to be in loop-closed SSA form to be able
> to compute overall effects of inner loops when required.  Unfortunately
> we have too many places it is used where we are not in loop-closed SSA
> form.  The following patch makes us more conservative in two places
> where we previously ICEd.
>
> I'm not 100% sure we'll get away w/ not being in loop-closed SSA form
> (code correctness wise) but unless we get a testcase showing this the
> following is a sane approach (esp. on release branches).
>
> Bootstrap and regtest in progress on x86_64-unknown-linux-gnu.
>
> Richard.
>
> 2017-04-27  Richard Biener  
>
> PR middle-end/80539
> * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not
> being in loop-closed SSA form conservatively.
> (chrec_fold_multiply_poly_poly): Likewise.
>
> * gcc.dg/torture/pr80539.c: New testcase.
>
> Index: gcc/tree-chrec.c
> ===
> --- gcc/tree-chrec.c(revision 247293)
> +++ gcc/tree-chrec.c(working copy)
> @@ -149,7 +149,12 @@ chrec_fold_plus_poly_poly (enum tree_cod
>
>/* This function should never be called for chrecs of loops that
>   do not belong to the same loop nest.  */
> -  gcc_assert (loop0 == loop1);
> +  if (loop0 != loop1)
> +{
> +  /* It still can happen if we are not in loop-closed SSA form.  */
> +  gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA));
> +  return chrec_dont_know;
> +}
>
>if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
>  {
> @@ -211,7 +216,12 @@ chrec_fold_multiply_poly_poly (tree type
> chrec_fold_multiply (type, CHREC_LEFT (poly0), poly1),
> CHREC_RIGHT (poly0));
>
> -  gcc_assert (loop0 == loop1);
> +  if (loop0 != loop1)
> +{
> +  /* It still can happen if we are not in loop-closed SSA form.  */
> +  gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA));
> +  return chrec_dont_know;
> +}
>
>/* poly0 and poly1 are two polynomials in the same variable,
>   {a, +, b}_x * {c, +, d}_x  ->  {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x.  
> */
> Index: gcc/testsuite/gcc.dg/torture/pr80539.c
> ===
> --- gcc/testsuite/gcc.dg/torture/pr80539.c  (nonexistent)
> +++ gcc/testsuite/gcc.dg/torture/pr80539.c  (working copy)
> @@ -0,0 +1,22 @@
> +/* { dg-do compile } */
> +
> +signed char a, b;
> +void fn1()
> +{
> +  signed char c, e;
> +  short d;
> +  if (0) {
> +  for (; d;) {
> +l1:
> + for (c = 7; a; c++)
> +   ;
> + e = 6;
> + for (; b; e++)
> +   ;
> +  }
> +  c -= e;
> +  }
> +  if (d == 7)
> +goto l1;
> +  a = c;
> +}


Re: Fix ICE with -fauto-profile when walking vdefs

2017-04-18 Thread Sebastian Pop
On Mon, Apr 3, 2017 at 5:34 AM, Richard Biener <rguent...@suse.de> wrote:
> On Fri, 31 Mar 2017, Sebastian Pop wrote:
>
>> On Fri, Mar 31, 2017 at 12:06 PM, Richard Biener <rguent...@suse.de> wrote:
> Does the following fix it?
>
> Index: gcc/auto-profile.c
> ===
> --- gcc/auto-profile.c  (revision 246642)
> +++ gcc/auto-profile.c  (working copy)
> @@ -1511,7 +1511,9 @@ afdo_vpt_for_early_inline (stmt_set *pro
>
>if (has_vpt)
>  {
> -  optimize_inline_calls (current_function_decl);
> +  unsigned todo = optimize_inline_calls (current_function_decl);
> +  if (todo & TODO_update_ssa_any)
> +   update_ssa (TODO_update_ssa);
>return true;
>  }

Yes, this patch solves the problem, and this is also what Dehao has
suggested in his last comment in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65972

Thanks,
Sebastian

>
>
> afdo really _grossly_ over-does inlining.  And it looks like a total
> hack to me.
>
> It iterates PARAM_EARLY_INLINER_MAX_ITERATIONS but early_inliner does
> that itself already..


Re: Fix ICE with -fauto-profile when walking vdefs

2017-03-31 Thread Sebastian Pop
On Fri, Mar 31, 2017 at 1:50 PM, Richard Biener  wrote:
> That looks like a workaround rather than the correct fix.  Who sets .MEM? It 
> should assign the proper def.
>

Moving the auto_profile pass above several other passes fixes the problem.
The minimal change to fix the problem is by disabling these two passes:

--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -86,14 +86,12 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_ccp, false /* nonzero_p */);
   /* After CCP we rewrite no longer addressed locals into SSA
  form if possible.  */
-  NEXT_PASS (pass_forwprop);
   NEXT_PASS (pass_early_thread_jumps);
   NEXT_PASS (pass_sra_early);
   /* pass_build_ealias is a dummy pass that ensures that we
  execute TODO_rebuild_alias at this point.  */
   NEXT_PASS (pass_build_ealias);
   NEXT_PASS (pass_fre);
-  NEXT_PASS (pass_early_vrp);
   NEXT_PASS (pass_merge_phi);
   NEXT_PASS (pass_dse);
   NEXT_PASS (pass_cd_dce);

It seems to me that early_vrp is the one changing the IR in an inconsistent way.


Re: Fix ICE with -fauto-profile when walking vdefs

2017-03-31 Thread Sebastian Pop
On Fri, Mar 31, 2017 at 12:06 PM, Richard Biener  wrote:
> That's not a default definition but bogus SSA form.  You have to fix that, 
> not this symptom.
>

Ok.
It also crashes when adding a call to verifty_ssa

diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index 4b21340c6f0..b834a40af4d 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1589,6 +1590,7 @@ afdo_annotate_cfg (const stmt_set _stmts)
 static void
 early_inline ()
 {
+  verify_ssa (true, true);
   compute_inline_parameters (cgraph_node::get (current_function_decl), true);
   unsigned todo = early_inliner (cfun);
   if (todo & TODO_update_ssa_any)

The crash is on:

  gcc_assert (!need_ssa_update_p (cfun));

and after adding a call to update the SSA, it finishes compilation
without errors.
I am testing the following patch:

* auto-profile.c (early_inline): Call update_ssa.

--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1589,6 +1589,8 @@ afdo_annotate_cfg (const stmt_set _stmts)
 static void
 early_inline ()
 {
+  if (need_ssa_update_p (current_function_decl))
+update_ssa (TODO_update_ssa);
   compute_inline_parameters (cgraph_node::get (current_function_decl), true);
   unsigned todo = early_inliner (cfun);
   if (todo & TODO_update_ssa_any)


Fix ICE with -fauto-profile when walking vdefs

2017-03-31 Thread Sebastian Pop
Hi,

with trunk gcc as of today and gcc releases 6.* and 5.*,
I get an ICE when compiling a large c++ project with autoFDO
at -O1 and above with -fauto-profile=some.gcov

internal compiler error: tree check: expected ssa_name, have var_decl
in walk_aliased_vdefs_1, at tree-ssa-alias.c:2912
0x1072fec tree_check_failed(tree_node const*, char const*, int, char
const*, ...)
../../gcc/tree.c:9819
0xed6ad9 tree_check(tree_node*, char const*, int, char const*, tree_code)
../../gcc/tree.h:3064
0xed6ad9 walk_aliased_vdefs_1
../../gcc/tree-ssa-alias.c:2912
0xed6b61 walk_aliased_vdefs(ao_ref*, tree_node*, bool (*)(ao_ref*,
tree_node*, void*), void*, bitmap_head**, bool*, unsigned int)
../../gcc/tree-ssa-alias.c:2972
0xbe97f0 parm_ref_data_preserved_p
../../gcc/ipa-prop.c:1015
0xbe97f0 ipa_load_from_parm_agg(ipa_func_body_info*,
vec*, gimple*, tree_node*,
int*, long*, long*, bool*, bool*)
../../gcc/ipa-prop.c:1138
0xbd3213 unmodified_parm_or_parm_agg_item
../../gcc/ipa-inline-analysis.c:1626
0xbd4d05 set_cond_stmt_execution_predicate
../../gcc/ipa-inline-analysis.c:1789
0xbd4d05 compute_bb_predicates
../../gcc/ipa-inline-analysis.c:1925
0xbdb140 estimate_function_body_sizes
../../gcc/ipa-inline-analysis.c:2603
0xbdfcce compute_inline_parameters(cgraph_node*, bool)
../../gcc/ipa-inline-analysis.c:3048
0x1446ce8 early_inline
../../gcc/auto-profile.c:1592
0x1449aac auto_profile
../../gcc/auto-profile.c:1656

The patch below fixes the ICE by checking that the vdef is an SSA_NAME
before trying to walk to a def stmt.  At that point I see that the
vdef is a var_decl:

(gdb) p vdef
$1 = (tree) 0x7fffda143750
(gdb) pt
warning: Expression is not an assignment (and might have no effect)
 >
used static ignored external VOID file  line 0 col 0
align 8>
(gdb) pgs
warning: Expression is not an assignment (and might have no effect)
.MEM

vdef comes from two frames above as gimple_vuse (stmt) in:

  int walked = walk_aliased_vdefs (, gimple_vuse (stmt), mark_modified,
  , NULL);

(gdb) p stmt
$2 = (gimple *) 0x7fffd77d4730
(gdb) pgg
# VUSE <.MEM>
_66 = this_13(D)->s_;

The reason why I have left the check in the do-while loop
is because vdef is updated at the bottom of the loop as:

  vdef = gimple_vuse (def_stmt);

and that may again find a default definition vdef
that is not pointing to another statement defining it.

The patch passed bootstrap and regression test on x86_64-linux.
Ok for trunk and other release branches?

Thanks,
Sebastian

* tree-ssa-alias.c (walk_aliased_vdefs_1): Handle default virtual defs.

diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index 3f0c650475d..5a66306610f 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -2909,6 +2909,10 @@ walk_aliased_vdefs_1 (ao_ref *ref, tree vdef,
 {
   do
 {
+  /* Before asking for a statement, check that it is an SSA_NAME.  */
+  if (TREE_CODE(vdef) != SSA_NAME)
+   return cnt;
+
   gimple *def_stmt = SSA_NAME_DEF_STMT (vdef);

   if (*visited


Re: [PATCH][GRAPHITE] Remove support for ISL 0.14

2017-02-15 Thread Sebastian Pop
On Wed, Feb 15, 2017 at 6:44 AM, Thomas Schwinge
 wrote:
> Hi!
>
> On Fri, 10 Feb 2017 15:13:57 +0100 (CET), Richard Biener  
> wrote:
>> As a cleanup (and to be able to close bugs only reproducing with ISL 0.14)
>> the following removes support for ISL 0.14 for GCC 7.
>
> (This got committed in r245382.)
>
>> --- config/isl.m4 (revision 245328)
>> +++ config/isl.m4 (working copy)
>> @@ -106,27 +106,15 @@ AC_DEFUN([ISL_CHECK_VERSION],
>
>> -if test x"$ac_has_isl_options_set_schedule_serialize_sccs" = x"yes"; 
>> then
>> -  islver="0.15"
>> -  AC_SUBST([islver])
>> +  AC_MSG_RESULT([required isl version is 0.15 or later])
>>  fi
>
> This removed "islver", which is still used:
>
> Makefile.tpl:   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
> Makefile.tpl:HOST_ISLVER = @islver@
> gcc/Makefile.in:@echo "set ISLVER \"$(ISLVER)\"" >> ./site.tmp
> gcc/testsuite/gcc.dg/graphite/graphite.exp:global ISLVER
> gcc/testsuite/gcc.dg/graphite/graphite.exp:if { $ISLVER == "0.15" } {
> gcc/testsuite/gcc.dg/graphite/graphite.exp-dg-runtest $fuse_files 
> "" "-O2 -ffast-math -floop-nest-optimize -fdump-tree-graphite-all"
> gcc/testsuite/gcc.dg/graphite/graphite.exp-}
>
> OK to commit the following to restore graphite fuse-*.c testing?  That
> is, revert most of (the remaining pieces of) r232811.
>

Looks good.  Thanks!

Sebastian


>  Makefile.in| 2 --
>  Makefile.tpl   | 2 --
>  gcc/testsuite/gcc.dg/graphite/graphite.exp | 8 +---
>  3 files changed, 1 insertion(+), 11 deletions(-)
>
> diff --git Makefile.in Makefile.in
> [snipped]
> diff --git Makefile.tpl Makefile.tpl
> index a6a3166..d0fa070 100644
> --- Makefile.tpl
> +++ Makefile.tpl
> @@ -223,7 +223,6 @@ HOST_EXPORTS = \
> GMPINC="$(HOST_GMPINC)"; export GMPINC; \
> ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
> ISLINC="$(HOST_ISLINC)"; export ISLINC; \
> -   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
> LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
> LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
> XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
> XGCC_FLAGS_FOR_TARGET; \
> @@ -316,7 +315,6 @@ HOST_GMPINC = @gmpinc@
>  # Where to find isl
>  HOST_ISLLIBS = @isllibs@
>  HOST_ISLINC = @islinc@
> -HOST_ISLVER = @islver@
>
>  # Where to find libelf
>  HOST_LIBELFLIBS = @libelflibs@
> diff --git gcc/testsuite/gcc.dg/graphite/graphite.exp 
> gcc/testsuite/gcc.dg/graphite/graphite.exp
> index 2499431..50aae30 100644
> --- gcc/testsuite/gcc.dg/graphite/graphite.exp
> +++ gcc/testsuite/gcc.dg/graphite/graphite.exp
> @@ -49,10 +49,10 @@ set run_id_files  [lsort [glob -nocomplain 
> $srcdir/$subdir/run-id-*.c ] ]
>  set opt_files [lsort [glob -nocomplain 
> $srcdir/$subdir/interchange-*.c \
>
> $srcdir/$subdir/uns-interchange-*.c \
>
> $srcdir/$subdir/isl-ast-gen-*.c \
> +  $srcdir/$subdir/fuse-*.c \
>$srcdir/$subdir/block-*.c \
>$srcdir/$subdir/uns-block-*.c 
> ] ]
>  set vect_files[lsort [glob -nocomplain $srcdir/$subdir/vect-*.c ] ]
> -set fuse_files[lsort [glob -nocomplain $srcdir/$subdir/fuse-*.c ] ]
>
>  # Tests to be compiled.
>  set dg-do-what-default compile
> @@ -64,11 +64,6 @@ set dg-do-what-default run
>  dg-runtest $run_id_files  "" "-O2 -fgraphite-identity"
>  dg-runtest $opt_files "" "-O2 -ffast-math -floop-nest-optimize 
> -fdump-tree-graphite-all"
>
> -global ISLVER
> -if { $ISLVER == "0.15" } {
> -dg-runtest $fuse_files "" "-O2 -ffast-math -floop-nest-optimize 
> -fdump-tree-graphite-all"
> -}
> -
>  # Vectorizer tests, to be run or compiled, depending on target capabilities.
>  global DEFAULT_VECTCFLAGS
>  set DEFAULT_VECTCFLAGS "-O2 -fgraphite-identity -ftree-vectorize 
> -fno-vect-cost-model -fdump-tree-vect-details -ffast-math"
> @@ -84,7 +79,6 @@ foreach f $id_files  {lremove wait_to_run_files $f}
>  foreach f $run_id_files  {lremove wait_to_run_files $f}
>  foreach f $opt_files {lremove wait_to_run_files $f}
>  foreach f $vect_files{lremove wait_to_run_files $f}
> -foreach f $fuse_files{lremove wait_to_run_files $f}
>  dg-runtest $wait_to_run_files "" "-ansi -pedantic-errors"
>
>  # Clean up.
>
>
> GrĂ¼ĂŸe
>  Thomas


Re: [PATCH] Fix PR69823

2017-02-08 Thread Sebastian Pop
On Wed, Feb 8, 2017 at 8:34 AM, Richard Biener  wrote:
>
> The following fixes walking the SESE region when determining if it is
> valid.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Will commit as obvious once that passed.

The change looks good.

Thanks,
Sebastian

>
> Thanks,
> Richard.
>
> 2017-02-08  Richard Biener  
>
> PR tree-optimization/69823
> * graphite-scop-detection.c (scop_detection::harmful_loop_in_region):
> Properly enumerate all BBs in the region.  Use auto_vec/auto_bitmap.
>
> * gcc.dg/graphite/pr69823.c: New testcase.
>
> Index: gcc/graphite-scop-detection.c
> ===
> --- gcc/graphite-scop-detection.c   (revision 245276)
> +++ gcc/graphite-scop-detection.c   (working copy)
> @@ -1062,35 +1062,18 @@ scop_detection::harmful_loop_in_region (
>print_sese (dump_file, scop));
>gcc_assert (dominated_by_p (CDI_DOMINATORS, exit_bb, entry_bb));
>
> -  int depth = bb_dom_dfs_in (CDI_DOMINATORS, exit_bb)
> -- bb_dom_dfs_in (CDI_DOMINATORS, entry_bb);
> +  auto_vec worklist;
> +  auto_bitmap loops;
>
> -  gcc_assert (depth > 0);
> -
> -  vec dom
> -  = get_dominated_to_depth (CDI_DOMINATORS, entry_bb, depth);
> -  int i;
> -  basic_block bb;
> -  bitmap loops = BITMAP_ALLOC (NULL);
> -  FOR_EACH_VEC_ELT (dom, i, bb)
> +  worklist.safe_push (entry_bb);
> +  while (! worklist.is_empty ())
>  {
> +  basic_block bb = worklist.pop ();
>DEBUG_PRINT (dp << "Visiting bb_" << bb->index << "\n");
>
> -  /* We don't want to analyze any bb outside sese.  */
> -  if (!dominated_by_p (CDI_POST_DOMINATORS, bb, exit_bb))
> -   continue;
> -
> -  /* Basic blocks dominated by the scop->exit are not in the scop.  */
> -  if (bb != exit_bb && dominated_by_p (CDI_DOMINATORS, bb, exit_bb))
> -   continue;
> -
>/* The basic block should not be part of an irreducible loop.  */
>if (bb->flags & BB_IRREDUCIBLE_LOOP)
> -   {
> - dom.release ();
> - BITMAP_FREE (loops);
> - return true;
> -   }
> +   return true;
>
>/* Check for unstructured control flow: CFG not generated by structured
>  if-then-else.  */
> @@ -1114,13 +1097,14 @@ scop_detection::harmful_loop_in_region (
>  any loop fully contained in the scop: other bbs are checked below
>  in loop_is_valid_in_scop.  */
>   if (harmful_stmt_in_bb (scop, bb))
> -   {
> - dom.release ();
> - BITMAP_FREE (loops);
> - return true;
> -   }
> +   return true;
> }
>
> +  if (bb != exit_bb)
> +   for (basic_block dom = first_dom_son (CDI_DOMINATORS, bb);
> +dom;
> +dom = next_dom_son (CDI_DOMINATORS, dom))
> + worklist.safe_push (dom);
>  }
>
>/* Go through all loops and check that they are still valid in the combined
> @@ -1133,15 +1117,9 @@ scop_detection::harmful_loop_in_region (
>gcc_assert (loop->num == (int) j);
>
>if (!loop_is_valid_in_scop (loop, scop))
> -   {
> - dom.release ();
> - BITMAP_FREE (loops);
> - return true;
> -   }
> +   return true;
>  }
>
> -  dom.release ();
> -  BITMAP_FREE (loops);
>return false;
>  }
>
> Index: gcc/testsuite/gcc.dg/graphite/pr69823.c
> ===
> --- gcc/testsuite/gcc.dg/graphite/pr69823.c (nonexistent)
> +++ gcc/testsuite/gcc.dg/graphite/pr69823.c (working copy)
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -floop-nest-optimize" } */
> +
> +void
> +foo (int c, int *p, int *a1, int *a2, int *a3)
> +{
> +  int i;
> +
> +  if (c)
> +{
> +  for (i = 0; i < 8; i++)
> +   a1[i] = 1;
> +
> +  if (*p)
> +   *a2 = 0;
> +}
> +
> +  for (i = 0; i < 8; i++)
> +a3[i] = 0;
> +}


Re: [PATCH] Fix PR71824

2017-02-07 Thread Sebastian Pop
On Tue, Feb 7, 2017 at 5:19 AM, Richard Biener  wrote:
> On Wed, 1 Feb 2017, Richard Biener wrote:
>
>> Applied as follows, bootstrapped & tested on x86_64-unknown-linux-gnu.
>
> And as shown by the new testcase (ICEing on the gcc-6-branch only) the
> fix is not enough as breadth merging of loop and loop->next may pull in
> other loops into the region.  Eventually this also shows that only
> trying to merge loop with loop->next may not find all valid scops
> as loop and loop->next->next may eventually be successfully merged
> (inner loops of a loop are not sorted in any particular way, SCoP
> dection seems to assume dominance order).

Understood.  I do not think we take this wrong assumption about
loop order in other parts of Graphite.  Thanks for the patch.

Sebastian


Re: [PATCH] XFAIL gcc.dg/graphite/scop-dsyrk.c

2017-02-01 Thread Sebastian Pop
Sorry for duplicates, I'm resending as plain text for the mailing list.

On Wed, Feb 1, 2017 at 6:57 AM, Richard Biener  wrote:
>
>
> The following XFAILs the testcases, making them fail reliably independelty
> of int/long type sizes and also providing new testcase variants that
> succeed reliably.
>
> I don't see us fixing the underlying niter analysis issue for GCC 7.
>

I agree.  There is a way with isl to represent the modulo expressions for niter.
It would take some time to properly implement.

>
> Tested on x86_64-unknown-linux-gnu with {,-m32}, applied.
>

Thanks,
Sebastian


Re: [PATCH] Provide opt-info for autopar and graphite

2017-02-01 Thread Sebastian Pop
On Wed, Feb 1, 2017 at 4:43 AM, Richard Biener  wrote:
> * graphite.c: Include tree-vectorizer.h for find_loop_location.
> (graphite_transform_loops): Provide opt-info for optimized nests.
> * tree-parloop.c (parallelize_loops): Provide opt-info for
> parallelized loops.

Looks good to me.


Re: [PATCH] Fix PR71824

2017-01-31 Thread Sebastian Pop
On Tue, Jan 31, 2017 at 9:11 AM, Richard Biener <rguent...@suse.de> wrote:
> On Tue, 31 Jan 2017, Richard Biener wrote:
>
>> On Tue, 31 Jan 2017, Sebastian Pop wrote:
>>
>> > Resend as plain text to please gcc-patches@
>> >
>> > On Tue, Jan 31, 2017 at 8:39 AM, Sebastian Pop <seb...@gmail.com> wrote:
>> > >
>> > >
>> > > On Tue, Jan 31, 2017 at 7:49 AM, Richard Biener <rguent...@suse.de> 
>> > > wrote:
>> > >>
>> > >>
>> > >> The following fixes an ICE that happens because instantiate_scev
>> > >> doesn't really work as expected for SESE regions (a FIXME comment
>> > >> hints at this already).  So instead of asserting all goes well
>> > >> just bail out (add_loop_constraints seems to add constraints not
>> > >> required for correctness?).
>> > >
>> > >
>> > > The conditions under which a loop is executed are required for 
>> > > correctness.
>> > > There is a similar check in scop_detection::can_represent_loop_1
>> > >
>> > > && (niter = number_of_latch_executions (loop))
>> > > && !chrec_contains_undetermined (niter)
>> > >
>> > > that is supposed to filter out all these loops where this assert does not
>> > > hold.
>> > > The question is: why scop detection has not rejected this loop?
>> > >
>> > > Well, I see that we do not check that niter can be analyzed in the 
>> > > region:
>> > > so we would need another check like this:
>> > >
>> > > diff --git a/gcc/graphite-scop-detection.c 
>> > > b/gcc/graphite-scop-detection.c
>> > > index 3860693..8e14412 100644
>> > > --- a/gcc/graphite-scop-detection.c
>> > > +++ b/gcc/graphite-scop-detection.c
>> > > @@ -931,6 +931,7 @@ scop_detection::can_represent_loop_1 (loop_p loop,
>> > > sese_l scop)
>> > >  && niter_desc.control.no_overflow
>> > >  && (niter = number_of_latch_executions (loop))
>> > >  && !chrec_contains_undetermined (niter)
>> > > +&& !chrec_contains_undetermined (scalar_evolution_in_region (scop,
>> > > loop, niter))
>> > >  && graphite_can_represent_expr (scop, loop, niter);
>> > >  }
>> > >
>> > > Could you please try this patch and see whether it fixes the problem?
>>
>> It doesn't.  It seems we test the above before the regions are
>> eventually merged?  That is, the above enters with
>>
>> $46 = (const sese_l &) @0x7fffd6f0: {
>>   entry =  7)>,
>>   exit =  8)>}
>>
>> but the failing case with
>>
>> $15 = (const sese_l &) @0x298b420: {entry = 
>> 3)>,
>>   exit =  15)>}
>
> Index: graphite-scop-detection.c
> ===
> --- graphite-scop-detection.c   (revision 245064)
> +++ graphite-scop-detection.c   (working copy)
> @@ -905,7 +905,9 @@ scop_detection::build_scop_breadth (sese
>
>sese_l combined = merge_sese (s1, s2);
>
> -  if (combined)
> +  if (combined
> +  && loop_is_valid_in_scop (loop, combined)
> +  && loop_is_valid_in_scop (loop->next, combined))

Looks good.  Thanks for the fix!

Sebastian

>  s1 = combined;
>else
>  add_scop (s2);
> @@ -931,6 +933,8 @@ scop_detection::can_represent_loop_1 (lo
>  && niter_desc.control.no_overflow
>  && (niter = number_of_latch_executions (loop))
>  && !chrec_contains_undetermined (niter)
> +&& !chrec_contains_undetermined (scalar_evolution_in_region (scop,
> +loop,
> niter))
>  && graphite_can_represent_expr (scop, loop, niter);
>  }
>
>
> seems to fix it.
>
> Richard.


Re: [PATCH] Fix PR71824

2017-01-31 Thread Sebastian Pop
On Tue, Jan 31, 2017 at 9:06 AM, Richard Biener <rguent...@suse.de> wrote:
> On Tue, 31 Jan 2017, Sebastian Pop wrote:
>
>> On Tue, Jan 31, 2017 at 7:49 AM, Richard Biener <rguent...@suse.de> wrote:
>>
>> >
>> > The following fixes an ICE that happens because instantiate_scev
>> > doesn't really work as expected for SESE regions (a FIXME comment
>> > hints at this already).  So instead of asserting all goes well
>> > just bail out (add_loop_constraints seems to add constraints not
>> > required for correctness?).
>> >
>>
>> The conditions under which a loop is executed are required for correctness.
>> There is a similar check in scop_detection::can_represent_loop_1
>>
>> && (niter = number_of_latch_executions (loop))
>> && !chrec_contains_undetermined (niter)
>>
>> that is supposed to filter out all these loops where this assert does not
>> hold.
>> The question is: why scop detection has not rejected this loop?
>>
>> Well, I see that we do not check that niter can be analyzed in the region:
>> so we would need another check like this:
>>
>> diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
>> index 3860693..8e14412 100644
>> --- a/gcc/graphite-scop-detection.c
>> +++ b/gcc/graphite-scop-detection.c
>> @@ -931,6 +931,7 @@ scop_detection::can_represent_loop_1 (loop_p loop,
>> sese_l scop)
>>  && niter_desc.control.no_overflow
>>  && (niter = number_of_latch_executions (loop))
>>  && !chrec_contains_undetermined (niter)
>> +&& !chrec_contains_undetermined (scalar_evolution_in_region (scop,
>> loop, niter))
>>  && graphite_can_represent_expr (scop, loop, niter);
>>  }
>>
>> Could you please try this patch and see whether it fixes the problem?
>
> It doesn't.  It seems we test the above before the regions are
> eventually merged?

We are supposed to verify that the merged regions are still a valid scop.
So we are probably missing in merge_sese an extra call to verify that all
the loops can be represented in the combined region.


Re: [PATCH] Fix PR71824

2017-01-31 Thread Sebastian Pop
Resend as plain text to please gcc-patches@

On Tue, Jan 31, 2017 at 8:39 AM, Sebastian Pop <seb...@gmail.com> wrote:
>
>
> On Tue, Jan 31, 2017 at 7:49 AM, Richard Biener <rguent...@suse.de> wrote:
>>
>>
>> The following fixes an ICE that happens because instantiate_scev
>> doesn't really work as expected for SESE regions (a FIXME comment
>> hints at this already).  So instead of asserting all goes well
>> just bail out (add_loop_constraints seems to add constraints not
>> required for correctness?).
>
>
> The conditions under which a loop is executed are required for correctness.
> There is a similar check in scop_detection::can_represent_loop_1
>
> && (niter = number_of_latch_executions (loop))
> && !chrec_contains_undetermined (niter)
>
> that is supposed to filter out all these loops where this assert does not
> hold.
> The question is: why scop detection has not rejected this loop?
>
> Well, I see that we do not check that niter can be analyzed in the region:
> so we would need another check like this:
>
> diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
> index 3860693..8e14412 100644
> --- a/gcc/graphite-scop-detection.c
> +++ b/gcc/graphite-scop-detection.c
> @@ -931,6 +931,7 @@ scop_detection::can_represent_loop_1 (loop_p loop,
> sese_l scop)
>  && niter_desc.control.no_overflow
>  && (niter = number_of_latch_executions (loop))
>  && !chrec_contains_undetermined (niter)
> +&& !chrec_contains_undetermined (scalar_evolution_in_region (scop,
> loop, niter))
>  && graphite_can_represent_expr (scop, loop, niter);
>  }
>
> Could you please try this patch and see whether it fixes the problem?
>
> Thanks,
> Sebastian
>


Re: [PATCH 2/3] [graphite] add array access function in the right order

2016-04-11 Thread Sebastian Pop
On Sat, Apr 9, 2016 at 11:00 AM, Tom de Vries <tom_devr...@mentor.com> wrote:
> On 09/12/15 19:26, Sebastian Pop wrote:
>>
>> we used to add the access functions in the wrong order, Fortran style,
>> leading to unprofitable interchanges.
>> ---
>>   gcc/graphite-sese-to-poly.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
>> index 887c212..480c552 100644
>> --- a/gcc/graphite-sese-to-poly.c
>> +++ b/gcc/graphite-sese-to-poly.c
>> @@ -912,7 +912,7 @@ pdr_add_memory_accesses (isl_map *acc, dr_info )
>> for (i = 0; i < nb_subscripts; i++)
>>   {
>> isl_pw_aff *aff;
>> -  tree afn = DR_ACCESS_FN (dr, nb_subscripts - 1 - i);
>> +  tree afn = DR_ACCESS_FN (dr, i);
>>
>> aff = extract_affine (scop, afn,
>> isl_space_domain (isl_map_get_space (acc)));
>>
>
> Hi,
>
> I think the fix for PR68953 (
> https://gcc.gnu.org/viewcvs/gcc?view=revision=234851 ) undoes this
> fix.
>
> What problem was this patch intending to address?
>
> In other words, have I re-introduced a problem by fixing PR68953 ?
>

>From the commit message of r234851, it was an interchange profitability
that triggered the change.  I think there is still a problem in the way we are
parsing arrays in C vs. Fortran.  It is good that now we have the correctness
testcase that you added with the patch.

Thanks,
Sebastian


Re: [PATCH, PR68953] Fix pdr accesses order

2016-04-08 Thread Sebastian Pop
On Fri, Apr 8, 2016 at 2:03 AM, Tom de Vries  wrote:
> pdr_0 (read
> in gimple stmt: _9 = yu[_8][0];
> data accesses: { S_4[i1, i2] -> [1, 0, 1 + i1] }

data access should be { S_4[i1, i2] -> [1, 1 + i1, 0] }

> subscript sizes: { [1, i1, 0] : i1 >= 0 and i1 <= 3 }
> )
[...]
> I'm not really sure how this is supposed to be fixed. I imagine that we 
> should do one of 3:
> 1. we change the order in the access functions
> 2. we change the order in the subscript_sizes
> 3. we keep the orders as they are, but don't intersect them directly
>but do an order inversion before.
>
> I've picked 1, since that was the easiest for me to implement (but I'm not 
> sure if by doing so, I've broken any hardcoded graphite assumptions).

1 is the right fix: both access functions and subscript sizes should
be in the same order.
If Richi agrees, ok to commit.

Thanks,
Sebastian


[PATCH] [graphite] document that isl-0.16 is supported

2016-01-29 Thread Sebastian Pop
* config/isl.m4: Add comments about isl-0.16.
* configure: Regenerate.

gcc/
* doc/install.texi: Document that isl-0.16 is supported.
---
 config/isl.m4|  6 +++---
 configure| 12 ++--
 gcc/doc/install.texi |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/config/isl.m4 b/config/isl.m4
index 0103f1f..92524af 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -106,7 +106,7 @@ AC_DEFUN([ISL_CHECK_VERSION],
 LDFLAGS="${_isl_saved_LDFLAGS} ${isllibs} ${gmplibs}"
 LIBS="${_isl_saved_LIBS} -lisl -lgmp"
 
-AC_MSG_CHECKING([for isl 0.15 (or deprecated 0.14)])
+AC_MSG_CHECKING([for isl 0.16, 0.15, or deprecated 0.14])
 AC_TRY_LINK([#include ],
 [isl_ctx_get_max_operations (isl_ctx_alloc ());],
 [gcc_cv_isl=yes],
@@ -114,10 +114,10 @@ AC_DEFUN([ISL_CHECK_VERSION],
 AC_MSG_RESULT([$gcc_cv_isl])
 
 if test "${gcc_cv_isl}" = no ; then
-  AC_MSG_RESULT([recommended isl version is 0.15, minimum required isl 
version 0.14 is deprecated])
+  AC_MSG_RESULT([recommended isl version is 0.16 or 0.15, the minimum 
required isl version 0.14 is deprecated])
 fi
 
-AC_MSG_CHECKING([for isl-0.15])
+AC_MSG_CHECKING([for isl 0.16 or 0.15])
 AC_TRY_LINK([#include ],
 [isl_options_set_schedule_serialize_sccs (NULL, 0);],
 [ac_has_isl_options_set_schedule_serialize_sccs=yes],
diff --git a/configure b/configure
index b9a4b51..89c863c 100755
--- a/configure
+++ b/configure
@@ -6021,8 +6021,8 @@ $as_echo "$as_me: WARNING: using in-tree isl, disabling 
version check" >&2;}
 LDFLAGS="${_isl_saved_LDFLAGS} ${isllibs} ${gmplibs}"
 LIBS="${_isl_saved_LIBS} -lisl -lgmp"
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl 0.15 (or 
deprecated 0.14)" >&5
-$as_echo_n "checking for isl 0.15 (or deprecated 0.14)... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl 0.16, 0.15, or 
deprecated 0.14" >&5
+$as_echo_n "checking for isl 0.16, 0.15, or deprecated 0.14... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include 
@@ -6045,12 +6045,12 @@ rm -f core conftest.err conftest.$ac_objext \
 $as_echo "$gcc_cv_isl" >&6; }
 
 if test "${gcc_cv_isl}" = no ; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: recommended isl version 
is 0.15, minimum required isl version 0.14 is deprecated" >&5
-$as_echo "recommended isl version is 0.15, minimum required isl version 0.14 
is deprecated" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: recommended isl version 
is 0.16 or 0.15, the minimum required isl version 0.14 is deprecated" >&5
+$as_echo "recommended isl version is 0.16 or 0.15, the minimum required isl 
version 0.14 is deprecated" >&6; }
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl-0.15" >&5
-$as_echo_n "checking for isl-0.15... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl 0.16 or 0.15" >&5
+$as_echo_n "checking for isl 0.16 or 0.15... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 062f42c..3df7974 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -383,7 +383,7 @@ installed but it is not in your default library search 
path, the
 @option{--with-mpc} configure option should be used.  See also
 @option{--with-mpc-lib} and @option{--with-mpc-include}.
 
-@item isl Library version 0.15 or 0.14.
+@item isl Library version 0.16, 0.15, or 0.14.
 
 Necessary to build GCC with the Graphite loop optimizations.
 It can be downloaded from @uref{ftp://gcc.gnu.org/pub/gcc/infrastructure/}.
-- 
2.5.0



[PATCH 2/3] [graphite] use codegen_error_p

2016-01-28 Thread Sebastian Pop
* graphite-isl-ast-to-gimple.c (binary_op_to_tree): Call 
codegen_error_p.
(ternary_op_to_tree): Same.
(unary_op_to_tree): Same.
(nary_op_to_tree): Same.
(gcc_expression_from_isl_expr_op): Same.
(gcc_expression_from_isl_expression): Same.
(graphite_create_new_loop): Same.
(graphite_create_new_loop_guard): Same.
(build_iv_mapping): Same.
(graphite_create_new_guard): Same.
(translate_isl_ast_to_gimple::copy_loop_phi_nodes): Same.
(translate_isl_ast_to_gimple::translate_pending_phi_nodes): Same.
---
 gcc/graphite-isl-ast-to-gimple.c | 49 
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 47225ef..ded1f74 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -438,16 +438,14 @@ class translate_isl_ast_to_gimple
vec iv_map);
 
   /* Duplicates the statements of basic block BB into basic block NEW_BB
- and compute the new induction variables according to the IV_MAP.
- CODEGEN_ERROR is set when the code generation cannot continue.  */
+ and compute the new induction variables according to the IV_MAP.  */
 
   bool graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
   vec iv_map);
 
   /* Copies BB and includes in the copied BB all the statements that can
  be reached following the use-def chains from the memory accesses,
- and returns the next edge following this new block.  codegen_error is
- set when the code generation cannot continue.  */
+ and returns the next edge following this new block.  */
 
   edge copy_bb_and_scalar_dependences (basic_block bb, edge next_e,
   vec iv_map);
@@ -480,8 +478,7 @@ class translate_isl_ast_to_gimple
  RENAME_MAP, inserting the gimplification code at GSI_TGT, for the
  translation REGION, with the original copied statement in LOOP, and using
  the induction variable renaming map IV_MAP.  Returns true when something
- has been renamed.  codegen_error is set when the code generation cannot
- continue.  */
+ has been renamed.  */
 
   bool rename_uses (gimple *copy, gimple_stmt_iterator *gsi_tgt,
basic_block old_bb, loop_p loop, vec iv_map);
@@ -597,7 +594,7 @@ binary_op_to_tree (tree type, __isl_take isl_ast_expr 
*expr, ivs_params )
   enum isl_ast_op_type expr_type = isl_ast_expr_get_op_type (expr);
   isl_ast_expr_free (expr);
 
-  if (codegen_error)
+  if (codegen_error_p ())
 return NULL_TREE;
 
   switch (expr_type)
@@ -699,7 +696,7 @@ ternary_op_to_tree (tree type, __isl_take isl_ast_expr 
*expr, ivs_params )
   tree c = gcc_expression_from_isl_expression (type, arg_expr, ip);
   isl_ast_expr_free (expr);
 
-  if (codegen_error)
+  if (codegen_error_p ())
 return NULL_TREE;
 
   return fold_build3 (COND_EXPR, type, a, b, c);
@@ -716,7 +713,8 @@ unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, 
ivs_params )
   isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
   tree tree_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
   isl_ast_expr_free (expr);
-  return codegen_error ? NULL_TREE : fold_build1 (NEGATE_EXPR, type, 
tree_expr);
+  return codegen_error_p () ? NULL_TREE
+: fold_build1 (NEGATE_EXPR, type, tree_expr);
 }
 
 /* Converts an isl_ast_expr_op expression E with unknown number of arguments
@@ -743,7 +741,7 @@ nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, 
ivs_params )
   isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
   tree res = gcc_expression_from_isl_expression (type, arg_expr, ip);
 
-  if (codegen_error)
+  if (codegen_error_p ())
 {
   isl_ast_expr_free (expr);
   return NULL_TREE;
@@ -755,7 +753,7 @@ nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, 
ivs_params )
   arg_expr = isl_ast_expr_get_op_arg (expr, i);
   tree t = gcc_expression_from_isl_expression (type, arg_expr, ip);
 
-  if (codegen_error)
+  if (codegen_error_p ())
{
  isl_ast_expr_free (expr);
  return NULL_TREE;
@@ -775,7 +773,7 @@ translate_isl_ast_to_gimple::
 gcc_expression_from_isl_expr_op (tree type, __isl_take isl_ast_expr *expr,
 ivs_params )
 {
-  if (codegen_error)
+  if (codegen_error_p ())
 {
   isl_ast_expr_free (expr);
   return NULL_TREE;
@@ -837,7 +835,7 @@ translate_isl_ast_to_gimple::
 gcc_expression_from_isl_expression (tree type, __isl_take isl_ast_expr *expr,
ivs_params )
 {
-  if (codegen_error)
+  if (codegen_error_p ())
 {
   isl_ast_expr_free (expr);
   return NULL_TREE;
@@ -879,7 +877,7 @@ graphite_create_new_loop (edge entry_edge, __isl_keep 
isl_ast_node *node_for,
   tree stride = 

[PATCH 3/3] [graphite] remove out of sync comments

2016-01-28 Thread Sebastian Pop
* graphite-isl-ast-to-gimple.c (class translate_isl_ast_to_gimple):
Remove comments from class declarations: they are already in the code
close by the defs.
---
 gcc/graphite-isl-ast-to-gimple.c | 437 ---
 1 file changed, 83 insertions(+), 354 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index ded1f74..161b434 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -171,342 +171,117 @@ class translate_isl_ast_to_gimple
 {
  public:
   translate_isl_ast_to_gimple (sese_info_p r)
-: region (r), codegen_error (false)
-{ }
-
-  /* Translates an isl AST node NODE to GCC representation in the
- context of a SESE.  */
+: region (r), codegen_error (false) { }
   edge translate_isl_ast (loop_p context_loop, __isl_keep isl_ast_node *node,
  edge next_e, ivs_params );
-
-  /* Translates an isl_ast_node_for to Gimple.  */
   edge translate_isl_ast_node_for (loop_p context_loop,
   __isl_keep isl_ast_node *node,
   edge next_e, ivs_params );
-
-  /* Create the loop for a isl_ast_node_for.
-
- - NEXT_E is the edge where new generated code should be attached.  */
   edge translate_isl_ast_for_loop (loop_p context_loop,
   __isl_keep isl_ast_node *node_for,
   edge next_e,
   tree type, tree lb, tree ub,
   ivs_params );
-
-  /* Translates an isl_ast_node_if to Gimple.  */
   edge translate_isl_ast_node_if (loop_p context_loop,
  __isl_keep isl_ast_node *node,
  edge next_e, ivs_params );
-
-  /* Translates an isl_ast_node_user to Gimple.
-
- FIXME: We should remove iv_map.create (loop->num + 1), if it is
- possible.  */
   edge translate_isl_ast_node_user (__isl_keep isl_ast_node *node,
edge next_e, ivs_params );
-
-  /* Translates an isl_ast_node_block to Gimple.  */
   edge translate_isl_ast_node_block (loop_p context_loop,
 __isl_keep isl_ast_node *node,
 edge next_e, ivs_params );
-
-  /* Converts a unary isl_ast_expr_op expression E to a GCC expression tree of
- type TYPE.  */
   tree unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
 ivs_params );
-
-  /* Converts a binary isl_ast_expr_op expression E to a GCC expression tree of
- type TYPE.  */
   tree binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
  ivs_params );
-
-  /* Converts a ternary isl_ast_expr_op expression E to a GCC expression tree 
of
- type TYPE.  */
   tree ternary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
   ivs_params );
-
-  /* Converts an isl_ast_expr_op expression E with unknown number of arguments
- to a GCC expression tree of type TYPE.  */
   tree nary_op_to_tree (tree type, __isl_take isl_ast_expr *expr,
ivs_params );
-
-  /* Converts an isl AST expression E back to a GCC expression tree of
- type TYPE.  */
   tree gcc_expression_from_isl_expression (tree type,
   __isl_take isl_ast_expr *,
   ivs_params );
-
-  /* Return the tree variable that corresponds to the given isl ast identifier
- expression (an isl_ast_expr of type isl_ast_expr_id).
-
- FIXME: We should replace blind conversation of id's type with derivation
- of the optimal type when we get the corresponding isl support.  Blindly
- converting type sizes may be problematic when we switch to smaller
- types.  */
   tree gcc_expression_from_isl_ast_expr_id (tree type,
__isl_keep isl_ast_expr *expr_id,
ivs_params );
-
-  /* Converts an isl_ast_expr_int expression E to a GCC expression tree of
- type TYPE.  */
   tree gcc_expression_from_isl_expr_int (tree type,
 __isl_take isl_ast_expr *expr);
-
-  /* Converts an isl_ast_expr_op expression E to a GCC expression tree of
- type TYPE.  */
   tree gcc_expression_from_isl_expr_op (tree type,
__isl_take isl_ast_expr *expr,
ivs_params );
-
-  /* Creates a new LOOP corresponding to isl_ast_node_for.  Inserts an
- induction variable for the new LOOP.  New LOOP is attached to CFG
- starting at ENTRY_EDGE.  LOOP is inserted into the loop tree and
- becomes the child loop of the OUTER_LOOP.  NEWIVS_INDEX binds
- isl's scattering name to the induction variable created for the
- loop of STMT.  The new induction variable 

[PATCH 1/3] [graphite] assert instead of silently failing code gen

2016-01-28 Thread Sebastian Pop
* graphite-isl-ast-to-gimple.c (get_rename_from_scev): Assert instead of
setting codegen_error to fail codegen.
---
 gcc/graphite-isl-ast-to-gimple.c | 26 ++
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 81ed304..47225ef 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -1833,31 +1833,18 @@ get_rename_from_scev (tree old_name, gimple_seq *stmts, 
loop_p loop,
   tree scev = scalar_evolution_in_region (region->region, loop, old_name);
 
   /* At this point we should know the exact scev for each
- scalar SSA_NAME used in the scop: all the other scalar
- SSA_NAMEs should have been translated out of SSA using
- arrays with one element.  */
-  tree new_expr;
-  if (chrec_contains_undetermined (scev))
-{
-  codegen_error = true;
-  return build_zero_cst (TREE_TYPE (old_name));
-}
+ scalar SSA_NAME used in the scop.  */
+  gcc_assert (!chrec_contains_undetermined (scev));
 
-  new_expr = chrec_apply_map (scev, iv_map);
+  tree new_expr = chrec_apply_map (scev, iv_map);
 
   /* The apply should produce an expression tree containing
  the uses of the new induction variables.  We should be
  able to use new_expr instead of the old_name in the newly
  generated loop nest.  */
-  if (chrec_contains_undetermined (new_expr)
-  || tree_contains_chrecs (new_expr, NULL))
-{
-  codegen_error = true;
-  return build_zero_cst (TREE_TYPE (old_name));
-}
+  gcc_assert (!chrec_contains_undetermined (new_expr)
+ && !tree_contains_chrecs (new_expr, NULL));
 
-  /* We should check all the operands and all of them should dominate the use 
at
- new_expr.  */
   if (TREE_CODE (new_expr) == SSA_NAME)
 {
   basic_block bb = gimple_bb (SSA_NAME_DEF_STMT (new_expr));
@@ -1898,8 +1885,7 @@ get_rename_from_scev (tree old_name, gimple_seq *stmts, 
loop_p loop,
substitution map RENAME_MAP, inserting the gimplification code at
GSI_TGT, for the translation REGION, with the original copied
statement in LOOP, and using the induction variable renaming map
-   IV_MAP.  Returns true when something has been renamed.  codegen_error
-   is set when the code generation cannot continue.  */
+   IV_MAP.  Returns true when something has been renamed.  */
 
 bool
 translate_isl_ast_to_gimple::rename_uses (gimple *copy,
-- 
2.5.0



[PATCH] [graphite] make debug comment more explicit

2016-01-28 Thread Sebastian Pop
2016-01-28  Abderrazek Zaafrani  

* graphite-optimize-isl.c (optimize_isl): Print a different debug
message when isl does not return a valid schedule.
---
 gcc/graphite-optimize-isl.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index d1620d5..6b3108d 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -477,8 +477,15 @@ optimize_isl (scop_p scop)
   if (!schedule || isl_ctx_last_error (scop->isl_context) == isl_error_quota)
 {
   if (dump_file && dump_flags)
-   fprintf (dump_file, "isl timed out --param max-isl-operations=%d\n",
-max_operations);
+   {
+ if (!schedule)
+   fprintf (dump_file, "isl did not return any schedule.\n",
+max_operations);
+ else
+   fprintf (dump_file, "isl timed out --param max-isl-operations=%d\n",
+max_operations);
+   }
+
   if (schedule)
isl_schedule_free (schedule);
   return false;
-- 
2.5.0



Re: [PATCH, PR69110] Don't return NULL access_fns in dr_analyze_indices

2016-01-26 Thread Sebastian Pop
Tom de Vries wrote:
> diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
> index a40f40d..4c29fc2 100644
> --- a/gcc/tree-data-ref.c
> +++ b/gcc/tree-data-ref.c
> @@ -1510,8 +1510,9 @@ initialize_data_dependence_relation (struct 
> data_reference *a,
>if (operand_equal_p (DR_REF (a), DR_REF (b), 0))
>  {
>   if (loop_nest.exists ()
> -&& !object_address_invariant_in_loop_p (loop_nest[0],
> - DR_BASE_OBJECT (a)))
> +  && (!object_address_invariant_in_loop_p (loop_nest[0],
> +   DR_BASE_OBJECT (a))
> +  || DR_NUM_DIMENSIONS (a) == 0))

Also please fix the indentation of all this if stmt.

>{
>  DDR_ARE_DEPENDENT (res) = chrec_dont_know;
>  return res;
> @@ -1548,8 +1549,9 @@ initialize_data_dependence_relation (struct 
> data_reference *a,
>   analyze it.  TODO -- in fact, it would suffice to record that there may
>   be arbitrary dependences in the loops where the base object varies.  */
>if (loop_nest.exists ()
> -  && !object_address_invariant_in_loop_p (loop_nest[0],
> -   DR_BASE_OBJECT (a)))
> +  && (!object_address_invariant_in_loop_p (loop_nest[0],
> +DR_BASE_OBJECT (a))
> +   || DR_NUM_DIMENSIONS (a) == 0))
>  {
>DDR_ARE_DEPENDENT (res) = chrec_dont_know;
>return res;

Let's check for DR_NUM_DIMENSIONS (a) == 0 independently of loop_nest.exists ().
We check for the loop_nest because we need to access the outer loop loop_nest[0]
to analyze the base object of a.

Otherwise the change looks good to me.

Thanks,
Sebastian


[PATCH] [graphite] handle isl_ast_op_select

2016-01-26 Thread Sebastian Pop
2016-01-26  Abderrazek Zaafrani  <a.zaafr...@samsung.com>
    Sebastian Pop  <s@samsung.com>

* graphite-isl-ast-to-gimple.c (ternary_op_to_tree): Handle
isl_ast_op_cond and isl_ast_op_select.
(gcc_expression_from_isl_expr_op): Same.

* gcc.dg/graphite/isl-ast-op-select.c: New.
---
 gcc/graphite-isl-ast-to-gimple.c  | 18 +++---
 gcc/testsuite/gcc.dg/graphite/isl-ast-op-select.c | 29 +++
 2 files changed, 37 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/graphite/isl-ast-op-select.c

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 0f58503..81ed304 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -689,22 +689,20 @@ tree
 translate_isl_ast_to_gimple::
 ternary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params )
 {
-  gcc_assert (isl_ast_expr_get_op_type (expr) == isl_ast_op_minus);
+  enum isl_ast_op_type t = isl_ast_expr_get_op_type (expr);
+  gcc_assert (t == isl_ast_op_cond || t == isl_ast_op_select);
   isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
-  tree tree_first_expr
-= gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree a = gcc_expression_from_isl_expression (type, arg_expr, ip);
   arg_expr = isl_ast_expr_get_op_arg (expr, 1);
-  tree tree_second_expr
-= gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree b = gcc_expression_from_isl_expression (type, arg_expr, ip);
   arg_expr = isl_ast_expr_get_op_arg (expr, 2);
-  tree tree_third_expr
-= gcc_expression_from_isl_expression (type, arg_expr, ip);
+  tree c = gcc_expression_from_isl_expression (type, arg_expr, ip);
   isl_ast_expr_free (expr);
 
   if (codegen_error)
 return NULL_TREE;
-  return fold_build3 (COND_EXPR, type, tree_first_expr,
- tree_second_expr, tree_third_expr);
+
+  return fold_build3 (COND_EXPR, type, a, b, c);
 }
 
 /* Converts a unary isl_ast_expr_op expression E to a GCC expression tree of
@@ -791,7 +789,6 @@ gcc_expression_from_isl_expr_op (tree type, __isl_take 
isl_ast_expr *expr,
 case isl_ast_op_call:
 case isl_ast_op_and_then:
 case isl_ast_op_or_else:
-case isl_ast_op_select:
   gcc_unreachable ();
 
 case isl_ast_op_max:
@@ -822,6 +819,7 @@ gcc_expression_from_isl_expr_op (tree type, __isl_take 
isl_ast_expr *expr,
   return unary_op_to_tree (type, expr, ip);
 
 case isl_ast_op_cond:
+case isl_ast_op_select:
   return ternary_op_to_tree (type, expr, ip);
 
 default:
diff --git a/gcc/testsuite/gcc.dg/graphite/isl-ast-op-select.c 
b/gcc/testsuite/gcc.dg/graphite/isl-ast-op-select.c
new file mode 100644
index 000..688176e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/isl-ast-op-select.c
@@ -0,0 +1,29 @@
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+static void kernel_gemm(int ni, int nj, int nk, double alpha, double beta, 
double C[1024][1024], double A[1024][1024], double B[1024][1024])
+{
+ int i, j, k;
+ for (i = 0; i < ni; i++)
+   for (j = 0; j < nj; j++)
+ {
+   C[i][j] *= beta;
+   for (k = 0; k < nk; ++k)
+ C[i][j] += alpha * A[i][k] * B[k][j];
+ }
+}
+
+void *polybench_alloc_data (int, int);
+
+int main(int argc, char** argv) {
+  int ni = 1024;
+  int nj = 1024;
+  int nk = 1024;
+  double alpha;
+  double beta;
+  double (*C)[1024][1024];
+  C = (double(*)[1024][1024])polybench_alloc_data ((1024) * (1024), 
sizeof(double));
+  double (*A)[1024][1024];
+  A = (double(*)[1024][1024])polybench_alloc_data ((1024) * (1024), 
sizeof(double));
+  double (*B)[1024][1024];
+  kernel_gemm (ni, nj, nk, alpha, beta, *C, *A, *B);
+}
-- 
2.5.0



[PATCH 1/3] add missing testcase

2016-01-25 Thread Sebastian Pop
---
 gcc/testsuite/gcc.dg/graphite/pr69292.c | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/graphite/pr69292.c

diff --git a/gcc/testsuite/gcc.dg/graphite/pr69292.c 
b/gcc/testsuite/gcc.dg/graphite/pr69292.c
new file mode 100644
index 000..b925181
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr69292.c
@@ -0,0 +1,19 @@
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+int m[1];
+
+void
+foo (double a[20][20], double b[20])
+{
+  int i, j, k;
+
+  for (i = 0; i < m[0]; ++i)
+for (j = 0; j < m[0]; ++j)
+  a[i][j] = a[i][j] + 1;
+
+  for (k = 0; k < 20; ++k)
+for (i = 0; i < m[0]; ++i)
+  for (j = 0; j < m[0]; ++j)
+   b[i] = b[i] + a[i][j];
+}
+
-- 
2.5.0



[PATCH 2/3] fix PR68343: disable fuse-*.c tests for isl 0.14 or earlier

2016-01-25 Thread Sebastian Pop
The patch disables all fuse-*.c tests when configuring gcc with isl 0.14 or 
earlier.

ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl: Export ISLVER.
* configure: Regenerate.
* config/isl.m4: Detect isl-0.15.

gcc/

* Makefile.in: Set ISLVER in site.exp.
* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Define HAVE_isl for isl-0.15.

gcc/testsuite/

* gcc.dg/graphite/graphite.exp: Only run the fuse-*.c tests with 
isl-0.15.
---
 Makefile.in|  2 ++
 Makefile.tpl   |  2 ++
 config/isl.m4  | 12 
 configure  | 29 +
 gcc/Makefile.in|  1 +
 gcc/testsuite/gcc.dg/graphite/fuse-2.c |  4 ++--
 gcc/testsuite/gcc.dg/graphite/graphite.exp |  8 +++-
 7 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 20d1c90..a519a54 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -222,6 +222,7 @@ HOST_EXPORTS = \
GMPINC="$(HOST_GMPINC)"; export GMPINC; \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
+   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
XGCC_FLAGS_FOR_TARGET; \
@@ -315,6 +316,7 @@ HOST_GMPINC = @gmpinc@
 # Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
+HOST_ISLVER = @islver@
 
 # Where to find libelf
 HOST_LIBELFLIBS = @libelflibs@
diff --git a/Makefile.tpl b/Makefile.tpl
index 2567365..829f664 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -225,6 +225,7 @@ HOST_EXPORTS = \
GMPINC="$(HOST_GMPINC)"; export GMPINC; \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
+   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
XGCC_FLAGS_FOR_TARGET; \
@@ -318,6 +319,7 @@ HOST_GMPINC = @gmpinc@
 # Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
+HOST_ISLVER = @islver@
 
 # Where to find libelf
 HOST_LIBELFLIBS = @libelflibs@
diff --git a/config/isl.m4 b/config/isl.m4
index 86ccb94..0103f1f 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -117,6 +117,18 @@ AC_DEFUN([ISL_CHECK_VERSION],
   AC_MSG_RESULT([recommended isl version is 0.15, minimum required isl 
version 0.14 is deprecated])
 fi
 
+AC_MSG_CHECKING([for isl-0.15])
+AC_TRY_LINK([#include ],
+[isl_options_set_schedule_serialize_sccs (NULL, 0);],
+[ac_has_isl_options_set_schedule_serialize_sccs=yes],
+[ac_has_isl_options_set_schedule_serialize_sccs=no])
+AC_MSG_RESULT($ac_has_isl_options_set_schedule_serialize_sccs)
+
+if test x"$ac_has_isl_options_set_schedule_serialize_sccs" = x"yes"; then
+  islver="0.15"
+  AC_SUBST([islver])
+fi
+
 CFLAGS=$_isl_saved_CFLAGS
 LDFLAGS=$_isl_saved_LDFLAGS
 LIBS=$_isl_saved_LIBS
diff --git a/configure b/configure
index cae3373..b9a4b51 100755
--- a/configure
+++ b/configure
@@ -650,6 +650,7 @@ extra_linker_plugin_flags
 extra_linker_plugin_configure_flags
 islinc
 isllibs
+islver
 poststage1_ldflags
 poststage1_libs
 stage1_ldflags
@@ -6048,6 +6049,34 @@ $as_echo "$gcc_cv_isl" >&6; }
 $as_echo "recommended isl version is 0.15, minimum required isl version 0.14 
is deprecated" >&6; }
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl-0.15" >&5
+$as_echo_n "checking for isl-0.15... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include 
+int
+main ()
+{
+isl_options_set_schedule_serialize_sccs (NULL, 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_has_isl_options_set_schedule_serialize_sccs=yes
+else
+  ac_has_isl_options_set_schedule_serialize_sccs=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+conftest$ac_exeext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$ac_has_isl_options_set_schedule_serialize_sccs" >&5
+$as_echo "$ac_has_isl_options_set_schedule_serialize_sccs" >&6; }
+
+if test x"$ac_has_isl_options_set_schedule_serialize_sccs" = x"yes"; then
+  islver="0.15"
+
+fi
+
 CFLAGS=$_isl_saved_CFLAGS
 LDFLAGS=$_isl_saved_LDFLAGS
 LIBS=$_isl_saved_LIBS
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ab9cbbf..aa3c018 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3698,6 +3698,7 @@ site.exp: ./config.status Makefile
  echo "set PLUGINCFLAGS \"$(PLUGINCFLAGS)\"" >> ./site.tmp; \
  echo "set GMPINC \"$(GMPINC)\"" >> 

[PATCH 3/3] new scop schedule for isl-0.15

2016-01-25 Thread Sebastian Pop
Keep unchanged the implementation for isl-0.14.

* graphite-poly.c (apply_poly_transforms): Simplify.
(print_isl_set): Use more readable format: ISL_YAML_STYLE_BLOCK.
(print_isl_map): Same.
(print_isl_union_map): Same.
(print_isl_schedule): New.
(debug_isl_schedule): New.
* graphite-dependences.c (scop_get_reads): Do not call
isl_union_map_add_map that is undocumented isl functionality.
(scop_get_must_writes): Same.
(scop_get_may_writes): Same.
(scop_get_original_schedule): Remove.
(scop_get_dependences): Do not call isl_union_map_compute_flow that
is deprecated in isl 0.15.  Instead, use isl_union_access_* interface.
(compute_deps): Remove.
* graphite-isl-ast-to-gimple.c (print_schedule_ast): New.
(debug_schedule_ast): New.
(translate_isl_ast_to_gimple::scop_to_isl_ast): Call 
set_separate_option.
(graphite_regenerate_ast_isl): Add dump.
(translate_isl_ast_to_gimple::scop_to_isl_ast): Generate code
from scop->transformed_schedule.
(graphite_regenerate_ast_isl): Add more dump.
* graphite-optimize-isl.c (optimize_isl): Set
scop->transformed_schedule.  Check whether schedules are equal.
(apply_poly_transforms): Move here.
* graphite-poly.c (apply_poly_transforms): ... from here.
(free_poly_bb): Static.
(free_scop): Static.
(pbb_number_of_iterations_at_time): Remove.
(print_isl_ast): New.
(debug_isl_ast): New.
(debug_scop_pbb): New.
* graphite-scop-detection.c (print_edge): Move.
(print_sese): Move.
* graphite-sese-to-poly.c (build_pbb_scattering_polyhedrons): Remove.
(build_scop_scattering): Remove.
(create_pw_aff_from_tree): Assert instead of bailing out.
(add_condition_to_pbb): Remove unused code, do not fail.
(add_conditions_to_domain): Same.
(add_conditions_to_constraints): Remove.
(build_scop_context): New.
(add_iter_domain_dimension): New.
(build_iteration_domains): Initialize pbb->iterators.
Call add_conditions_to_domain.
(nested_in): New.
(loop_at): New.
(index_outermost_in_loop): New.
(index_pbb_in_loop): New.
(outermost_pbb_in): New.
(add_in_sequence): New.
(add_outer_projection): New.
(outer_projection_mupa): New.
(add_loop_schedule): New.
(build_schedule_pbb): New.
(build_schedule_loop): New.
(embed_in_surrounding_loops): New.
(build_schedule_loop_nest): New.
(build_original_schedule): New.
(build_poly_scop): Call build_original_schedule.
* graphite.h: Declare print_isl_schedule and debug_isl_schedule.
(free_poly_dr): Remove.
(struct poly_bb): Add iterators.  Remove schedule, transformed, saved.
(free_poly_bb): Remove.
(debug_loop_vec): Remove.
(print_isl_ast): Declare.
(debug_isl_ast): Declare.
(scop_do_interchange): Remove.
(scop_do_strip_mine): Remove.
(scop_do_block): Remove.
(flatten_all_loops): Remove.
(optimize_isl): Remove.
(pbb_number_of_iterations_at_time): Remove.
(debug_scop_pbb): Declare.
(print_schedule_ast): Declare.
(debug_schedule_ast): Declare.
(struct scop): Remove schedule.  Add original_schedule,
transformed_schedule.
(free_gimple_poly_bb): Remove.
(print_generated_program): Remove.
(debug_generated_program): Remove.
(unify_scattering_dimensions): Remove.
* sese.c (print_edge): ... here.
(print_sese): ... here.
(debug_edge): ... here.
(debug_sese): ... here.
* sese.h (print_edge): Declare.
(print_sese): Declare.
(dump_edge): Declare.
(dump_sese): Declare.
---
 gcc/graphite-dependences.c | 123 ++-
 gcc/graphite-isl-ast-to-gimple.c   | 203 +++-
 gcc/graphite-optimize-isl.c| 177 +++---
 gcc/graphite-poly.c| 154 +
 gcc/graphite-scop-detection.c  |  15 -
 gcc/graphite-sese-to-poly.c| 365 ++---
 gcc/graphite.h |  48 +--
 gcc/sese.c |  34 ++
 gcc/sese.h |   7 +-
 gcc/testsuite/gcc.dg/graphite/pr35356-1.c  |   2 +-
 .../gfortran.dg/graphite/interchange-3.f90 |   2 +-
 11 files changed, 836 insertions(+), 294 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index 0544700..f9d5bc3 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -66,7 +66,7 @@ add_pdr_constraints (poly_dr_p pdr, poly_bb_p pbb)
 /* Returns all the memory reads in 

Re: [PATCH, PR69110] Don't return NULL access_fns in dr_analyze_indices

2016-01-23 Thread Sebastian Pop
On Sat, Jan 23, 2016 at 12:28 PM, Tom de Vries  wrote:
> That was my original patch, and Richard commented: 'I think avoiding a NULL
> access_fns is ok but it should be done unconditionally, not only for the
> DECL_P case'. In order words, he asked me to do the exact opposite of the
> change you now propose.
>

In the case of a DECL_P it is correct to say that it has an access
function of 0.
In the graphite testcase it is not correct to say that the access
function for a given data reference is zero:
we only initialize access_fns in the case of a polynomial chrec:

  if (TREE_CODE (ref) == MEM_REF)
{
  op = TREE_OPERAND (ref, 0);
  access_fn = analyze_scalar_evolution (loop, op);
  access_fn = instantiate_scev (before_loop, loop, access_fn);
  if (TREE_CODE (access_fn) == POLYNOMIAL_CHREC)
{
[...]
   access_fns.safe_push (access_fn);
}
}

In all other cases we may not have a representation of the access functions.
It is incorrect to initialize to "A[0]" all those data references that
cannot be analyzed.
If needed, instead of returning vNULL, one could initialize the vector to empty:

if (access_fns == vNULL)
  access_fns.create (0);

and that would be correct, though it would not teach the dependence analysis
how to deal with the global variable access function in pr69110.
I think the fix is to add the zero subscript only for DECL_P (ref).

Sebastian


Re: [PATCH, PR68976] Use reaching def phi arg in sese_add_exit_phis_edge

2016-01-15 Thread Sebastian Pop
On Fri, Jan 15, 2016 at 7:58 AM, Tom de Vries  wrote:
> During scop detection/canonicalize_loop_closed_ssa_form, an exit phi is
> introduced in the loop for _24:
> ...
>   :
>   # _58 = PHI <_24(22)>
> ...
> Note that _24 is not defined in the loop, but before it. AFAIU the header
> comment of canonicalize_loop_closed_ssa_form, this phi is not needed. That
> might be the root cause of the bug,

I think that may be the problem, as it is invariant in the loops, so
it is considered to be a parameter of the scop.
Let me see if we could avoid adding that phi node in the first place.


[PATCH 13/15] reinstantiate loop blocking

2016-01-15 Thread Sebastian Pop
* graphite-optimize-isl.c (get_schedule_for_node_st): Add back.
(optimize_isl): Call isl_schedule_map_schedule_node_bottom_up.
* params.def (PARAM_LOOP_BLOCK_TILE_SIZE): Adjust to 32.

gcc/testsuite

* gcc.dg/graphite/block-1.c:
* gcc.dg/graphite/block-5.c:
* gcc.dg/graphite/block-6.c:
* gcc.dg/graphite/block-pr47654.c:
* gcc.dg/graphite/interchange-0.c:
* gcc.dg/graphite/interchange-12.c:
* gcc.dg/graphite/interchange-14.c:
* gcc.dg/graphite/interchange-15.c:
* gcc.dg/graphite/interchange-5.c:
* gcc.dg/graphite/interchange-6.c:
* gcc.dg/graphite/interchange-8.c:
* gcc.dg/graphite/interchange-mvt.c:
* gcc.dg/graphite/uns-block-1.c:
* gcc.dg/graphite/uns-interchange-12.c:
* gcc.dg/graphite/uns-interchange-14.c:
* gcc.dg/graphite/uns-interchange-15.c:
* gcc.dg/graphite/uns-interchange-mvt.c:
* gfortran.dg/graphite/pr14741.f90:
---
 gcc/graphite-optimize-isl.c| 54 ++
 gcc/params.def |  2 +-
 gcc/testsuite/gcc.dg/graphite/block-1.c|  2 +-
 gcc/testsuite/gcc.dg/graphite/block-5.c|  2 +-
 gcc/testsuite/gcc.dg/graphite/block-6.c|  3 +-
 gcc/testsuite/gcc.dg/graphite/block-pr47654.c  |  2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-0.c  |  2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-12.c |  3 +-
 gcc/testsuite/gcc.dg/graphite/interchange-14.c |  3 +-
 gcc/testsuite/gcc.dg/graphite/interchange-15.c |  2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-5.c  |  2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-6.c  |  2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-8.c  |  3 +-
 gcc/testsuite/gcc.dg/graphite/interchange-mvt.c|  2 +-
 gcc/testsuite/gcc.dg/graphite/uns-block-1.c|  2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c |  3 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c |  3 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c |  2 +-
 .../gcc.dg/graphite/uns-interchange-mvt.c  |  2 +-
 gcc/testsuite/gfortran.dg/graphite/pr14741.f90 |  2 +-
 20 files changed, 74 insertions(+), 24 deletions(-)

diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index f385c77..28dc6d4 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -39,6 +39,56 @@ along with GCC; see the file COPYING3.  If not see
 #include "dumpfile.h"
 #include "graphite.h"
 
+/* get_schedule_for_node_st - Improve schedule for the schedule node.
+   Only Simple loop tiling is considered.  */
+
+static __isl_give isl_schedule_node *
+get_schedule_for_node_st (__isl_take isl_schedule_node *node, void *user)
+{
+  if (user)
+return node;
+
+  if (isl_schedule_node_get_type (node) != isl_schedule_node_band
+  || isl_schedule_node_n_children (node) != 1)
+return node;
+
+  isl_space *space = isl_schedule_node_band_get_space (node);
+  unsigned dims = isl_space_dim (space, isl_dim_set);
+  isl_schedule_node *child = isl_schedule_node_get_child (node, 0);
+  isl_schedule_node_type type = isl_schedule_node_get_type (child);
+  isl_space_free (space);
+  isl_schedule_node_free (child);
+
+  if (type != isl_schedule_node_leaf)
+return node;
+
+  if (dims <= 1 || !isl_schedule_node_band_get_permutable (node))
+{
+  if (dump_file && dump_flags)
+   fprintf (dump_file, "not tiled\n");
+  return node;
+}
+
+  /* Tile loops.  */
+  space = isl_schedule_node_band_get_space (node);
+  isl_multi_val *sizes = isl_multi_val_zero (space);
+  long tile_size = PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE);
+  isl_ctx *ctx = isl_schedule_node_get_ctx (node);
+
+  for (unsigned i = 0; i < dims; i++)
+{
+  sizes = isl_multi_val_set_val (sizes, i,
+isl_val_int_from_si (ctx, tile_size));
+  if (dump_file && dump_flags)
+   fprintf (dump_file, "tiled by %ld\n", tile_size);
+}
+
+  node = isl_schedule_node_band_tile (node, sizes);
+  node = isl_schedule_node_child (node, 0);
+
+  return node;
+}
+
 static isl_union_set *
 scop_get_domains (scop_p scop)
 {
@@ -83,6 +133,7 @@ optimize_isl (scop_p scop)
   sc = isl_schedule_constraints_set_validity (sc, isl_union_map_copy 
(validity));
   sc = isl_schedule_constraints_set_coincidence (sc, validity);
 
+  isl_options_set_tile_scale_tile_loops (scop->isl_context, 32);
   isl_options_set_schedule_serialize_sccs (scop->isl_context, 0);
   isl_options_set_schedule_maximize_band_depth (scop->isl_context, 1);
   isl_options_set_schedule_max_constant_term (scop->isl_context, 20);
@@ -95,6 +146,9 @@ optimize_isl (scop_p scop)
   isl_options_set_ast_build_atomic_upper_bound (scop->isl_context, 1);
 
   scop->transformed_schedule = isl_schedule_constraints_compute_schedule (sc);
+  scop->transformed_schedule =
+isl_schedule_map_schedule_node_bottom_up 

[PATCH 08/15] record loops in execution order

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-scop-detection.c (record_loop_in_sese): New.
(gather_bbs::before_dom_children): Call record_loop_in_sese.
(build_scops): Remove call to build_sese_loop_nests.
* sese.c (sese_record_loop): Remove.
(build_sese_loop_nests): Remove.
(new_sese_info): Remove region->loops.
(free_sese_info): Same.
* sese.h (sese_contains_loop): Same.
(build_sese_loop_nests): Remove.
(sese_contains_loop): Remove.
---
 gcc/graphite-scop-detection.c | 29 ---
 gcc/sese.c| 54 ---
 gcc/sese.h| 10 
 3 files changed, 26 insertions(+), 67 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index e004185..be33be3 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -1874,15 +1874,40 @@ gather_bbs::gather_bbs (cdi_direction direction, scop_p 
scop)
 {
 }
 
+/* Record in execution order the loops fully contained in the region.  */
+
+static void
+record_loop_in_sese (basic_block bb, sese_info_p region)
+{
+  loop_p father = bb->loop_father;
+  if (loop_in_sese_p (father, region->region))
+{
+  bool found = false;
+  loop_p loop0;
+  int j;
+  FOR_EACH_VEC_ELT (region->loop_nest, j, loop0)
+   if (father == loop0)
+ {
+   found = true;
+   break;
+ }
+  if (!found)
+   region->loop_nest.safe_push (father);
+}
+}
+
 /* Call-back for dom_walk executed before visiting the dominated
blocks.  */
 
 edge
 gather_bbs::before_dom_children (basic_block bb)
 {
-  if (!bb_in_sese_p (bb, scop->scop_info->region))
+  sese_info_p region = scop->scop_info;
+  if (!bb_in_sese_p (bb, region->region))
 return NULL;
 
+  record_loop_in_sese (bb, region);
+  
   gcond *stmt = single_pred_cond_non_loop_exit (bb);
 
   if (stmt)
@@ -1991,8 +2016,6 @@ build_scops (vec *scops)
  continue;
}
 
-  build_sese_loop_nests (scop->scop_info);
-
   find_scop_parameters (scop);
   graphite_dim_t max_dim = PARAM_VALUE (PARAM_GRAPHITE_MAX_NB_SCOP_PARAMS);
 
diff --git a/gcc/sese.c b/gcc/sese.c
index b0f54de..2ecff7d 100644
--- a/gcc/sese.c
+++ b/gcc/sese.c
@@ -43,56 +43,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "sese.h"
 #include "tree-ssa-propagate.h"
 
-/* Record LOOP as occurring in REGION.  */
-
-static void
-sese_record_loop (sese_info_p region, loop_p loop)
-{
-  if (sese_contains_loop (region, loop))
-return;
-
-  bitmap_set_bit (region->loops, loop->num);
-  region->loop_nest.safe_push (loop);
-}
-
-/* Build the loop nests contained in REGION.  Returns true when the
-   operation was successful.  */
-
-void
-build_sese_loop_nests (sese_info_p region)
-{
-  unsigned i;
-  basic_block bb;
-  struct loop *loop0, *loop1;
-
-  FOR_EACH_BB_FN (bb, cfun)
-if (bb_in_sese_p (bb, region->region))
-  {
-   struct loop *loop = bb->loop_father;
-
-   /* Only add loops if they are completely contained in the SCoP.  */
-   if (loop->header == bb
-   && bb_in_sese_p (loop->latch, region->region))
- sese_record_loop (region, loop);
-  }
-
-  /* Make sure that the loops in the SESE_LOOP_NEST are ordered.  It
- can be the case that an inner loop is inserted before an outer
- loop.  To avoid this, semi-sort once.  */
-  FOR_EACH_VEC_ELT (region->loop_nest, i, loop0)
-{
-  if (region->loop_nest.length () == i + 1)
-   break;
-
-  loop1 = region->loop_nest[i + 1];
-  if (loop0->num > loop1->num)
-   {
- region->loop_nest[i] = loop1;
- region->loop_nest[i + 1] = loop0;
-   }
-}
-}
-
 /* For a USE in BB, if BB is outside REGION, mark the USE in the
LIVEOUTS set.  */
 
@@ -228,7 +178,6 @@ new_sese_info (edge entry, edge exit)
 
   region->region.entry = entry;
   region->region.exit = exit;
-  region->loops = BITMAP_ALLOC (NULL);
   region->loop_nest.create (3);
   region->params.create (3);
   region->rename_map = new rename_map_t;
@@ -244,9 +193,6 @@ new_sese_info (edge entry, edge exit)
 void
 free_sese_info (sese_info_p region)
 {
-  if (region->loops)
-region->loops = BITMAP_ALLOC (NULL);
-
   region->params.release ();
   region->loop_nest.release ();
 
diff --git a/gcc/sese.h b/gcc/sese.h
index 99df354..f481524 100644
--- a/gcc/sese.h
+++ b/gcc/sese.h
@@ -86,7 +86,6 @@ typedef struct sese_info_t
   rename_map_t *rename_map;
 
   /* Loops completely contained in this SESE.  */
-  bitmap loops;
   vec loop_nest;
 
   /* Basic blocks contained in this SESE.  */
@@ -107,20 +106,11 @@ typedef struct sese_info_t
 extern sese_info_p new_sese_info (edge, edge);
 extern void free_sese_info (sese_info_p);
 extern voi

[PATCH 04/15] add missing ast node for isl 0.15

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-isl-ast-to-gimple.c (translate_isl_ast): Also handle
isl_ast_node_mark.
---
 gcc/graphite-isl-ast-to-gimple.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index d143ef7..dad802f 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -1242,6 +1242,13 @@ translate_isl_ast_to_gimple::translate_isl_ast (loop_p 
context_loop,
 case isl_ast_node_block:
   return translate_isl_ast_node_block (context_loop, node,
   next_e, ip);
+case isl_ast_node_mark:
+  {
+   isl_ast_node *n = isl_ast_node_mark_get_node (node);
+   edge e = translate_isl_ast (context_loop, n, next_e, ip);
+   isl_ast_node_free (n);
+   return e;
+  }
 
 default:
   gcc_unreachable ();
-- 
2.5.0



[PATCH 07/15] check that all loops are valid in the combined region

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

the bug was exposed by rewriting an if condition into an assert in the 
computation
of the loop iteration domains.

* graphite-scop-detection.c (loop_is_valid_scop): Renamed 
loop_is_valid_in_scop.
(scop_detection::harmful_stmt_in_region): Renamed 
harmful_loop_in_region.
Call loop_is_valid_in_scop.
---
 gcc/graphite-scop-detection.c | 56 ---
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index ad11227..e004185 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -554,7 +554,7 @@ public:
  region of code that can be represented in the polyhedral model.  SCOP
  defines the region we analyse.  */
 
-  bool loop_is_valid_scop (loop_p loop, sese_l scop) const;
+  bool loop_is_valid_in_scop (loop_p loop, sese_l scop) const;
 
   /* Return true when BEGIN is the preheader edge of a loop with a single exit
  END.  */
@@ -597,7 +597,7 @@ public:
  Limit the number of bbs between adjacent loops to
  PARAM_SCOP_MAX_NUM_BBS_BETWEEN_LOOPS.  */
 
-  bool harmful_stmt_in_region (sese_l scop) const;
+  bool harmful_loop_in_region (sese_l scop) const;
 
   /* Return true only when STMT is simple enough for being handled by Graphite.
  This depends on SCOP, as the parameters are initialized relatively to
@@ -777,8 +777,9 @@ scop_detection::merge_sese (sese_l first, sese_l second) 
const
   if (!second)
 return first;
 
-  DEBUG_PRINT (dp << "[try-merging-sese] s1: "; print_sese (dump_file, first);
-  dp << "[try-merging-sese] s2: ";
+  DEBUG_PRINT (dp << "[scop-detection] try merging sese s1: ";
+  print_sese (dump_file, first);
+  dp << "[scop-detection] try merging sese s2: ";
   print_sese (dump_file, second));
 
   /* Assumption: Both the sese's should be at the same loop depth or one scop
@@ -807,7 +808,7 @@ scop_detection::merge_sese (sese_l first, sese_l second) 
const
 
   sese_l combined (entry, exit);
 
-  DEBUG_PRINT (dp << "checking combined sese: ";
+  DEBUG_PRINT (dp << "[scop-detection] checking combined sese: ";
   print_sese (dump_file, combined));
 
   /* FIXME: We could iterate to find the dom which dominates pdom, and pdom
@@ -849,7 +850,7 @@ scop_detection::merge_sese (sese_l first, sese_l second) 
const
 }
 
   /* Analyze all the BBs in new sese.  */
-  if (harmful_stmt_in_region (combined))
+  if (harmful_loop_in_region (combined))
 return invalid_sese;
 
   DEBUG_PRINT (dp << "[merged-sese] s1: "; print_sese (dump_file, combined));
@@ -877,7 +878,7 @@ scop_detection::build_scop_depth (sese_l s, loop_p loop)
   return s;
 }
 
-  if (!loop_is_valid_scop (loop, s2))
+  if (!loop_is_valid_in_scop (loop, s2))
 return build_scop_depth (invalid_sese, loop->next);
 
   return build_scop_breadth (s2, loop);
@@ -954,7 +955,7 @@ scop_detection::can_represent_loop (loop_p loop, sese_l 
scop)
defines the region we analyse.  */
 
 bool
-scop_detection::loop_is_valid_scop (loop_p loop, sese_l scop) const
+scop_detection::loop_is_valid_in_scop (loop_p loop, sese_l scop) const
 {
   if (!scop)
 return false;
@@ -1008,7 +1009,7 @@ scop_detection::add_scop (sese_l s)
   /* Do not add scops with only one loop.  */
   if (region_has_one_loop (s))
 {
-  DEBUG_PRINT (dp << "[scop-detection-fail] Discarding one loop SCoP.\n";
+  DEBUG_PRINT (dp << "[scop-detection-fail] Discarding one loop SCoP: ";
   print_sese (dump_file, s));
   return;
 }
@@ -1016,7 +1017,7 @@ scop_detection::add_scop (sese_l s)
   if (get_exit_bb (s) == EXIT_BLOCK_PTR_FOR_FN (cfun))
 {
   DEBUG_PRINT (dp << "[scop-detection-fail] "
- << "Discarding SCoP exiting to return.";
+ << "Discarding SCoP exiting to return: ";
   print_sese (dump_file, s));
   return;
 }
@@ -1029,7 +1030,7 @@ scop_detection::add_scop (sese_l s)
   remove_intersecting_scops (s);
 
   scops.safe_push (s);
-  DEBUG_PRINT (dp << "Adding SCoP "; print_sese (dump_file, s));
+  DEBUG_PRINT (dp << "[scop-detection] Adding SCoP: "; print_sese (dump_file, 
s));
 }
 
 /* Return true when a statement in SCOP cannot be represented by Graphite.
@@ -1038,7 +1039,7 @@ scop_detection::add_scop (sese_l s)
PARAM_SCOP_MAX_NUM_BBS_BETWEEN_LOOPS.  */
 
 bool
-scop_detection::harmful_stmt_in_region (sese_l scop) const
+scop_detection::harmful_loop_in_region (sese_l scop) const
 {
   basic_block exit_bb = get_exit_bb (scop);
   basic_block entry_bb = get_entry_bb (scop);
@@ -1056,6 +1057,7 @@ scop_detection::harmful_stmt_in_region (

[PATCH 03/15] fix PR68343: disable graphite tests for isl 0.14 or earlier

2016-01-15 Thread Sebastian Pop
From: Aditya Kumar 

The patch disables all optimizations when configuring gcc with isl 0.14 or 
earlier.
The next patch makes use of the schedule-trees that is only availaible in isl 
0.15.

ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl: Export ISLVER.
* configure: Regenerate.
* config/isl.m4: Detect isl-0.15.

gcc/

* Makefile.in: Set ISLVER in site.exp.
* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Define HAVE_isl for isl-0.15.
* graphite-isl-ast-to-gimple.c: Remove #ifdefs related to isl-0.15.
* graphite-optimize-isl.c: Same.
* graphite.c: Same.
* graphite.h: Same.
* toplev.c: Same.

gcc/testsuite/

* g++.dg/graphite/graphite.exp: Only run the tests with isl-0.15.
* gcc.dg/graphite/graphite.exp: Same.
* gfortran.dg/graphite/graphite.exp: Same.

libgomp/

* config/isl.m4: New file.
* configure: Regenerate.
* configure.ac: Detect isl-0.15.
* testsuite/Makefile.am: Set ISLVER in libgomp-test-support.exp.
* testsuite/Makefile.in: Regenerate.
* testsuite/libgomp.graphite/graphite.exp: Only run the tests with
isl-0.15.
---
 Makefile.in |   2 +
 Makefile.tpl|   2 +
 config/isl.m4   |  12 ++
 configure   |  29 
 gcc/Makefile.in |   1 +
 gcc/config.in   |   6 -
 gcc/configure   |  43 +
 gcc/configure.ac|  26 +--
 gcc/graphite-isl-ast-to-gimple.c|  18 --
 gcc/graphite-optimize-isl.c | 208 
 gcc/graphite.c  |  12 +-
 gcc/graphite.h  |   9 -
 gcc/testsuite/g++.dg/graphite/graphite.exp  |   5 +
 gcc/testsuite/gcc.dg/graphite/graphite.exp  |   5 +
 gcc/testsuite/gfortran.dg/graphite/graphite.exp |   5 +
 gcc/toplev.c|   6 +-
 libgomp/config/isl.m4   | 158 ++
 libgomp/configure   | 201 ++-
 libgomp/configure.ac|  24 +++
 libgomp/testsuite/Makefile.am   |   2 +
 libgomp/testsuite/Makefile.in   |   3 +
 libgomp/testsuite/libgomp.graphite/graphite.exp |   5 +
 22 files changed, 468 insertions(+), 314 deletions(-)
 create mode 100644 libgomp/config/isl.m4

diff --git a/Makefile.in b/Makefile.in
index e9b5950..d2c5b9f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -222,6 +222,7 @@ HOST_EXPORTS = \
GMPINC="$(HOST_GMPINC)"; export GMPINC; \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
+   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
XGCC_FLAGS_FOR_TARGET; \
@@ -315,6 +316,7 @@ HOST_GMPINC = @gmpinc@
 # Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
+HOST_ISLVER = @islver@
 
 # Where to find libelf
 HOST_LIBELFLIBS = @libelflibs@
diff --git a/Makefile.tpl b/Makefile.tpl
index f7bb77e..88c2810 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -225,6 +225,7 @@ HOST_EXPORTS = \
GMPINC="$(HOST_GMPINC)"; export GMPINC; \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
+   ISLVER="$(HOST_ISLVER)"; export ISLVER; \
LIBELFLIBS="$(HOST_LIBELFLIBS)"; export LIBELFLIBS; \
LIBELFINC="$(HOST_LIBELFINC)"; export LIBELFINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
XGCC_FLAGS_FOR_TARGET; \
@@ -318,6 +319,7 @@ HOST_GMPINC = @gmpinc@
 # Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
+HOST_ISLVER = @islver@
 
 # Where to find libelf
 HOST_LIBELFLIBS = @libelflibs@
diff --git a/config/isl.m4 b/config/isl.m4
index 86ccb94..2cfeb46 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -117,6 +117,18 @@ AC_DEFUN([ISL_CHECK_VERSION],
   AC_MSG_RESULT([recommended isl version is 0.15, minimum required isl 
version 0.14 is deprecated])
 fi
 
+AC_MSG_CHECKING([Checking for isl-0.15])
+AC_TRY_LINK([#include ],
+[isl_options_set_schedule_serialize_sccs (NULL, 0);],
+[ac_has_isl_options_set_schedule_serialize_sccs=yes],
+[ac_has_isl_options_set_schedule_serialize_sccs=no])
+AC_MSG_RESULT($ac_has_isl_options_set_schedule_serialize_sccs)
+
+if test x"$ac_has_isl_options_set_schedule_serialize_sccs" = x"yes"; then
+  islver="0.15"
+  AC_SUBST([islver])
+fi
+
 

[PATCH 11/15] check for unstructured control flow

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-scop-detection.c (scop_detection::harmful_loop_in_region):
Discard unstructured if-then-else regions.
---
 gcc/graphite-scop-detection.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index a0c630b..f035e0d 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -1078,6 +1078,18 @@ scop_detection::harmful_loop_in_region (sese_l scop) 
const
  return true;
}
 
+  /* Check for unstructured control flow: CFG not generated by structured
+if-then-else.  */
+  if (bb->succs->length () > 1)
+   {
+ edge e;
+ edge_iterator ei;
+ FOR_EACH_EDGE (e, ei, bb->succs)
+   if (!dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest)
+   && !dominated_by_p (CDI_DOMINATORS, e->dest, bb))
+ return true;
+   }
+
   /* Collect all loops in the current region.  */
   loop_p loop = bb->loop_father;
   if (loop_in_sese_p (loop, scop))
-- 
2.5.0



[PATCH 06/15] fix codegen error exposed by compute isl flow patch

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

we used to fail using an iv from a different loop.

* graphite-isl-ast-to-gimple.c (enum phi_node_kind): New.
(class translate_isl_ast_to_gimple): Use phi_node_kind instead of bool.
(is_valid_rename): Same.
(translate_isl_ast_to_gimple::get_rename): Same.
(translate_isl_ast_to_gimple::rename_all_uses): Same.
(translate_isl_ast_to_gimple::rename_uses): Same.
(get_new_name): Check for close_phi nodes.
(copy_loop_phi_args): Use phi_node_kind.
(translate_isl_ast_to_gimple::copy_loop_close_phi_args): Same.
(translate_isl_ast_to_gimple::copy_cond_phi_args): Same.

gcc/testsuite

* gfortran.dg/graphite/interchange-3.f90: Adjust pattern.
---
 gcc/graphite-isl-ast-to-gimple.c   | 48 ++
 .../gfortran.dg/graphite/interchange-3.f90 |  2 +-
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index b0da425..a196419 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -135,6 +135,14 @@ set_separate_option (__isl_take isl_schedule_node *node, 
void *user)
   return node;
 }
 
+enum phi_node_kind
+{
+  unknown_phi,
+  loop_phi,
+  close_phi,
+  cond_phi
+};
+
 class translate_isl_ast_to_gimple
 {
  public:
@@ -317,14 +325,14 @@ class translate_isl_ast_to_gimple
  SSA form.  */
 
   bool is_valid_rename (tree rename, basic_block def_bb, basic_block use_bb,
-   bool loop_phi, tree old_name, basic_block old_bb) const;
+   phi_node_kind, tree old_name, basic_block old_bb) const;
 
   /* Returns the expression associated to OLD_NAME (which is used in OLD_BB), 
in
  NEW_BB from RENAME_MAP.  LOOP_PHI is true when we want to rename OLD_NAME
  within a loop PHI instruction.  */
 
   tree get_rename (basic_block new_bb, tree old_name,
-  basic_block old_bb, bool loop_phi) const;
+  basic_block old_bb, phi_node_kind) const;
 
   /* For ops which are scev_analyzeable, we can regenerate a new name from
   its scalar evolution around LOOP.  */
@@ -344,7 +352,7 @@ class translate_isl_ast_to_gimple
  true when we want to rename an OP within a loop PHI instruction.  */
 
   tree get_new_name (basic_block new_bb, tree op,
-basic_block old_bb, bool loop_phi) const;
+basic_block old_bb, phi_node_kind) const;
 
   /* Collect all the operands of NEW_EXPR by recursively visiting each
  operand.  */
@@ -1349,7 +1357,7 @@ phi_uses_name (basic_block bb, tree name)
 bool
 translate_isl_ast_to_gimple::
 is_valid_rename (tree rename, basic_block def_bb, basic_block use_bb,
-bool loop_phi, tree old_name, basic_block old_bb) const
+phi_node_kind phi_kind, tree old_name, basic_block old_bb) 
const
 {
   /* The def of the rename must either dominate the uses or come from a
  back-edge.  Also the def must respect the loop closed ssa form.  */
@@ -1367,7 +1375,7 @@ is_valid_rename (tree rename, basic_block def_bb, 
basic_block use_bb,
   if (dominated_by_p (CDI_DOMINATORS, use_bb, def_bb))
 return true;
 
-  if (bb_contains_loop_phi_nodes (use_bb) && loop_phi)
+  if (bb_contains_loop_phi_nodes (use_bb) && phi_kind == loop_phi)
 {
   /* The loop-header dominates the loop-body.  */
   if (!dominated_by_p (CDI_DOMINATORS, def_bb, use_bb))
@@ -1386,14 +1394,13 @@ is_valid_rename (tree rename, basic_block def_bb, 
basic_block use_bb,
 }
 
 /* Returns the expression associated to OLD_NAME (which is used in OLD_BB), in
-   NEW_BB from RENAME_MAP.  LOOP_PHI is true when we want to rename OLD_NAME
-   within a loop PHI instruction.  */
+   NEW_BB from RENAME_MAP.  PHI_KIND determines the kind of phi node.  */
 
 tree
 translate_isl_ast_to_gimple::get_rename (basic_block new_bb,
 tree old_name,
 basic_block old_bb,
-bool loop_phi) const
+phi_node_kind phi_kind) const
 {
   gcc_assert (TREE_CODE (old_name) == SSA_NAME);
   vec  *renames = region->rename_map->get (old_name);
@@ -1407,7 +1414,9 @@ translate_isl_ast_to_gimple::get_rename (basic_block 
new_bb,
   if (TREE_CODE (rename) == SSA_NAME)
{
  basic_block bb = gimple_bb (SSA_NAME_DEF_STMT (rename));
- if (is_valid_rename (rename, bb, new_bb, loop_phi, old_name, old_bb))
+ if (is_valid_rename (rename, bb, new_bb, phi_kind, old_name, old_bb)
+ && (phi_kind == close_phi
+ || flow_bb_inside_loop_p (bb->loop_father, new_bb)))
return rename;
  return NULL_TREE;
}
@@ -1435,6 +1444,9 @@ translate_isl_ast_to_gimple::get_rename (basic_block 
new_bb,
   if (!domina

[PATCH 02/15] remove unused variable

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

2015-12-30  Sebastian Pop  <seb...@gmail.com>

* graphite-poly.c (new_poly_bb): Remove use of PBB_IS_REDUCTION.
* graphite.h (struct poly_bb): Remove field is_reduction.
(PBB_IS_REDUCTION): Remove.
---
 gcc/graphite-poly.c | 1 -
 gcc/graphite.h  | 4 
 2 files changed, 5 deletions(-)

diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index d188341..428c427 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -164,7 +164,6 @@ new_poly_bb (scop_p scop, gimple_poly_bb_p black_box)
   PBB_SCOP (pbb) = scop;
   pbb_set_black_box (pbb, black_box);
   PBB_DRS (pbb).create (3);
-  PBB_IS_REDUCTION (pbb) = false;
   GBB_PBB ((gimple_poly_bb_p) black_box) = pbb;
 
   return pbb;
diff --git a/gcc/graphite.h b/gcc/graphite.h
index 83f8191..f9af292 100644
--- a/gcc/graphite.h
+++ b/gcc/graphite.h
@@ -281,9 +281,6 @@ struct poly_bb
   /* A copy of the transformed scattering.  */
   isl_map *saved;
 
-  /* True when this PBB contains only a reduction statement.  */
-  bool is_reduction;
-
   /* The last basic block generated for this pbb.  */
   basic_block new_bb;
 };
@@ -291,7 +288,6 @@ struct poly_bb
 #define PBB_BLACK_BOX(PBB) ((gimple_poly_bb_p) PBB->black_box)
 #define PBB_SCOP(PBB) (PBB->scop)
 #define PBB_DRS(PBB) (PBB->drs)
-#define PBB_IS_REDUCTION(PBB) (PBB->is_reduction)
 
 extern poly_bb_p new_poly_bb (scop_p, gimple_poly_bb_p);
 extern void free_poly_bb (poly_bb_p);
-- 
2.5.0



[PATCH 12/15] new scop schedule.

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-dependences.c (scop_get_reads): Do not call
isl_union_map_add_map that is undocumented isl functionality.
(scop_get_must_writes): Same.
(scop_get_may_writes): Same.
(scop_get_original_schedule): Remove.
(scop_get_dependences): Do not call isl_union_map_compute_flow that
is deprecated in isl 0.15.  Instead, use isl_union_access_* interface.
(compute_deps): Remove.
* graphite-isl-ast-to-gimple.c (print_schedule_ast): New.
(debug_schedule_ast): New.
(translate_isl_ast_to_gimple::print_isl_ast_node): Removed.
(translate_isl_ast_to_gimple::get_max_schedule_dimensions): Remove.
(translate_isl_ast_to_gimple::extend_schedule): Remove.
(translate_isl_ast_to_gimple::generate_isl_schedule): Remove.
(translate_isl_ast_to_gimple::set_options): Remove.
(translate_isl_ast_to_gimple::scop_to_isl_ast): Generate code
from scop->transformed_schedule.
(graphite_regenerate_ast_isl): Add more dump.
* graphite-optimize-isl.c (optimize_isl): Set
scop->transformed_schedule.  Check whether schedules are equal.
(apply_poly_transforms): Move here.
* graphite-poly.c (apply_poly_transforms): ... from here.
(free_poly_bb): Static.
(free_scop): Static.
(pbb_number_of_iterations_at_time): Remove.
(print_isl_ast): New.
(debug_isl_ast): New.
(debug_scop_pbb): New.
* graphite-scop-detection.c (print_edge): Move.
(print_sese): Move.
* graphite-sese-to-poly.c (build_pbb_scattering_polyhedrons): Remove.
(build_scop_scattering): Remove.
(create_pw_aff_from_tree): Assert instead of bailing out.
(add_condition_to_pbb): Remove unused code, do not fail.
(add_conditions_to_domain): Same.
(add_conditions_to_constraints): Remove.
(build_scop_context): New.
(add_iter_domain_dimension): New.
(build_iteration_domains): Initialize pbb->iterators.
Call add_conditions_to_domain.
(nested_in): New.
(loop_at): New.
(index_outermost_in_loop): New.
(index_pbb_in_loop): New.
(outermost_pbb_in): New.
(add_in_sequence): New.
(add_outer_projection): New.
(outer_projection_mupa): New.
(add_loop_schedule): New.
(build_schedule_pbb): New.
(build_schedule_loop): New.
(embed_in_surrounding_loops): New.
(build_schedule_loop_nest): New.
(build_original_schedule): New.
(build_poly_scop): Call build_original_schedule.
* graphite.h (free_poly_dr): Remove.
(struct poly_bb): Add iterators.  Remove schedule, transformed, saved.
(free_poly_bb): Remove.
(debug_loop_vec): Remove.
(print_isl_ast): Declare.
(debug_isl_ast): Declare.
(scop_do_interchange): Remove.
(scop_do_strip_mine): Remove.
(scop_do_block): Remove.
(flatten_all_loops): Remove.
(optimize_isl): Remove.
(pbb_number_of_iterations_at_time): Remove.
(debug_scop_pbb): Declare.
(print_schedule_ast): Declare.
(debug_schedule_ast): Declare.
(struct scop): Remove schedule.  Add original_schedule,
transformed_schedule.
(free_gimple_poly_bb): Remove.
(print_generated_program): Remove.
(debug_generated_program): Remove.
(unify_scattering_dimensions): Remove.
* sese.c (print_edge): ... here.
(print_sese): ... here.
(debug_edge): ... here.
(debug_sese): ... here.
* sese.h (print_edge): Declare.
(print_sese): Declare.
(dump_edge): Declare.
(dump_sese): Declare.

gcc/testsuite

* gcc.dg/graphite/block-0.c: Adjust pattern.
* gcc.dg/graphite/block-1.c: Same.
* gcc.dg/graphite/block-5.c: Same.
* gcc.dg/graphite/block-6.c: Same.
* gcc.dg/graphite/block-pr47654.c: Same.
* gcc.dg/graphite/interchange-0.c: Same.
* gcc.dg/graphite/interchange-10.c: Same.
* gcc.dg/graphite/interchange-12.c: Same.
* gcc.dg/graphite/interchange-14.c: Same.
* gcc.dg/graphite/interchange-15.c: Same.
* gcc.dg/graphite/interchange-5.c: Same.
* gcc.dg/graphite/interchange-6.c: Same.
* gcc.dg/graphite/interchange-8.c: Same.
* gcc.dg/graphite/interchange-mvt.c: Same.
* gcc.dg/graphite/pr35356-1.c: Same.
* gcc.dg/graphite/scop-10.c (int toto): Same.
* gcc.dg/graphite/uns-block-1.c: Same.
* gcc.dg/graphite/uns-interchange-12.c: Same.
* gcc.dg/graphite/uns-interchange-14.c: Same.
* gcc.dg/graphite/uns-interchange-15.c: Same.
* gcc.dg/graphite/uns-interchange-mvt.c: Same.
* gfortran.dg/graphite/interchange-3.f90: Same.
* gfortran.dg/graphite/pr14741.f90: Same.
--

[PATCH 05/15] remove tiling

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

We remove all code related to tiling, then we will call isl functionality for 
that.

* graphite-isl-ast-to-gimple.c (set_options_for_schedule_tree): Remove.
(translate_isl_ast_to_gimple::scop_to_isl_ast): Call 
set_separate_option.
(graphite_regenerate_ast_isl): Add dump.
* graphite-optimize-isl.c (get_schedule_for_node_st): Remove.
(get_schedule_map_st): Remove.
(get_single_map): Remove.
(apply_schedule_map_to_scop): Remove.
(optimize_isl): Do not use isl_union_maps to build the schedule.
* graphite-poly.c (apply_poly_transforms): Simplify.
(print_isl_set): Use more readable format: ISL_YAML_STYLE_BLOCK.
(print_isl_map): Same.
(print_isl_union_map): Same.
(print_isl_schedule): New.
(debug_isl_schedule): New.
* graphite.h: Declare print_isl_schedule and debug_isl_schedule.

gcc/testsuite

* gcc.dg/graphite/block-0.c: Adjust patern.
* gcc.dg/graphite/block-1.c: Same.
* gcc.dg/graphite/block-5.c: Same.
* gcc.dg/graphite/block-6.c: Same.
* gcc.dg/graphite/block-pr47654.c: Same.
* gcc.dg/graphite/interchange-0.c: Same.
* gcc.dg/graphite/interchange-1.c: Same.
* gcc.dg/graphite/interchange-10.c: Same.
* gcc.dg/graphite/interchange-11.c: Same.
* gcc.dg/graphite/interchange-12.c: Same.
* gcc.dg/graphite/interchange-13.c: Same.
* gcc.dg/graphite/interchange-14.c: Same.
* gcc.dg/graphite/interchange-15.c: Same.
* gcc.dg/graphite/interchange-16.c: Same.
* gcc.dg/graphite/interchange-2.c: Same.
* gcc.dg/graphite/interchange-3.c: Same.
* gcc.dg/graphite/interchange-4.c: Same.
* gcc.dg/graphite/interchange-5.c: Same.
* gcc.dg/graphite/interchange-6.c: Same.
* gcc.dg/graphite/interchange-7.c: Same.
* gcc.dg/graphite/interchange-8.c: Same.
* gcc.dg/graphite/interchange-9.c: Same.
* gcc.dg/graphite/interchange-mvt.c: Same.
* gcc.dg/graphite/uns-block-1.c: Same.
* gcc.dg/graphite/uns-interchange-12.c: Same.
* gcc.dg/graphite/uns-interchange-14.c: Same.
* gcc.dg/graphite/uns-interchange-15.c: Same.
* gcc.dg/graphite/uns-interchange-9.c: Same.
* gcc.dg/graphite/uns-interchange-mvt.c: Same.
* gfortran.dg/graphite/interchange-3.f90: Same.
* gfortran.dg/graphite/pr14741.f90: Same.
---
 gcc/graphite-isl-ast-to-gimple.c   |  47 +++-
 gcc/graphite-optimize-isl.c| 130 +++--
 gcc/graphite-poly.c|  36 --
 gcc/graphite.h |   2 +
 gcc/testsuite/gcc.dg/graphite/block-0.c|   2 +-
 gcc/testsuite/gcc.dg/graphite/block-1.c|   2 +-
 gcc/testsuite/gcc.dg/graphite/block-5.c|   3 +-
 gcc/testsuite/gcc.dg/graphite/block-6.c|   3 +-
 gcc/testsuite/gcc.dg/graphite/block-pr47654.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-0.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-1.c  |   7 +-
 gcc/testsuite/gcc.dg/graphite/interchange-10.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-11.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-12.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-13.c |   1 +
 gcc/testsuite/gcc.dg/graphite/interchange-14.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-15.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-16.c |   1 +
 gcc/testsuite/gcc.dg/graphite/interchange-2.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-3.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-4.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-5.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-6.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-7.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-8.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-9.c  |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-mvt.c|   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-block-1.c|   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-12.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-15.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c  |   2 +-
 .../gcc.dg/graphite/uns-interchange-mvt.c  |   2 +-
 .../gfortran.dg/graphite/interchange-3.f90 |   2 +-
 gcc/testsuite/gfortran.dg/graphite/pr14741.f90 |   2 +-
 35 files changed, 97 insertions(+), 185 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index dad802f..b0da425 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -300,12 +300,6 @@ class translate_isl_ast_to_gimple
 
   __is

[PATCH 10/15] rewrite computation of iteration domains

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-sese-to-poly.c (set_scop_parameter_dim): Remove.
(cleanup_loop_iter_dom): Remove.
(build_loop_iteration_domains): Remove.
(build_scop_context): Remove.
(build_scop_iteration_domain): Remove.
(add_loop_constraints): New.
(build_iteration_domains): New.
(build_poly_scop): Call build_iteration_domains.
---
 gcc/graphite-sese-to-poly.c | 407 +---
 1 file changed, 192 insertions(+), 215 deletions(-)

diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 78dc2fb..abf18a7 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -431,159 +431,6 @@ extract_affine (scop_p s, tree e, __isl_take isl_space 
*space)
   return res;
 }
 
-/* Assign dimension for each parameter in SCOP.  */
-
-static void
-set_scop_parameter_dim (scop_p scop)
-{
-  sese_info_p region = scop->scop_info;
-  unsigned nbp = sese_nb_params (region);
-  isl_space *space = isl_space_set_alloc (scop->isl_context, nbp, 0);
-
-  unsigned i;
-  tree e;
-  FOR_EACH_VEC_ELT (region->params, i, e)
-space = isl_space_set_dim_id (space, isl_dim_param, i,
-  isl_id_for_ssa_name (scop, e));
-
-  scop->param_context = isl_set_universe (space);
-}
-
-static inline bool
-cleanup_loop_iter_dom (isl_set *inner, isl_set *outer, isl_space *space, mpz_t 
g)
-{
-  isl_set_free (inner);
-  isl_set_free (outer);
-  isl_space_free (space);
-  mpz_clear (g);
-  return false;
-}
-
-/* Builds the constraint polyhedra for LOOP in SCOP.  OUTER_PH gives
-   the constraints for the surrounding loops.  */
-
-static bool
-build_loop_iteration_domains (scop_p scop, struct loop *loop,
-  int nb,
- isl_set *outer, isl_set **doms)
-{
-
-  tree nb_iters = number_of_latch_executions (loop);
-  const sese_l& region = scop->scop_info->region;
-  gcc_assert (loop_in_sese_p (loop, region));
-
-  isl_set *inner = isl_set_copy (outer);
-  int pos = isl_set_dim (outer, isl_dim_set);
-  isl_val *v;
-  mpz_t g;
-
-  mpz_init (g);
-
-  inner = isl_set_add_dims (inner, isl_dim_set, 1);
-  isl_space *space = isl_set_get_space (inner);
-
-  /* 0 <= loop_i */
-  isl_constraint *c = isl_inequality_alloc
-  (isl_local_space_from_space (isl_space_copy (space)));
-  c = isl_constraint_set_coefficient_si (c, isl_dim_set, pos, 1);
-  inner = isl_set_coalesce (isl_set_add_constraint (inner, c));
-
-  /* loop_i <= cst_nb_iters */
-  if (TREE_CODE (nb_iters) == INTEGER_CST)
-{
-  c = isl_inequality_alloc
- (isl_local_space_from_space (isl_space_copy (space)));
-  c = isl_constraint_set_coefficient_si (c, isl_dim_set, pos, -1);
-  tree_int_to_gmp (nb_iters, g);
-  v = isl_val_int_from_gmp (scop->isl_context, g);
-  c = isl_constraint_set_constant_val (c, v);
-  inner = isl_set_add_constraint (inner, c);
-}
-
-  /* loop_i <= expr_nb_iters */
-  else if (!chrec_contains_undetermined (nb_iters))
-{
-  isl_pw_aff *aff;
-
-  nb_iters = scalar_evolution_in_region (region, loop, nb_iters);
-
-  /* Bail out as we do not know the scev.  */
-  if (chrec_contains_undetermined (nb_iters))
-   return cleanup_loop_iter_dom (inner, outer, space, g);
-
-  aff = extract_affine (scop, nb_iters, isl_set_get_space (inner));
-  isl_set *valid = isl_pw_aff_nonneg_set (isl_pw_aff_copy (aff));
-  valid = isl_set_project_out (valid, isl_dim_set, 0,
-  isl_set_dim (valid, isl_dim_set));
-
-  if (valid)
-   scop->param_context = isl_set_coalesce
- (isl_set_intersect (scop->param_context, valid));
-
-  isl_local_space *ls = isl_local_space_from_space (isl_space_copy 
(space));
-  isl_aff *al = isl_aff_set_coefficient_si (isl_aff_zero_on_domain (ls),
-   isl_dim_in, pos, 1);
-  isl_set *le = isl_pw_aff_le_set (isl_pw_aff_from_aff (al),
-  isl_pw_aff_copy (aff));
-  inner = isl_set_intersect (inner, le);
-
-  widest_int nit;
-  if (max_stmt_executions (loop, ))
-   {
- /* Insert in the context the constraints from the
-estimation of the number of iterations NIT and the
-symbolic number of iterations (involving parameter
-names) NB_ITERS.  First, build the affine expression
-"NIT - NB_ITERS" and then say that it is positive,
-i.e., NIT approximates NB_ITERS: "NIT >= NB_ITERS".  */
- mpz_t g;
- mpz_init (g);
- wi::to_mpz (nit, g, SIGNED);
- mpz_sub_ui (g, g, 1);
-
- isl_pw_aff *approx
-   = extract_affine_gmp (g, isl_set_get_space (inner));
- isl_set *x = isl_pw_aff_ge_set (approx, aff);
- x = isl_set_project_out 

[PATCH 01/15] add more coalescing to simplify constraints

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

2015-12-30  Aditya Kumar  <aditya...@samsung.com>
    Sebastian Pop  <s@samsung.com>

* graphite-dependences.c (constrain_domain): Add call to isl_*_coalesce.
(add_pdr_constraints): Same.
(scop_get_reads): Same.
(scop_get_must_writes): Same.
(scop_get_may_writes): Same.
(scop_get_original_schedule): Same.
(extend_schedule): Same.
(apply_schedule_on_deps): Same.
(carries_deps): Same.
(compute_deps): Same.
(scop_get_dependences): Same.
* graphite-isl-ast-to-gimple.c
(translate_isl_ast_to_gimple::generate_isl_schedule): Same.
* graphite-optimize-isl.c (get_schedule_for_band): Same.
(get_schedule_for_band_list): Same.
(get_schedule_map): Same.
(apply_schedule_map_to_scop): Same.
* graphite-sese-to-poly.c (build_pbb_scattering_polyhedrons): Same.
(build_loop_iteration_domains): Same.
(add_condition_to_pbb): Same.
(add_param_constraints): Same.
(pdr_add_memory_accesses): Same.
(pdr_add_data_dimensions): Same.
---
 gcc/graphite-dependences.c   | 63 ++--
 gcc/graphite-isl-ast-to-gimple.c |  2 ++
 gcc/graphite-optimize-isl.c  | 12 
 gcc/graphite-sese-to-poly.c  | 28 --
 4 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index 46869d7..ae08059 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -49,7 +49,7 @@ constrain_domain (isl_map *map, isl_set *s)
 
   s = isl_set_set_tuple_id (s, id);
   isl_space_free (d);
-  return isl_map_intersect_domain (map, s);
+  return isl_map_coalesce (isl_map_intersect_domain (map, s));
 }
 
 /* Constrain pdr->accesses with pdr->subscript_sizes and pbb->domain.  */
@@ -59,8 +59,8 @@ add_pdr_constraints (poly_dr_p pdr, poly_bb_p pbb)
 {
   isl_map *x = isl_map_intersect_range (isl_map_copy (pdr->accesses),
isl_set_copy (pdr->subscript_sizes));
-  x = constrain_domain (x, isl_set_copy (pbb->domain));
-  return x;
+  x = isl_map_coalesce (x);
+  return constrain_domain (x, isl_set_copy (pbb->domain));
 }
 
 /* Returns all the memory reads in SCOP.  */
@@ -93,7 +93,7 @@ scop_get_reads (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the memory must writes in SCOP.  */
@@ -126,7 +126,7 @@ scop_get_must_writes (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the memory may writes in SCOP.  */
@@ -159,7 +159,7 @@ scop_get_may_writes (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the original schedules in SCOP.  */
@@ -179,7 +179,7 @@ scop_get_original_schedule (scop_p scop, vec 
pbbs)
isl_set_copy (pbb->domain)));
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Helper function used on each MAP of a isl_union_map.  Computes the
@@ -242,7 +242,7 @@ extend_schedule (__isl_take isl_union_map *x)
   str.umap = isl_union_map_empty (isl_union_map_get_space (x));
   isl_union_map_foreach_map (x, extend_schedule_1, (void *) );
   isl_union_map_free (x);
-  return str.umap;
+  return isl_union_map_coalesce (str.umap);
 }
 
 /* Applies SCHEDULE to the in and out dimensions of the dependences
@@ -252,22 +252,17 @@ static isl_map *
 apply_schedule_on_deps (__isl_keep isl_union_map *schedule,
__isl_keep isl_union_map *deps)
 {
-  isl_map *x;
-  isl_union_map *ux, *trans;
-
-  trans = isl_union_map_copy (schedule);
-  trans = extend_schedule (trans);
-  ux = isl_union_map_copy (deps);
+  isl_union_map *trans = extend_schedule (isl_union_map_copy (schedule));
+  isl_union_map *ux = isl_union_map_copy (deps);
   ux = isl_union_map_apply_domain (ux, isl_union_map_copy (trans));
   ux = isl_union_map_apply_range (ux, trans);
-  if (isl_union_map_is_empty (ux))
-{
-  isl_union_map_free (ux);
-  return NULL;
-}
-  x = isl_map_from_union_map (ux);
+  ux = isl_union_map_coalesce (ux);
+
+  if (!isl_union_map_is_empty (ux))
+return isl_map_from_union_map (ux);
 
-  return x;
+  isl_union_map_free (ux);
+  return NULL;
 }
 
 /* Return true when DEPS is non empty and the intersection of LEX with
@@ -280,25 +275,19 @@ carries_deps (__isl_keep isl_union_map *schedule,
  __isl_keep isl_union_map *deps,
  int depth)
 {
-  bool res;
-  int i;
-  isl_space *space;
-  isl_map *lex, *x;
-  isl_constraint *ineq;
-
   if (isl_union_map_is_empty (deps))
 return false;
 
-  x = apply_schedule_on_deps (schedule, deps);
+  isl_map *x = apply_schedule_on_deps (schedule, deps);
   if (x == NULL)
 ret

[PATCH 09/15] fix memory leak in scop-detection

2016-01-15 Thread Sebastian Pop
From: Sebastian Pop <s@samsung.com>

* graphite-scop-detection.c
(scop_detection::harmful_loop_in_region): Free dom and loops.
(scop_detection::loop_body_is_valid_scop): Free bbs.
---
 gcc/graphite-scop-detection.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index be33be3..a0c630b 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -1088,7 +1088,11 @@ scop_detection::harmful_loop_in_region (sese_l scop) 
const
 any loop fully contained in the scop: other bbs are checked below
 in loop_is_valid_in_scop.  */
  if (harmful_stmt_in_bb (scop, bb))
-   return true;
+   {
+ dom.release ();
+ BITMAP_FREE (loops);
+ return true;
+   }
}
 
 }
@@ -1104,13 +1108,14 @@ scop_detection::harmful_loop_in_region (sese_l scop) 
const
 
   if (!loop_is_valid_in_scop (loop, scop))
{
+ dom.release ();
  BITMAP_FREE (loops);
  return true;
}
 }
 
-  BITMAP_FREE (loops);
   dom.release ();
+  BITMAP_FREE (loops);
   return false;
 }
 
@@ -1503,7 +1508,10 @@ scop_detection::loop_body_is_valid_scop (loop_p loop, 
sese_l scop) const
   basic_block bb = bbs[i];
 
   if (harmful_stmt_in_bb (scop, bb))
-   return false;
+   {
+ free (bbs);
+ return false;
+   }
 }
   free (bbs);
 
-- 
2.5.0



[PATCH] [graphite] fix PR68976: only add loop close phi for names defined in loop

2016-01-15 Thread Sebastian Pop
* graphite-isl-ast-to-gimple.c: Fix comment.
* graphite-scop-detection.c (defined_in_loop_p): New.
(canonicalize_loop_closed_ssa): Do not add close phi nodes for SSA
names defined in loop.

gcc/testsuite

* gcc.dg/graphite/pr68976.c: New test.
---
 gcc/graphite-isl-ast-to-gimple.c|  4 ++--
 gcc/graphite-scop-detection.c   | 13 -
 gcc/testsuite/gcc.dg/graphite/pr68976.c | 11 +++
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/graphite/pr68976.c

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index df52c49..9509af4 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -492,8 +492,8 @@ private:
 /* Return the tree variable that corresponds to the given isl ast identifier
expression (an isl_ast_expr of type isl_ast_expr_id).
 
-   FIXME: We should replace blind conversation of id's type with derivation
-   of the optimal type when we get the corresponding isl support. Blindly
+   FIXME: We should replace blind conversion of id's type with derivation
+   of the optimal type when we get the corresponding isl support.  Blindly
converting type sizes may be problematic when we switch to smaller
types.  */
 
diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 8dfb20a..6ddf7bb 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -336,6 +336,15 @@ make_close_phi_nodes_unique (basic_block bb)
 }
 }
 
+/* Return true when NAME is defined in LOOP.  */
+
+static bool
+defined_in_loop_p (tree name, loop_p loop)
+{
+  gcc_assert (TREE_CODE (name) == SSA_NAME);
+  return loop == loop_containing_stmt (SSA_NAME_DEF_STMT (name));
+}
+
 /* Transforms LOOP to the canonical loop closed SSA form.  */
 
 static void
@@ -376,7 +385,9 @@ canonicalize_loop_closed_ssa (loop_p loop)
use_operand_p use_p;
gphi *close_phi;
 
-   if (TREE_CODE (arg) != SSA_NAME)
+   /* Only add close phi nodes for SSA_NAMEs defined in LOOP.  */
+   if (TREE_CODE (arg) != SSA_NAME
+   || !defined_in_loop_p (arg, loop))
  continue;
 
close_phi = create_phi_node (NULL_TREE, close);
diff --git a/gcc/testsuite/gcc.dg/graphite/pr68976.c 
b/gcc/testsuite/gcc.dg/graphite/pr68976.c
new file mode 100644
index 000..ae9bf0f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr68976.c
@@ -0,0 +1,11 @@
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+int kw = -1, hv = -1, ju;
+int mc[1];
+void xx(void)
+{
+  for (; kw; ++kw)
+for (; hv; ++hv)
+  for (ju = 0; ju < 2; ++ju)
+mc[kw+1] = mc[0];
+}
-- 
2.5.0



Re: [PATCH, PR68976] Use reaching def phi arg in sese_add_exit_phis_edge

2016-01-15 Thread Sebastian Pop
On Fri, Jan 15, 2016 at 11:19 AM, Sebastian Pop <seb...@gmail.com> wrote:
> On Fri, Jan 15, 2016 at 7:58 AM, Tom de Vries <tom_devr...@mentor.com> wrote:
>> During scop detection/canonicalize_loop_closed_ssa_form, an exit phi is
>> introduced in the loop for _24:
>> ...
>>   :
>>   # _58 = PHI <_24(22)>
>> ...
>> Note that _24 is not defined in the loop, but before it. AFAIU the header
>> comment of canonicalize_loop_closed_ssa_form, this phi is not needed. That
>> might be the root cause of the bug,
>
> I think that may be the problem, as it is invariant in the loops, so
> it is considered to be a parameter of the scop.
> Let me see if we could avoid adding that phi node in the first place.

I just sent out a patch that implements this.
Thanks Tom for pointing out the issue!


[PATCH] [graphite] fix pr68692: reinstantiate the copy of internal parameters

2016-01-15 Thread Sebastian Pop
Adding a testcase and reverting this patch:
[PATCH] remove parameter_rename_map

This map was used in the transition to the new scop detection: with the new scop
detection, we do not need this map anymore.

   * graphite-isl-ast-to-gimple.c (gcc_expression_from_isl_ast_expr_id):
   Remove use of parameter_rename_map.
   (copy_def): Remove.
   (copy_internal_parameters): Remove.
   (graphite_regenerate_ast_isl): Remove call to copy_internal_parameters.
   * sese.c (new_sese_info): Do not initialize parameter_rename_map.
   (free_sese_info): Do not free parameter_rename_map.
   (set_rename): Do not use parameter_rename_map.
   (rename_uses): Update call to set_rename.
   (graphite_copy_stmts_from_block): Do not use parameter_rename_map.
   * sese.h (parameter_rename_map_t): Remove.
   (struct sese_info_t): Remove field parameter_rename_map.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229783 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/graphite-isl-ast-to-gimple.c   | 107 -
 gcc/sese.c |   4 +
 gcc/sese.h |   4 +
 gcc/testsuite/gfortran.dg/graphite/pr68692.f90 |  64 +++
 4 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/graphite/pr68692.f90

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index d7d0f7a..a8f88ff 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -512,7 +512,11 @@ gcc_expression_from_isl_ast_expr_id (tree type,
  "Could not map isl_id to tree expression");
   isl_ast_expr_free (expr_id);
   tree t = res->second;
-  return fold_convert (type, t);
+  tree *val = region->parameter_rename_map->get(t);
+
+  if (!val)
+   val = 
+  return fold_convert (type, *val);
 }
 
 /* Converts an isl_ast_expr_int expression E to a GCC expression tree of
@@ -1475,6 +1479,13 @@ translate_isl_ast_to_gimple::set_rename (tree old_name, 
tree expr)
   r.safe_push (expr);
   region->rename_map->put (old_name, r);
 }
+
+  tree t;
+  int i;
+  /* For a parameter of a scop we don't want to rename it.  */
+  FOR_EACH_VEC_ELT (region->params, i, t)
+if (old_name == t)
+  region->parameter_rename_map->put(old_name, expr);
 }
 
 /* Return an iterator to the instructions comes last in the execution order.
@@ -2735,6 +2746,14 @@ should_copy_to_new_region (gimple *stmt, sese_info_p 
region)
   && scev_analyzable_p (lhs, region->region))
 return false;
 
+  /* Do not copy parameters that have been generated in the header of the
+ scop.  */
+  if (is_gimple_assign (stmt)
+  && (lhs = gimple_assign_lhs (stmt))
+  && TREE_CODE (lhs) == SSA_NAME
+  && region->parameter_rename_map->get(lhs))
+return false;
+
   return true;
 }
 
@@ -2800,6 +2819,25 @@ 
translate_isl_ast_to_gimple::graphite_copy_stmts_from_block (basic_block bb,
   if (codegen_error_p ())
return false;
 
+  /* For each SSA_NAME in the parameter_rename_map rename their usage.  */
+  ssa_op_iter iter;
+  use_operand_p use_p;
+  if (!is_gimple_debug (copy))
+   FOR_EACH_SSA_USE_OPERAND (use_p, copy, iter, SSA_OP_USE)
+ {
+   tree old_name = USE_FROM_PTR (use_p);
+
+   if (TREE_CODE (old_name) != SSA_NAME
+   || SSA_NAME_IS_DEFAULT_DEF (old_name))
+ continue;
+
+   tree *new_expr = region->parameter_rename_map->get (old_name);
+   if (!new_expr)
+ continue;
+
+   replace_exp (use_p, *new_expr);
+ }
+
   update_stmt (copy);
 }
 
@@ -3111,6 +3149,70 @@ translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p 
scop)
   return ast_isl;
 }
 
+/* Copy def from sese REGION to the newly created TO_REGION. TR is defined by
+   DEF_STMT. GSI points to entry basic block of the TO_REGION.  */
+
+static void
+copy_def (tree tr, gimple *def_stmt, sese_info_p region, sese_info_p to_region,
+ gimple_stmt_iterator *gsi)
+{
+  if (!defined_in_sese_p (tr, region->region))
+return;
+
+  ssa_op_iter iter;
+  use_operand_p use_p;
+  FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_USE)
+{
+  tree use_tr = USE_FROM_PTR (use_p);
+
+  /* Do not copy parameters that have been generated in the header of the
+scop.  */
+  if (region->parameter_rename_map->get(use_tr))
+   continue;
+
+  gimple *def_of_use = SSA_NAME_DEF_STMT (use_tr);
+  if (!def_of_use)
+   continue;
+
+  copy_def (use_tr, def_of_use, region, to_region, gsi);
+}
+
+  gimple *copy = gimple_copy (def_stmt);
+  gsi_insert_after (gsi, copy, GSI_NEW_STMT);
+
+  /* Create new names for all the definitions created by COPY and
+ add replacement mappings for each new name.  */
+  def_operand_p def_p;
+  ssa_op_iter op_iter;
+  FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS)
+{
+  

Re: [PATCH 1/2] [graphite] add more dumps on data dependence graph

2016-01-09 Thread Sebastian Pop
On Sat, Jan 9, 2016 at 7:26 AM, Gerald Pfeifer <ger...@pfeifer.com> wrote:
> Hi Sebastian,
>
> On Fri, 25 Dec 2015, Sebastian Pop wrote:
>>> on December 17th 2015, my nightly bootstrap (on i386-unknown-freebsd10.1,
>>> but I don't think this is material) started to fail as follows:
>>>
>>>   /scratch/tmp/gerald/gcc-HEAD/gcc/graphite-scop-detection.c:1892:17:
>>>   note: in instantiation of member function 'vec<dr_info, va_heap, 
>>> vl_ptr>::safe_push'
>>>   requested here
>>>   scop->drs.safe_push (dr_info (dr, pbb));
>> I do not see what the error is.  Do you happen to have
>> the few lines with the error before this note?
>
> thanks for the quick response.  My Internet (non-)connectivity the
> last two weeks did not allow me to debug this further.  Now I'm back
> to normal, and here is what I found:
>
> When I remove the isl package, GCC bootstraps just fine.  As soon as
> I add the package again, things fail again.
>
> From the configure log:
>
>   checking for isl 0.15 (or deprecated 0.14)... yes
>   checking Checking for isl_options_set_schedule_serialize_sccs... no
>
> And here is the actual failure, which is different from my original
> report (probably due to forcing serial building).  Invocation:
>
>   c++ -std=gnu++98 -fno-PIE -c -g -DIN_GCC -fno-strict-aliasing
>   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall
>   -Wno-narrowing -Wwrite-string s -Wcast-qual -Wno-format
>   -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long
>   -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H
>   :
>   -o graphite-dependences.o -MT graphite-dependences.o -MMD -MP -MF
>   ./.deps/graphite-dependences.TPo 
> /scratch/tmp/gerald/gcc-HEAD/gcc/graphite-dependences.c
>
> Error:
>
>   /scratch/tmp/gerald/gcc-HEAD/gcc/graphite-dependences.c:240:3: error: no 
> matching function for call to 'isl_union_map_foreach_map'
>   isl_union_map_foreach_map (x, max_number_of_out_dimensions, (void *) );
>   ^
>   /home/gerald/10-i386/include/isl/union_map.h:204:10: note: candidate
>   function not viable: no known conversion from 'int (isl_map *, void *)'
>   to 'isl_stat (*)(isl_map *, void *)' for 2nd argument
>   isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap,
>
>
> At first I thought this is related to FreeBSD now using clang as the
> system compiler, but the same happens using a current GCC 6 build.
>
> Then I started digging into this, wondering why apparently it had
> as the return type for the second argument as opposed to "isl_stat".
>
> My .../include/isl/union_map.h has
>
>   isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap,
> isl_stat (*fn)(__isl_take isl_map *map, void *user), void *user);
>
> whereas graphite_dependences.c has
>
>   static isl_stat
>   max_number_of_out_dimensions (__isl_take isl_map *map, void *user)
>
> so everything should be fine, shouldn't it?
>
> Turns out gcc/graphite.h is causing all this:
>
>   #ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
>   /* isl 0.15 or later.  */
>   #include 
>
>   #else
>   /* isl 0.14 or 0.13.  */
>   # define isl_stat int
>   # define isl_stat_ok 0
>   #endif
>
> So, despite actually _having_ type isl_stat we #define isl_stat to int
> and do so after having all the isl/ include files use the proper type.
>
> Digging deeper, there appear to be two issues:
>
>  1. Instead of a feature test (for isl_stat) we use a version check
> based on another feature test (isl_options_set_schedule_serialize_sccs).
>
>  2. That feature test for isl_options_set_schedule_serialize_sccs does
> not work properly.
>
> It would be great could you look into issue 1 in any case, but for the

I will have a look.
In general I do not like the current status of having that many
#ifdefs in graphite: it makes the code hard to read and to maintain.

> time being let's focus on issue 2.  Here is what gcc/config.log shows:
>
>   configure:28943: checking Checking for 
> isl_options_set_schedule_serialize_sccs
>   configure:28956: /home/gerald/gcc-ref10-i386/bin/g++ -std=gnu++98 -o 
> conftest -g
> -static-libstdc++ -static-libgcc  conftest.cpp  -lisl
> -L/home/gerald/10-i386 /lib -lmpc -lmpfr -lgmp >&5
>   conftest.cpp:258:26: fatal error: isl/schedule.h: No such file or directory
>  #include 
>   compilation terminated.
>   configure:28956: $? = 1
>
> Note the -L option pointing to /home/gerald/10-i386 (where I have my
> local packages for this kind of testing), whereas the associated -I
> option is missing.  And indeed, tha

[PATCH 1/4] [graphite] add more coalescing to simplify constraints

2015-12-18 Thread Sebastian Pop
---
 gcc/graphite-dependences.c   | 63 ++--
 gcc/graphite-isl-ast-to-gimple.c |  2 ++
 gcc/graphite-optimize-isl.c  | 12 
 gcc/graphite-sese-to-poly.c  | 28 --
 4 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index 46869d7..ae08059 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -49,7 +49,7 @@ constrain_domain (isl_map *map, isl_set *s)
 
   s = isl_set_set_tuple_id (s, id);
   isl_space_free (d);
-  return isl_map_intersect_domain (map, s);
+  return isl_map_coalesce (isl_map_intersect_domain (map, s));
 }
 
 /* Constrain pdr->accesses with pdr->subscript_sizes and pbb->domain.  */
@@ -59,8 +59,8 @@ add_pdr_constraints (poly_dr_p pdr, poly_bb_p pbb)
 {
   isl_map *x = isl_map_intersect_range (isl_map_copy (pdr->accesses),
isl_set_copy (pdr->subscript_sizes));
-  x = constrain_domain (x, isl_set_copy (pbb->domain));
-  return x;
+  x = isl_map_coalesce (x);
+  return constrain_domain (x, isl_set_copy (pbb->domain));
 }
 
 /* Returns all the memory reads in SCOP.  */
@@ -93,7 +93,7 @@ scop_get_reads (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the memory must writes in SCOP.  */
@@ -126,7 +126,7 @@ scop_get_must_writes (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the memory may writes in SCOP.  */
@@ -159,7 +159,7 @@ scop_get_may_writes (scop_p scop, vec pbbs)
  }
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Returns all the original schedules in SCOP.  */
@@ -179,7 +179,7 @@ scop_get_original_schedule (scop_p scop, vec 
pbbs)
isl_set_copy (pbb->domain)));
 }
 
-  return res;
+  return isl_union_map_coalesce (res);
 }
 
 /* Helper function used on each MAP of a isl_union_map.  Computes the
@@ -242,7 +242,7 @@ extend_schedule (__isl_take isl_union_map *x)
   str.umap = isl_union_map_empty (isl_union_map_get_space (x));
   isl_union_map_foreach_map (x, extend_schedule_1, (void *) );
   isl_union_map_free (x);
-  return str.umap;
+  return isl_union_map_coalesce (str.umap);
 }
 
 /* Applies SCHEDULE to the in and out dimensions of the dependences
@@ -252,22 +252,17 @@ static isl_map *
 apply_schedule_on_deps (__isl_keep isl_union_map *schedule,
__isl_keep isl_union_map *deps)
 {
-  isl_map *x;
-  isl_union_map *ux, *trans;
-
-  trans = isl_union_map_copy (schedule);
-  trans = extend_schedule (trans);
-  ux = isl_union_map_copy (deps);
+  isl_union_map *trans = extend_schedule (isl_union_map_copy (schedule));
+  isl_union_map *ux = isl_union_map_copy (deps);
   ux = isl_union_map_apply_domain (ux, isl_union_map_copy (trans));
   ux = isl_union_map_apply_range (ux, trans);
-  if (isl_union_map_is_empty (ux))
-{
-  isl_union_map_free (ux);
-  return NULL;
-}
-  x = isl_map_from_union_map (ux);
+  ux = isl_union_map_coalesce (ux);
+
+  if (!isl_union_map_is_empty (ux))
+return isl_map_from_union_map (ux);
 
-  return x;
+  isl_union_map_free (ux);
+  return NULL;
 }
 
 /* Return true when DEPS is non empty and the intersection of LEX with
@@ -280,25 +275,19 @@ carries_deps (__isl_keep isl_union_map *schedule,
  __isl_keep isl_union_map *deps,
  int depth)
 {
-  bool res;
-  int i;
-  isl_space *space;
-  isl_map *lex, *x;
-  isl_constraint *ineq;
-
   if (isl_union_map_is_empty (deps))
 return false;
 
-  x = apply_schedule_on_deps (schedule, deps);
+  isl_map *x = apply_schedule_on_deps (schedule, deps);
   if (x == NULL)
 return false;
-  space = isl_map_get_space (x);
-  space = isl_space_range (space);
-  lex = isl_map_lex_le (space);
-  space = isl_map_get_space (x);
-  ineq = isl_inequality_alloc (isl_local_space_from_space (space));
 
-  for (i = 0; i < depth - 1; i++)
+  isl_space *space = isl_map_get_space (x);
+  isl_map *lex = isl_map_lex_le (isl_space_range (space));
+  isl_constraint *ineq = isl_inequality_alloc
+(isl_local_space_from_space (isl_map_get_space (x)));
+
+  for (int i = 0; i < depth - 1; i++)
 lex = isl_map_equate (lex, isl_dim_in, i, isl_dim_out, i);
 
   /* in + 1 <= out  */
@@ -306,8 +295,9 @@ carries_deps (__isl_keep isl_union_map *schedule,
   ineq = isl_constraint_set_coefficient_si (ineq, isl_dim_in, depth - 1, -1);
   ineq = isl_constraint_set_constant_si (ineq, -1);
   lex = isl_map_add_constraint (lex, ineq);
+  lex = isl_map_coalesce (lex);
   x = isl_map_intersect (x, lex);
-  res = !isl_map_is_empty (x);
+  bool res = !isl_map_is_empty (x);
 
   isl_map_free (x);
   return res;
@@ -336,6 +326,8 @@ compute_deps (scop_p scop, vec pbbs,
   isl_union_map *may_writes = scop_get_may_writes (scop, pbbs);
   isl_union_map *all_writes = isl_union_map_union
 

[PATCH 3/4] [graphite] add tiling on schedule trees

2015-12-18 Thread Sebastian Pop
---
 gcc/graphite-optimize-isl.c | 96 -
 gcc/graphite-poly.c | 19 +
 gcc/graphite.h  |  2 +
 gcc/params.def  |  2 +-
 4 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index 7c3bfcf..9d185c6 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -48,6 +48,71 @@ optimize_isl (scop_p scop ATTRIBUTE_UNUSED)
 }
 #else
 
+static isl_schedule_node *
+tile_node (__isl_take isl_schedule_node *node)
+{
+  isl_ctx *ctx = isl_schedule_node_get_ctx (node);
+  isl_space *space = isl_schedule_node_band_get_space (node);
+  unsigned dims = isl_space_dim (space, isl_dim_set);
+  isl_multi_val *sizes = isl_multi_val_zero (space);
+
+  for (unsigned i = 0; i < dims; i++)
+{
+  isl_val *tile_size = isl_val_int_from_si
+   (ctx, PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE));
+  sizes = isl_multi_val_set_val (sizes, i, tile_size);
+}
+
+  isl_id *id1 = isl_id_alloc (ctx, "tile", NULL);
+  node = isl_schedule_node_insert_mark
+(node, id1);
+  node = isl_schedule_node_child (node, 0);
+  node = isl_schedule_node_band_tile (node, sizes);
+  node = isl_schedule_node_child (node, 0);
+  isl_id *id2 = isl_id_alloc (ctx, "point", NULL);
+  node = isl_schedule_node_insert_mark
+(node, id2);
+
+  return isl_schedule_node_child (node, 0);
+}
+
+static bool is_tileable_node (__isl_keep isl_schedule_node *node)
+{
+  if (isl_schedule_node_get_type (node) != isl_schedule_node_band)
+return false;
+
+  if (isl_schedule_node_n_children (node) != 1)
+return false;
+
+  if (!isl_schedule_node_band_get_permutable (node))
+return false;
+
+  isl_space *space = isl_schedule_node_band_get_space (node);
+  unsigned dims = isl_space_dim (space, isl_dim_set);
+  isl_space_free (space);
+
+  if (dims <= 1)
+return false;
+
+  isl_schedule_node *child = isl_schedule_node_get_child (node, 0);
+  enum isl_schedule_node_type type = isl_schedule_node_get_type (child);
+  isl_schedule_node_free (child);
+
+  if (type != isl_schedule_node_leaf)
+return false;
+
+  return true;
+}
+
+static isl_schedule_node *
+optimize_node (__isl_take isl_schedule_node *node, void *user ATTRIBUTE_UNUSED)
+{
+  if (is_tileable_node (node))
+return tile_node (node);
+
+  return node;
+}
+
 static isl_union_set *
 scop_get_domains (scop_p scop)
 {
@@ -62,8 +127,6 @@ scop_get_domains (scop_p scop)
   return res;
 }
 
-static const int CONSTANT_BOUND = 20;
-
 /* Compute the schedule for SCOP based on its parameters, domain and set of
constraints.  Then apply the schedule to SCOP.  */
 
@@ -85,15 +148,13 @@ optimize_isl (scop_p scop)
   isl_union_map *validity = isl_union_map_copy (scop->dependence);
   isl_union_map *proximity = isl_union_map_copy (validity);
 
-  isl_options_set_schedule_max_constant_term (scop->isl_context, 
CONSTANT_BOUND);
-  isl_options_set_schedule_maximize_band_depth (scop->isl_context, 1);
-  isl_options_set_schedule_serialize_sccs (scop->isl_context, 0);
+  isl_options_set_schedule_serialize_sccs (scop->isl_context, 1);
   isl_options_set_schedule_maximize_band_depth (scop->isl_context, 1);
   isl_options_set_schedule_max_constant_term (scop->isl_context, 20);
   isl_options_set_schedule_max_coefficient (scop->isl_context, 20);
   isl_options_set_tile_scale_tile_loops (scop->isl_context, 0);
-  isl_options_set_coalesce_bounded_wrapping (scop->isl_context, 1);
-  isl_options_set_ast_build_exploit_nested_bounds (scop->isl_context, 1);
+  //isl_options_set_coalesce_bounded_wrapping (scop->isl_context, 1);
+  //isl_options_set_ast_build_exploit_nested_bounds (scop->isl_context, 1);
   isl_options_set_ast_build_atomic_upper_bound (scop->isl_context, 1);
 
   /* FIXME: the use of isl_union_set_compute_schedule is discouraged in isl
@@ -114,9 +175,24 @@ optimize_isl (scop_p scop)
   return false;
 }
 
-  /* Attach the schedule to scop so that it can be used in code generation.
- schedule freeing will occur in code generation.  */
-  scop->schedule = schedule;
+  if (dump_file)
+{
+  fprintf (dump_file, "schedule before tiling:\n");
+  print_isl_schedule (dump_file, schedule);
+}
+
+  isl_schedule_node *root = isl_schedule_get_root (schedule);
+  root = isl_schedule_node_map_descendant_bottom_up (root, optimize_node, 
NULL);
+  scop->schedule = isl_schedule_node_get_schedule (root);
+
+  if (dump_file)
+{
+  fprintf (dump_file, "schedule after tiling:\n");
+  print_isl_schedule (dump_file, scop->schedule);
+}
+
+  isl_schedule_free (schedule);
+  isl_schedule_node_free (root);
   return true;
 }
 #endif /* HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS */
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index ff451b8..73356f2 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -541,6 +541,7 @@ void
 print_isl_set (FILE *f, isl_set *set)
 {
   isl_printer *p = 

[PATCH 2/4] [graphite] remove isl scheduler optimizations for deprecated isl 0.14

2015-12-18 Thread Sebastian Pop
---
 gcc/graphite-isl-ast-to-gimple.c |  56 +++
 gcc/graphite-optimize-isl.c  | 317 +--
 gcc/graphite-poly.c  |  24 +--
 3 files changed, 40 insertions(+), 357 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index aaca9e9..64183c4 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -303,14 +303,6 @@ class translate_isl_ast_to_gimple
 
   __isl_give isl_union_map *generate_isl_schedule (scop_p scop);
 
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-  /* Set the "separate" option for all schedules.  This helps reducing control
- overhead.  */
-
-  __isl_give isl_schedule *
-set_options_for_schedule_tree (__isl_take isl_schedule *schedule);
-#endif
-
   /* Set the separate option for all dimensions.
  This helps to reduce control overhead.  */
 
@@ -3186,19 +3178,6 @@ ast_build_before_for (__isl_keep isl_ast_build *build, 
void *user)
   return id;
 }
 
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-/* Set the separate option for all schedules.  This helps reducing control
-   overhead.  */
-
-__isl_give isl_schedule *
-translate_isl_ast_to_gimple::set_options_for_schedule_tree
-(__isl_take isl_schedule *schedule)
-{
-  return isl_schedule_map_schedule_node_bottom_up
-(schedule, set_separate_option, NULL);
-}
-#endif
-
 /* Set the separate option for all dimensions.
This helps to reduce control overhead.  */
 
@@ -3223,7 +3202,6 @@ translate_isl_ast_to_gimple::set_options (__isl_take 
isl_ast_build *control,
 __isl_give isl_ast_node *
 translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p scop, ivs_params )
 {
-  isl_ast_node *ast_isl = NULL;
   /* Generate loop upper bounds that consist of the current loop iterator, an
  operator (< or <=) and an expression not involving the iterator.  If this
  option is not set, then the current loop iterator may appear several times
@@ -3231,6 +3209,23 @@ translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p 
scop, ivs_params )
   isl_options_set_ast_build_atomic_upper_bound (scop->isl_context, true);
 
   add_parameters_to_ivs_params (scop, ip);
+
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+  /* isl 0.15 and isl scheduler has a new schedule.  */
+  if (scop->schedule)
+{
+  /* Set the separate option to reduce control flow overhead.  */
+  isl_schedule *schedule = isl_schedule_map_schedule_node_bottom_up
+   (scop->schedule, set_separate_option, NULL);
+  isl_ast_build *context_isl = generate_isl_context (scop);
+  isl_ast_node *ast_isl = isl_ast_build_node_from_schedule
+   (context_isl, schedule);
+  isl_ast_build_free (context_isl);
+  return ast_isl;
+}
+#endif
+
+  /* isl 0.14, graphite-identity, or parallelize.  */
   isl_union_map *schedule_isl = generate_isl_schedule (scop);
   isl_ast_build *context_isl = generate_isl_context (scop);
   context_isl = set_options (context_isl, schedule_isl);
@@ -3241,21 +3236,8 @@ translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p 
scop, ivs_params )
isl_ast_build_set_before_each_for (context_isl, ast_build_before_for,
   dependence);
 }
-
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-  if (scop->schedule)
-{
-  scop->schedule = set_options_for_schedule_tree (scop->schedule);
-  ast_isl = isl_ast_build_node_from_schedule (context_isl, scop->schedule);
-  isl_union_map_free(schedule_isl);
-}
-  else
-ast_isl = isl_ast_build_ast_from_schedule (context_isl, schedule_isl);
-#else
-  ast_isl = isl_ast_build_ast_from_schedule (context_isl, schedule_isl);
-  isl_schedule_free (scop->schedule);
-#endif
-
+  isl_ast_node *ast_isl = isl_ast_build_ast_from_schedule
+(context_isl, schedule_isl);
   isl_ast_build_free (context_isl);
   return ast_isl;
 }
diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index 15dd5b0..7c3bfcf 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -39,303 +39,15 @@ along with GCC; see the file COPYING3.  If not see
 #include "dumpfile.h"
 #include "graphite.h"
 
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-/* isl 0.15 or later.  */
-
-/* get_schedule_for_node_st - Improve schedule for the schedule node.
-   Only Simple loop tiling is considered.  */
-
-static __isl_give isl_schedule_node *
-get_schedule_for_node_st (__isl_take isl_schedule_node *node, void *user)
-{
-  if (user)
-return node;
-
-  if (isl_schedule_node_get_type (node) != isl_schedule_node_band
-  || isl_schedule_node_n_children (node) != 1)
-return node;
-
-  isl_space *space = isl_schedule_node_band_get_space (node);
-  unsigned dims = isl_space_dim (space, isl_dim_set);
-  isl_schedule_node *child = isl_schedule_node_get_child (node, 0);
-  isl_schedule_node_type type = isl_schedule_node_get_type (child);
-  isl_space_free (space);
-  isl_schedule_node_free 

[PATCH 4/4] [graphite] add missing ast node for isl 0.15

2015-12-18 Thread Sebastian Pop
---
 gcc/graphite-isl-ast-to-gimple.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 64183c4..7e00b17 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -1245,6 +1245,15 @@ translate_isl_ast_to_gimple::translate_isl_ast (loop_p 
context_loop,
 case isl_ast_node_block:
   return translate_isl_ast_node_block (context_loop, node,
   next_e, ip);
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+case isl_ast_node_mark:
+  {
+   isl_ast_node *n = isl_ast_node_mark_get_node (node);
+   edge e = translate_isl_ast (context_loop, n, next_e, ip);
+   isl_ast_node_free (n);
+   return e;
+  }
+#endif
 
 default:
   gcc_unreachable ();
-- 
1.9.1



[PATCH] [graphite] replace ISL with isl

2015-12-17 Thread Sebastian Pop
---
 Makefile.in   |  2 +-
 Makefile.tpl  |  2 +-
 config/isl.m4 |  2 +-
 configure | 10 +++---
 configure.ac  | 14 
 contrib/download_prerequisites|  2 +-
 gcc/Makefile.in   |  2 +-
 gcc/common.opt|  2 +-
 gcc/configure |  8 ++---
 gcc/configure.ac  |  8 ++---
 gcc/doc/install.texi  |  8 ++---
 gcc/doc/invoke.texi   |  4 +--
 gcc/graphite-isl-ast-to-gimple.c  | 47 +--
 gcc/graphite-scop-detection.c |  4 +--
 gcc/graphite-sese-to-poly.c   |  6 ++--
 gcc/graphite.c|  4 +--
 gcc/graphite.h|  2 +-
 gcc/params.def|  2 +-
 gcc/testsuite/gcc.dg/graphite/fuse-1.c|  4 +--
 gcc/testsuite/gcc.dg/graphite/fuse-2.c|  4 +--
 gcc/testsuite/gcc.dg/graphite/interchange-1.c |  2 +-
 gcc/testsuite/gcc.dg/graphite/pr35356-1.c |  2 +-
 gcc/toplev.c  |  2 +-
 23 files changed, 69 insertions(+), 74 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index cb62c35..e9b5950 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -312,7 +312,7 @@ NORMAL_TARGET_EXPORTS = \
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
 
-# Where to find ISL
+# Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
 
diff --git a/Makefile.tpl b/Makefile.tpl
index 693e4d5..f7bb77e 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -315,7 +315,7 @@ NORMAL_TARGET_EXPORTS = \
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
 
-# Where to find ISL
+# Where to find isl
 HOST_ISLLIBS = @isllibs@
 HOST_ISLINC = @islinc@
 
diff --git a/config/isl.m4 b/config/isl.m4
index e4e4aab..86ccb94 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -94,7 +94,7 @@ AC_DEFUN([ISL_REQUESTED],
 
 # ISL_CHECK_VERSION ISL_CHECK_VERSION ()
 # 
-# Test that ISL contains functionality added to the minimum expected version.
+# Test whether isl contains functionality added to the minimum expected 
version.
 AC_DEFUN([ISL_CHECK_VERSION],
 [
   if test "${ENABLE_ISL_CHECK}" = yes ; then
diff --git a/configure b/configure
index c3c5cb0..f5786ed 100755
--- a/configure
+++ b/configure
@@ -1549,7 +1549,7 @@ Optional Packages:
   --with-boot-libs=LIBS   libraries for stage2 and later
   --with-boot-ldflags=FLAGS
   linker flags for stage2 and later
-  --with-isl=PATH Specify prefix directory for the installed ISL
+  --with-isl=PATH Specify prefix directory for the installed isl
   package. Equivalent to
   --with-isl-include=PATH/include plus
   --with-isl-lib=PATH/lib
@@ -5943,7 +5943,7 @@ fi
 
 
 
-# GCC GRAPHITE dependency ISL.
+# GCC GRAPHITE dependency isl.
 # Basic setup is inlined here, actual checks are in config/isl.m4
 
 
@@ -5956,7 +5956,7 @@ fi
 # Treat --without-isl as a request to disable
 # GRAPHITE support and skip all following checks.
 if test "x$with_isl" != "xno"; then
-  # Check for ISL
+  # Check for isl
 
 
 # Check whether --with-isl-include was given.
@@ -6079,13 +6079,13 @@ $as_echo "recommended isl version is 0.15, minimum 
required isl version 0.14 is
 && test "x${isllibs}" = x \
 && test "x${islinc}" = x ; then
 
-as_fn_error "Unable to find a usable ISL.  See config.log for details." 
"$LINENO" 5
+as_fn_error "Unable to find a usable isl.  See config.log for details." 
"$LINENO" 5
   fi
 
 
 fi
 
-# If the ISL check failed, disable builds of in-tree variant of ISL
+# If the isl check failed, disable builds of in-tree variant of isl
 if test "x$with_isl" = xno ||
test "x$gcc_cv_isl" = xno; then
   noconfigdirs="$noconfigdirs isl"
diff --git a/configure.ac b/configure.ac
index a6998ff..a719e03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1773,31 +1773,31 @@ AC_ARG_WITH(boot-ldflags,
  fi])
 AC_SUBST(poststage1_ldflags)
 
-# GCC GRAPHITE dependency ISL.
+# GCC GRAPHITE dependency isl.
 # Basic setup is inlined here, actual checks are in config/isl.m4
 
 AC_ARG_WITH(isl,
   [AS_HELP_STRING(
[--with-isl=PATH],
-   [Specify prefix directory for the installed ISL package.
+   [Specify prefix directory for the installed isl package.
 Equivalent to --with-isl-include=PATH/include
 plus --with-isl-lib=PATH/lib])])
 
 # Treat --without-isl as a request to disable
 # GRAPHITE support and skip all following checks.
 if test "x$with_isl" != "xno"; then
-  # Check for ISL
+  # Check for isl
   dnl Provide configure switches and initialize islinc & isllibs
   dnl with user input.
   ISL_INIT_FLAGS
- 

[PATCH] [graphite] update required isl version

2015-12-16 Thread Sebastian Pop
we check for a the isl compute timeout function added in isl 0.13.
That means GCC could still be configured with isl 0.13, 0.14, and 0.15.

* config/isl.m4 (ISL_CHECK_VERSION): Check for
isl_ctx_get_max_operations.
* configure: Regenerate.

gcc/
* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Remove checks for functions that exist in isl 0.13 or
later.
* graphite-isl-ast-to-gimple.c: Remove #ifdefs and code for isl 0.12.
* graphite-optimize-isl.c: Same.
* graphite-poly.c: Same.
* graphite-sese-to-poly.c: Same.
* graphite.h: Add comment for isl 0.14.
* toplev.c (print_version): Print isl version.
---
 config/isl.m4| 29 +++
 configure| 23 +--
 gcc/config.in| 12 
 gcc/configure| 61 ++--
 gcc/configure.ac | 23 ---
 gcc/graphite-isl-ast-to-gimple.c | 10 ++-
 gcc/graphite-optimize-isl.c  | 34 --
 gcc/graphite-poly.c  |  8 --
 gcc/graphite-sese-to-poly.c  |  8 --
 gcc/graphite.h   |  1 +
 gcc/toplev.c | 10 +--
 11 files changed, 49 insertions(+), 170 deletions(-)

diff --git a/config/isl.m4 b/config/isl.m4
index 459fac1..7387ff2 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -19,23 +19,23 @@
 
 # ISL_INIT_FLAGS ()
 # -
-# Provide configure switches for ISL support.
+# Provide configure switches for isl support.
 # Initialize isllibs/islinc according to the user input.
 AC_DEFUN([ISL_INIT_FLAGS],
 [
   AC_ARG_WITH([isl-include],
 [AS_HELP_STRING(
   [--with-isl-include=PATH],
-  [Specify directory for installed ISL include files])])
+  [Specify directory for installed isl include files])])
   AC_ARG_WITH([isl-lib],
 [AS_HELP_STRING(
   [--with-isl-lib=PATH],
-  [Specify the directory for the installed ISL library])])
+  [Specify the directory for the installed isl library])])
 
   AC_ARG_ENABLE(isl-version-check,
 [AS_HELP_STRING(
   [--disable-isl-version-check],
-  [disable check for ISL version])],
+  [disable check for isl version])],
 ENABLE_ISL_CHECK=$enableval,
 ENABLE_ISL_CHECK=yes)
   
@@ -58,15 +58,15 @@ AC_DEFUN([ISL_INIT_FLAGS],
   if test "x${with_isl_lib}" != x; then
 isllibs="-L$with_isl_lib"
   fi
-  dnl If no --with-isl flag was specified and there is in-tree ISL
+  dnl If no --with-isl flag was specified and there is in-tree isl
   dnl source, set up flags to use that and skip any version tests
-  dnl as we cannot run them before building ISL.
+  dnl as we cannot run them before building isl.
   if test "x${islinc}" = x && test "x${isllibs}" = x \
  && test -d ${srcdir}/isl; then
 isllibs='-L$$r/$(HOST_SUBDIR)/isl/'"$lt_cv_objdir"' '
 islinc='-I$$r/$(HOST_SUBDIR)/isl/include -I$$s/isl/include'
 ENABLE_ISL_CHECK=no
-AC_MSG_WARN([using in-tree ISL, disabling version check])
+AC_MSG_WARN([using in-tree isl, disabling version check])
   fi
 
   isllibs="${isllibs} -lisl"
@@ -75,7 +75,7 @@ AC_DEFUN([ISL_INIT_FLAGS],
 
 # ISL_REQUESTED (ACTION-IF-REQUESTED, ACTION-IF-NOT)
 # 
-# Provide actions for failed ISL detection.
+# Provide actions for failed isl detection.
 AC_DEFUN([ISL_REQUESTED],
 [
   AC_REQUIRE([ISL_INIT_FLAGS])
@@ -106,12 +106,17 @@ AC_DEFUN([ISL_CHECK_VERSION],
 LDFLAGS="${_isl_saved_LDFLAGS} ${isllibs}"
 LIBS="${_isl_saved_LIBS} -lisl"
 
-AC_MSG_CHECKING([for compatible ISL])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[;]])],
-   [gcc_cv_isl=yes],
-   [gcc_cv_isl=no])
+AC_MSG_CHECKING([for isl 0.15 (or deprecated 0.14)])
+AC_TRY_LINK([#include ],
+[isl_ctx_get_max_operations (isl_ctx_alloc ());],
+[gcc_cv_isl=yes],
+[gcc_cv_isl=no])
 AC_MSG_RESULT([$gcc_cv_isl])
 
+if test "${gcc_cv_isl}" = no ; then
+  AC_MSG_RESULT([recommended isl version is 0.15, minimum required isl 
version 0.14 is deprecated])
+fi
+
 CFLAGS=$_isl_saved_CFLAGS
 LDFLAGS=$_isl_saved_LDFLAGS
 LIBS=$_isl_saved_LIBS
diff --git a/configure b/configure
index 090615f..a6495c4 100755
--- a/configure
+++ b/configure
@@ -1492,7 +1492,7 @@ Optional Features:
   build static libjava [default=no]
   --enable-bootstrap  enable bootstrapping [yes if native build]
   --disable-isl-version-check
-  disable check for ISL version
+  disable check for isl version
   --enable-ltoenable link time optimization support
   --enable-linker-plugin-configure-flags=FLAGS
   additional flags for configuring linker plugins
@@ -1553,8 +1553,8 @@ Optional Packages:
  

[PATCH] [graphite] move all isl include files to graphite.h

2015-12-16 Thread Sebastian Pop
* graphite-dependences.c: Move all isl include files to...
* graphite-isl-ast-to-gimple.c: Same.
* graphite-optimize-isl.c: Same.
* graphite-poly.c: Same.
* graphite-scop-detection.c: Same.
* graphite.c: Same.
* graphite.h: ... here.
---
 gcc/graphite-dependences.c   |  9 -
 gcc/graphite-isl-ast-to-gimple.c | 12 
 gcc/graphite-optimize-isl.c  | 17 -
 gcc/graphite-poly.c  | 14 --
 gcc/graphite-scop-detection.c|  6 --
 gcc/graphite.c   |  7 ---
 gcc/graphite.h   | 20 ++--
 7 files changed, 18 insertions(+), 67 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index 407a11e..46869d7 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -37,17 +37,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "cfgloop.h"
 #include "tree-data-ref.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include "graphite.h"
 
-
 /* Add the constraints from the set S to the domain of MAP.  */
 
 static isl_map *
diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 66c4c5a..795232a 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -53,18 +53,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "cfganal.h"
 #include "value-prof.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-#include 
-#endif
-
 #include "graphite.h"
 #include 
 
diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index cb45bfe..c546edc 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -37,23 +37,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-data-ref.h"
 #include "params.h"
 #include "dumpfile.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-/* isl 0.15 or later.  */
-#include 
-#include 
-#endif
-
 #include "graphite.h"
 
 #ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index 1f50ff8..d188341 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -40,22 +40,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "pretty-print.h"
 #include "gimple-pretty-print.h"
 #include "tree-dump.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include "graphite.h"
 
-#define OPENSCOP_MAX_STRING 256
-
-
 /* Print to STDERR the GMP value VAL.  */
 
 DEBUG_FUNCTION void
diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 0d5dc2b..dd506b5 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -48,12 +48,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "tree-ssa-propagate.h"
 #include "gimple-pretty-print.h"
-
-#include 
-#include 
-#include 
-#include 
-
 #include "graphite.h"
 
 class debug_printer
diff --git a/gcc/graphite.c b/gcc/graphite.c
index f156c5e..8d0d24c 100644
--- a/gcc/graphite.c
+++ b/gcc/graphite.c
@@ -52,13 +52,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "dbgcnt.h"
 #include "tree-parloops.h"
 #include "tree-cfgcleanup.h"
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
 #include "graphite.h"
 
 /* Print global statistics to FILE.  */
diff --git a/gcc/graphite.h b/gcc/graphite.h
index 01da3db..83f8191 100644
--- a/gcc/graphite.h
+++ b/gcc/graphite.h
@@ -23,10 +23,26 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_GRAPHITE_POLY_H
 
 #include "sese.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 
-#ifndef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
-  /* isl 0.14.  */
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+/* isl 0.15 or later.  */
+#include 
+
+#else
+/* isl 0.14 or 0.13.  */
 # define isl_stat int
 # define isl_stat_ok 0
 #endif
-- 
1.9.1



[PATCH] [graphite] attach schedule tree to the scop

2015-12-16 Thread Sebastian Pop
we used to translate the just computed schedule tree into a union_map,
and then in the code generation it would be translated back to a schedule tree
just before generating AST code.
---
 gcc/graphite-isl-ast-to-gimple.c | 65 ++--
 gcc/graphite-optimize-isl.c  |  5 +++-
 gcc/graphite-poly.c  |  4 +--
 gcc/graphite.h   |  4 +++
 4 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index e2b5a00..66c4c5a 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -61,6 +61,9 @@ along with GCC; see the file COPYING3.  If not see
 #include 
 #include 
 #include 
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+#include 
+#endif
 
 #include "graphite.h"
 #include 
@@ -124,6 +127,29 @@ void ivs_params_clear (ivs_params )
 }
 }
 
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+
+/* Set the "separate" option for the schedule node.  */
+
+static __isl_give isl_schedule_node *
+set_separate_option (__isl_take isl_schedule_node *node, void *user)
+{
+  if (user)
+return node;
+
+  if (isl_schedule_node_get_type (node) != isl_schedule_node_band)
+return node;
+
+  /* Set the "separate" option unless it is set earlier to another option.  */
+  if (isl_schedule_node_band_member_get_ast_loop_type (node, 0)
+  == isl_ast_loop_default)
+return isl_schedule_node_band_member_set_ast_loop_type
+  (node, 0, isl_ast_loop_separate);
+
+  return node;
+}
+#endif
+
 class translate_isl_ast_to_gimple
 {
  public:
@@ -289,6 +315,14 @@ class translate_isl_ast_to_gimple
 
   __isl_give isl_union_map *generate_isl_schedule (scop_p scop);
 
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+  /* Set the "separate" option for all schedules.  This helps reducing control
+ overhead.  */
+
+  __isl_give isl_schedule *
+set_options_for_schedule_tree (__isl_take isl_schedule *schedule);
+#endif
+
   /* Set the separate option for all dimensions.
  This helps to reduce control overhead.  */
 
@@ -3162,6 +3196,19 @@ ast_build_before_for (__isl_keep isl_ast_build *build, 
void *user)
   return id;
 }
 
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+/* Set the separate option for all schedules.  This helps reducing control
+   overhead.  */
+
+__isl_give isl_schedule *
+translate_isl_ast_to_gimple::set_options_for_schedule_tree
+(__isl_take isl_schedule *schedule)
+{
+  return isl_schedule_map_schedule_node_bottom_up
+(schedule, set_separate_option, NULL);
+}
+#endif
+
 /* Set the separate option for all dimensions.
This helps to reduce control overhead.  */
 
@@ -3186,6 +3233,7 @@ translate_isl_ast_to_gimple::set_options (__isl_take 
isl_ast_build *control,
 __isl_give isl_ast_node *
 translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p scop, ivs_params )
 {
+  isl_ast_node *ast_isl = NULL;
   /* Generate loop upper bounds that consist of the current loop iterator, an
  operator (< or <=) and an expression not involving the iterator.  If this
  option is not set, then the current loop iterator may appear several times
@@ -3203,8 +3251,21 @@ translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p 
scop, ivs_params )
isl_ast_build_set_before_each_for (context_isl, ast_build_before_for,
   dependence);
 }
-  isl_ast_node *ast_isl = isl_ast_build_ast_from_schedule (context_isl,
-  schedule_isl);
+
+#ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
+  if (scop->schedule)
+{
+  scop->schedule = set_options_for_schedule_tree (scop->schedule);
+  ast_isl = isl_ast_build_node_from_schedule (context_isl, scop->schedule);
+  isl_union_map_free(schedule_isl);
+}
+  else
+ast_isl = isl_ast_build_ast_from_schedule (context_isl, schedule_isl);
+#else
+  ast_isl = isl_ast_build_ast_from_schedule (context_isl, schedule_isl);
+  isl_schedule_free (scop->schedule);
+#endif
+
   isl_ast_build_free (context_isl);
   return ast_isl;
 }
diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
index f5cb5c4..cb45bfe 100644
--- a/gcc/graphite-optimize-isl.c
+++ b/gcc/graphite-optimize-isl.c
@@ -420,6 +420,10 @@ optimize_isl (scop_p scop)
   return false;
 }
 
+  // Attach the schedule to scop so that it can be used in code generation.
+  // schedule freeing will occur in code generation.
+  scop->schedule = schedule;
+
 #ifdef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
   /* isl 0.15 or later.  */
   isl_union_map *schedule_map = get_schedule_map_st (schedule);
@@ -428,7 +432,6 @@ optimize_isl (scop_p scop)
 #endif
   apply_schedule_map_to_scop (scop, schedule_map);
 
-  isl_schedule_free (schedule);
   isl_union_map_free (schedule_map);
   return true;
 }
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index 00d674c..1f50ff8 100644
--- a/gcc/graphite-poly.c
+++ 

[PATCH 2/2] [graphite] update required isl versions

2015-12-14 Thread Sebastian Pop
we now check the isl version, as there are no real differences in existing files
in between isl 0.14 and isl 0.15.
---
 config/isl.m4| 29 +++
 configure| 23 +--
 gcc/config.in| 12 
 gcc/configure| 61 ++--
 gcc/configure.ac | 23 ---
 gcc/graphite-isl-ast-to-gimple.c | 10 ++-
 gcc/graphite-optimize-isl.c  | 30 ++--
 gcc/graphite-poly.c  |  8 --
 gcc/graphite-sese-to-poly.c  |  8 --
 gcc/graphite.h   |  1 +
 10 files changed, 39 insertions(+), 166 deletions(-)

diff --git a/config/isl.m4 b/config/isl.m4
index 459fac1..7387ff2 100644
--- a/config/isl.m4
+++ b/config/isl.m4
@@ -19,23 +19,23 @@
 
 # ISL_INIT_FLAGS ()
 # -
-# Provide configure switches for ISL support.
+# Provide configure switches for isl support.
 # Initialize isllibs/islinc according to the user input.
 AC_DEFUN([ISL_INIT_FLAGS],
 [
   AC_ARG_WITH([isl-include],
 [AS_HELP_STRING(
   [--with-isl-include=PATH],
-  [Specify directory for installed ISL include files])])
+  [Specify directory for installed isl include files])])
   AC_ARG_WITH([isl-lib],
 [AS_HELP_STRING(
   [--with-isl-lib=PATH],
-  [Specify the directory for the installed ISL library])])
+  [Specify the directory for the installed isl library])])
 
   AC_ARG_ENABLE(isl-version-check,
 [AS_HELP_STRING(
   [--disable-isl-version-check],
-  [disable check for ISL version])],
+  [disable check for isl version])],
 ENABLE_ISL_CHECK=$enableval,
 ENABLE_ISL_CHECK=yes)
   
@@ -58,15 +58,15 @@ AC_DEFUN([ISL_INIT_FLAGS],
   if test "x${with_isl_lib}" != x; then
 isllibs="-L$with_isl_lib"
   fi
-  dnl If no --with-isl flag was specified and there is in-tree ISL
+  dnl If no --with-isl flag was specified and there is in-tree isl
   dnl source, set up flags to use that and skip any version tests
-  dnl as we cannot run them before building ISL.
+  dnl as we cannot run them before building isl.
   if test "x${islinc}" = x && test "x${isllibs}" = x \
  && test -d ${srcdir}/isl; then
 isllibs='-L$$r/$(HOST_SUBDIR)/isl/'"$lt_cv_objdir"' '
 islinc='-I$$r/$(HOST_SUBDIR)/isl/include -I$$s/isl/include'
 ENABLE_ISL_CHECK=no
-AC_MSG_WARN([using in-tree ISL, disabling version check])
+AC_MSG_WARN([using in-tree isl, disabling version check])
   fi
 
   isllibs="${isllibs} -lisl"
@@ -75,7 +75,7 @@ AC_DEFUN([ISL_INIT_FLAGS],
 
 # ISL_REQUESTED (ACTION-IF-REQUESTED, ACTION-IF-NOT)
 # 
-# Provide actions for failed ISL detection.
+# Provide actions for failed isl detection.
 AC_DEFUN([ISL_REQUESTED],
 [
   AC_REQUIRE([ISL_INIT_FLAGS])
@@ -106,12 +106,17 @@ AC_DEFUN([ISL_CHECK_VERSION],
 LDFLAGS="${_isl_saved_LDFLAGS} ${isllibs}"
 LIBS="${_isl_saved_LIBS} -lisl"
 
-AC_MSG_CHECKING([for compatible ISL])
-AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[;]])],
-   [gcc_cv_isl=yes],
-   [gcc_cv_isl=no])
+AC_MSG_CHECKING([for isl 0.15 (or deprecated 0.14)])
+AC_TRY_LINK([#include ],
+[isl_ctx_get_max_operations (isl_ctx_alloc ());],
+[gcc_cv_isl=yes],
+[gcc_cv_isl=no])
 AC_MSG_RESULT([$gcc_cv_isl])
 
+if test "${gcc_cv_isl}" = no ; then
+  AC_MSG_RESULT([recommended isl version is 0.15, minimum required isl 
version 0.14 is deprecated])
+fi
+
 CFLAGS=$_isl_saved_CFLAGS
 LDFLAGS=$_isl_saved_LDFLAGS
 LIBS=$_isl_saved_LIBS
diff --git a/configure b/configure
index 090615f..a6495c4 100755
--- a/configure
+++ b/configure
@@ -1492,7 +1492,7 @@ Optional Features:
   build static libjava [default=no]
   --enable-bootstrap  enable bootstrapping [yes if native build]
   --disable-isl-version-check
-  disable check for ISL version
+  disable check for isl version
   --enable-ltoenable link time optimization support
   --enable-linker-plugin-configure-flags=FLAGS
   additional flags for configuring linker plugins
@@ -1553,8 +1553,8 @@ Optional Packages:
   package. Equivalent to
   --with-isl-include=PATH/include plus
   --with-isl-lib=PATH/lib
-  --with-isl-include=PATH Specify directory for installed ISL include files
-  --with-isl-lib=PATH Specify the directory for the installed ISL library
+  --with-isl-include=PATH Specify directory for installed isl include files
+  --with-isl-lib=PATH Specify the directory for the installed isl library
   --with-build-sysroot=SYSROOT
   use sysroot as the system root during the build
   --with-debug-prefix-map='A=B C=D ...'
@@ -6003,8 +6003,8 @@ fi
 

[PATCH 1/2] [graphite] add more dumps on data dependence graph

2015-12-14 Thread Sebastian Pop
---
 gcc/graphite-dependences.c| 31 +++
 gcc/graphite-poly.c   | 15 ++-
 gcc/graphite-scop-detection.c | 21 -
 3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c
index bb81ae3..7b7912a 100644
--- a/gcc/graphite-dependences.c
+++ b/gcc/graphite-dependences.c
@@ -89,8 +89,16 @@ scop_get_reads (scop_p scop, vec pbbs)
if (pdr_read_p (pdr))
  {
if (dump_file)
- print_pdr (dump_file, pdr);
+ {
+   fprintf (dump_file, "Adding read to depedence graph: ");
+   print_pdr (dump_file, pdr);
+ }
res = isl_union_map_add_map (res, add_pdr_constraints (pdr, pbb));
+   if (dump_file)
+ {
+   fprintf (dump_file, "Reads depedence graph: ");
+   print_isl_union_map (dump_file, res);
+ }
  }
 }
 
@@ -114,8 +122,16 @@ scop_get_must_writes (scop_p scop, vec pbbs)
if (pdr_write_p (pdr))
  {
if (dump_file)
- print_pdr (dump_file, pdr);
+ {
+   fprintf (dump_file, "Adding must write to depedence graph: ");
+   print_pdr (dump_file, pdr);
+ }
res = isl_union_map_add_map (res, add_pdr_constraints (pdr, pbb));
+   if (dump_file)
+ {
+   fprintf (dump_file, "Must writes depedence graph: ");
+   print_isl_union_map (dump_file, res);
+ }
  }
 }
 
@@ -139,9 +155,16 @@ scop_get_may_writes (scop_p scop, vec pbbs)
if (pdr_may_write_p (pdr))
  {
if (dump_file)
- print_pdr (dump_file, pdr);
-
+ {
+   fprintf (dump_file, "Adding may write to depedence graph: ");
+   print_pdr (dump_file, pdr);
+ }
res = isl_union_map_add_map (res, add_pdr_constraints (pdr, pbb));
+   if (dump_file)
+ {
+   fprintf (dump_file, "May writes depedence graph: ");
+   print_isl_union_map (dump_file, res);
+ }
  }
 }
 
diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c
index f4bdd40..6c01a4c 100644
--- a/gcc/graphite-poly.c
+++ b/gcc/graphite-poly.c
@@ -31,13 +31,15 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "gimple.h"
 #include "cfghooks.h"
-#include "gimple-pretty-print.h"
 #include "diagnostic-core.h"
 #include "fold-const.h"
 #include "gimple-iterator.h"
 #include "tree-ssa-loop.h"
 #include "cfgloop.h"
 #include "tree-data-ref.h"
+#include "pretty-print.h"
+#include "gimple-pretty-print.h"
+#include "tree-dump.h"
 
 #include 
 #include 
@@ -147,6 +149,17 @@ new_poly_dr (poly_bb_p pbb, gimple *stmt, enum 
poly_dr_type type,
   pdr->subscript_sizes = subscript_sizes;
   PDR_TYPE (pdr) = type;
   PBB_DRS (pbb).safe_push (pdr);
+
+  if (dump_file)
+{
+  fprintf (dump_file, "Converting dr: ");
+  print_pdr (dump_file, pdr);
+  fprintf (dump_file, "To polyhedral representation:\n");
+  fprintf (dump_file, "  - access functions: ");
+  print_isl_map (dump_file, acc);
+  fprintf (dump_file, "  - subscripts: ");
+  print_isl_set (dump_file, subscript_sizes);
+}
 }
 
 /* Free polyhedral data reference PDR.  */
diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 729a5fd..23562d1 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -1684,9 +1684,9 @@ build_cross_bb_scalars_def (scop_p scop, tree def, 
basic_block def_bb,
 if (def_bb != gimple_bb (use_stmt) && !is_gimple_debug (use_stmt))
   {
writes->safe_push (def);
-   DEBUG_PRINT (dp << "Adding scalar write:\n";
+   DEBUG_PRINT (dp << "Adding scalar write: ";
 print_generic_expr (dump_file, def, 0);
-dp << "From stmt:\n";
+dp << "\nFrom stmt: ";
 print_gimple_stmt (dump_file,
SSA_NAME_DEF_STMT (def), 0, 0));
/* This is required by the FOR_EACH_IMM_USE_STMT when we want to break
@@ -1713,9 +1713,9 @@ build_cross_bb_scalars_use (scop_p scop, tree use, gimple 
*use_stmt,
   gimple *def_stmt = SSA_NAME_DEF_STMT (use);
   if (gimple_bb (def_stmt) != gimple_bb (use_stmt))
 {
-  DEBUG_PRINT (dp << "Adding scalar read:";
+  DEBUG_PRINT (dp << "Adding scalar read: ";
   print_generic_expr (dump_file, use, 0);
-  dp << "\nFrom stmt:";
+  dp << "\nFrom stmt: ";
   print_gimple_stmt (dump_file, use_stmt, 0, 0));
   reads->safe_push (std::make_pair (use_stmt, use));
 }
@@ -1879,7 +1879,18 @@ gather_bbs::before_dom_children (basic_block bb)
   int i;
   data_reference_p dr;
   FOR_EACH_VEC_ELT (gbb->data_refs, i, dr)
-

Re: [committed 5/5] Fix -Wmisleading-indentation warning in graphite-optimize-isl.c

2015-12-11 Thread Sebastian Pop
David Malcolm wrote:
> gcc/ChangeLog:
>   * graphite-optimize-isl.c (scop_get_domains): Fix indentation.
> ---
>  gcc/graphite-optimize-isl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/graphite-optimize-isl.c b/gcc/graphite-optimize-isl.c
> index 8727e39..0c6a971 100644
> --- a/gcc/graphite-optimize-isl.c
> +++ b/gcc/graphite-optimize-isl.c
> @@ -359,7 +359,7 @@ scop_get_domains (scop_p scop ATTRIBUTE_UNUSED)
>FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
>  res = isl_union_set_add_set (res, isl_set_copy (pbb->domain));
>  
> -return res;
> +  return res;

Thanks!
Sebastian



  1   2   3   4   5   >