[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-18 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

Tom de Vries  changed:

   What|Removed |Added

 Status|RESOLVED|WAITING
   Last reconfirmed||2017-08-18
 Resolution|FIXED   |---
 Ever confirmed|0   |1

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-18 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

Tom de Vries  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #11 from Tom de Vries  ---
(In reply to Tom de Vries from comment #10)
> [ Redoing https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01333.html, using
> PR81875 instead of PR81844, since PR81844 was overwritten ]
> 
> Filed comment 3 as PR81875 - omp for loop optimized away
> 
> This PR remains for the analysis of the test-case from comment 0.

My current hypothesis is that this is a cuda bug.

Filed bug report at nvidia, waiting for confirmation.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-17 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #10 from Tom de Vries  ---
[ Redoing https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01333.html, using PR81875
instead of PR81844, since PR81844 was overwritten ]

Filed comment 3 as PR81875 - omp for loop optimized away

This PR remains for the analysis of the test-case from comment 0.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-14 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #10 from Tom de Vries  ---
Filed comment 3 as PR81844 - omp for loop optimized away

This PR remains for the analysis of the test-case from comment 0.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

Tom de Vries  changed:

   What|Removed |Added

  Attachment #41970|0   |1
is obsolete||

--- Comment #9 from Tom de Vries  ---
Created attachment 41972
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41972=edit
Updated patch

Updated patch, passes check-target-libgomp and check-gcc/gomp.exp.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #8 from Tom de Vries  ---
(In reply to Tom de Vries from comment #7)
> (In reply to Tom de Vries from comment #6)
> > Created attachment 41970 [details]
> > tentative patch for test-case from comment 3
> 
> Works for test-case from comment 2 as well.

But not for test-case from comment 0.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #7 from Tom de Vries  ---
(In reply to Tom de Vries from comment #6)
> Created attachment 41970 [details]
> tentative patch for test-case from comment 3

Works for test-case from comment 2 as well.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #6 from Tom de Vries  ---
Created attachment 41970
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41970=edit
tentative patch for test-case from comment 3

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #5 from Tom de Vries  ---
(In reply to Tom de Vries from comment #4)
> (gdb) call debug_generic_expr (cond)
> (signed long) i < 0


And the conversion from unsigned to signed comparison is done here in
c_parser_omp_for_loop:
...
(gdb) call debug_generic_expr (cond)
<<< Unknown tree: c_maybe_const_expr

  i >>> > 9223372036854775807
(gdb) n
15030 cond = c_fully_fold (cond, false, NULL);
(gdb) n
15031 switch (cond_expr.original_code)
(gdb) call debug_generic_expr (cond)
(signed long) i < 0
...

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-11 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #4 from Tom de Vries  ---
(In reply to Alexander Monakov from comment #3)
> The comparison should have read '(long long)i < 0', no idea how the cast is
> lost.

It seems to be lost here, in c-omp.c:
...
   553/* 2.5.1.  The comparison in the condition is computed in
   554   the type of DECL, otherwise the behavior is undefined.
   555
   556   For example:
   557   long n; int i;
   558   i < n;
   559
   560   according to ISO will be evaluated as:
   561   (long)i < n;
   562
   563   We want to force:
   564   i < (int)n;  */
   565if (TREE_CODE (op0) == NOP_EXPR
   566&& decl == TREE_OPERAND (op0, 0))
   567  {
   568TREE_OPERAND (cond, 0) = TREE_OPERAND (op0, 0);
   569TREE_OPERAND (cond, 1)
   570  = fold_build1_loc (elocus, NOP_EXPR, TREE_TYPE
(decl),
   571 TREE_OPERAND (cond, 1));
   572  }
...

...
568   TREE_OPERAND (cond, 0) = TREE_OPERAND (op0, 0);
(gdb) call debug_generic_expr (cond)
(signed long) i < 0
(gdb) n
569   TREE_OPERAND (cond, 1)
(gdb) call debug_generic_expr (cond)
i < 0
...

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-10 Thread amonakov at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #3 from Alexander Monakov  ---
The new testcase fails on any target and not related to offloading. Simplified
further:

#define N 32ULL
int a[N];

const unsigned long long c = 0x7fffULL;

f2_tpf_static32 (void)
{
  unsigned long long i;
#pragma omp for
  for (i = c + N; i > c; i -= 1ULL)
a[i - 1ULL - c] -= 4;
}

in the .original dump we have:

{
  long long unsigned int i;

long long unsigned int i;
  #pragma omp for
  for (i = 9223372036854775839; i < 0; i = i + 18446744073709551615)
{
  a[i + 9223372036854775808] = a[i + 9223372036854775808] + -4
}
}

and soon after we deduce that loop doesn't iterate because i is unsigned. The
comparison should have read '(long long)i < 0', no idea how the cast is lost.

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-10 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #2 from Tom de Vries  ---
Simplified version, aborts in host code because loop has no effect:
...
#include 

extern void abort ();

#define N 32ULL

#pragma omp declare target
int a[N];
#pragma omp end declare target

const unsigned long long c = 0x7fffULL;

__attribute__((noinline, noclone)) void
f2_tpf_static32 (void)
{
  unsigned long long i;
#pragma omp target parallel for schedule(static, 32)
  for (i = c + N; i > c; i -= 1ULL)
a[i - 1ULL - c] -= 4;
}

__attribute__((noinline, noclone)) int
test_tpf_static32 (void)
{
  int i, j, k;
  for (i = 0; i < N; i++)
a[i] = i - 25;

#pragma omp target update to(a)
  f2_tpf_static32 ();
#pragma omp target update from(a)

  for (i = 0; i < N; i++)
printf ("%d: %d, expected: %d\n", i, a[i], i - 29);

  for (i = 0; i < N; i++)
if (a[i] != i - 29)
  return 1;

  return 0;
}

int
main ()
{
  if (test_tpf_static32 ())
abort ();

  return 0;
}
...

[Bug libgomp/81805] Another libgomp.c/for-5.c failure on nvptx -- illegal memory access

2017-08-10 Thread amonakov at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81805

--- Comment #1 from Alexander Monakov  ---
Can't reproduce this on my end. Are you going to proceed with analyzing the
failure?