[hsa] Add missing guard in OMP gridification
authorMartin Jambor <mjambor@suse.cz>
Mon, 30 Oct 2017 15:07:20 +0000 (16:07 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Mon, 30 Oct 2017 15:07:20 +0000 (16:07 +0100)
2017-10-30  Martin Jambor  <mjambor@suse.cz>

* omp-grid.c (grid_attempt_target_gridification): Also insert a
condition whether loop should be executed at all.

From-SVN: r254225

gcc/ChangeLog
gcc/omp-grid.c

index c690e338484a5086f705795c8ac2782a48eba51e..8710e29f51aab3281edf66f1339ce3ccdf9a3d26 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-30  Martin Jambor  <mjambor@suse.cz>
+
+       * omp-grid.c (grid_attempt_target_gridification): Also insert a
+       condition whether loop should be executed at all.
+
 2017-10-30  Will Schmidt  <will_schmidt@vnet.ibm.com>
 
        * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for
index a7b6f60aeafbc1348770650fabaa116e5f396dd2..121c96ebe396b1ffe416181e5a05929bfe1d9646 100644 (file)
@@ -1315,6 +1315,7 @@ grid_attempt_target_gridification (gomp_target *target,
       n1 = fold_convert (itype, n1);
       n2 = fold_convert (itype, n2);
 
+      tree cond = fold_build2 (cond_code, boolean_type_node, n1, n2);
       tree step
        = omp_get_for_step_from_incr (loc, gimple_omp_for_incr (inner_loop, i));
 
@@ -1328,6 +1329,7 @@ grid_attempt_target_gridification (gomp_target *target,
                         fold_build1 (NEGATE_EXPR, itype, step));
       else
        t = fold_build2 (TRUNC_DIV_EXPR, itype, t, step);
+      t = fold_build3 (COND_EXPR, itype, cond, t, build_zero_cst (itype));
       if (grid.tiling)
        {
          if (cond_code == GT_EXPR)