[Bug target/104952] [nvptx][OpenMP] wrong code with OR / AND reduction ('reduction(||:' and '&&') with SIMT

vries at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 17 13:29:05 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104952

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
Alternative fix that doesn't require fiddling with the 'code' var:
...
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index d932d74cb03..d0ddd4a6142 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -6734,7 +6734,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq
*ilist, gimpl
e_seq *dlist,
                          x = build_call_expr_internal_loc
                            (UNKNOWN_LOCATION, IFN_GOMP_SIMT_XCHG_BFLY,
                             TREE_TYPE (ivar), 2, ivar, simt_lane);
-                         x = build2 (code, TREE_TYPE (ivar), ivar, x);
+                         /* Make sure x is evaluated unconditionally.  */
+                         tree bfly_var = create_tmp_var (TREE_TYPE (ivar));
+                         gimplify_assign (bfly_var, x, &llist[2]);
+                         x = build2 (code, TREE_TYPE (ivar), ivar, bfly_var);
                          gimplify_assign (ivar, x, &llist[2]);
                        }
                      tree ivar2 = ivar;
...


More information about the Gcc-bugs mailing list