n2 = OMP_CLAUSE_DECL (innerc);
}
tree step = fd->loop.step;
+ tree orig_step = step; /* May be different from step if is_simt. */
bool is_simt = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
OMP_CLAUSE__SIMT_);
tree altv = NULL_TREE, altn2 = NULL_TREE;
if (fd->collapse == 1
&& !broken_loop
- && TREE_CODE (fd->loops[0].step) != INTEGER_CST)
+ && TREE_CODE (orig_step) != INTEGER_CST)
{
/* The vectorizer currently punts on loops with non-constant steps
for the main IV (can't compute number of iterations and gives up
itype = signed_type_for (itype);
t = build_int_cst (itype, (fd->loop.cond_code == LT_EXPR ? -1 : 1));
t = fold_build2 (PLUS_EXPR, itype,
- fold_convert (itype, fd->loop.step), t);
+ fold_convert (itype, step), t);
t = fold_build2 (PLUS_EXPR, itype, t, fold_convert (itype, n2));
t = fold_build2 (MINUS_EXPR, itype, t,
fold_convert (itype, fd->loop.v));
t = fold_build2 (TRUNC_DIV_EXPR, itype,
fold_build1 (NEGATE_EXPR, itype, t),
fold_build1 (NEGATE_EXPR, itype,
- fold_convert (itype, fd->loop.step)));
+ fold_convert (itype, step)));
else
t = fold_build2 (TRUNC_DIV_EXPR, itype, t,
- fold_convert (itype, fd->loop.step));
+ fold_convert (itype, step));
t = fold_convert (TREE_TYPE (altv), t);
altn2 = create_tmp_var (TREE_TYPE (altv));
expand_omp_build_assign (&gsi, altn2, t);
if (is_simt)
{
gsi = gsi_start_bb (l2_bb);
- step = fold_build2 (MINUS_EXPR, TREE_TYPE (step), fd->loop.step, step);
+ step = fold_build2 (MINUS_EXPR, TREE_TYPE (step), orig_step, step);
if (POINTER_TYPE_P (type))
t = fold_build_pointer_plus (fd->loop.v, step);
else
--- /dev/null
+/* Minimized from for-5.c. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Size of array we want to write. */
+#define N 32
+
+/* Size of extra space before and after. */
+#define CANARY_SIZE (N * 32)
+
+/* Start of array we want to write. */
+#define BASE (CANARY_SIZE)
+
+// Total size to be allocated.
+#define ALLOC_SIZE (CANARY_SIZE + N + CANARY_SIZE)
+
+#pragma omp declare target
+int a[ALLOC_SIZE];
+#pragma omp end declare target
+
+int
+main (void)
+{
+ /* Use variable step in for loop. */
+ int s = 1;
+
+#pragma omp target update to(a)
+
+ /* Write a[BASE] .. a[BASE + N - 1]. */
+#pragma omp target simd
+ for (int i = N - 1; i > -1; i -= s)
+ a[BASE + i] = 1;
+
+#pragma omp target update from(a)
+
+ for (int i = 0; i < ALLOC_SIZE; i++)
+ {
+ int expected = (BASE <= i && i < BASE + N) ? 1 : 0;
+ if (a[i] == expected)
+ continue;
+
+ printf ("Expected %d, got %d at base[%d]\n", expected, a[i], i - BASE);
+ abort ();
+ }
+
+ return 0;
+}