[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 12:56:25 GMT 2022


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

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
This fixes it:
...
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index d932d74cb03..f2ac8f98e32 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -6734,7 +6734,21 @@ 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.  */
+                         enum tree_code update_code;
+                         switch (OMP_CLAUSE_REDUCTION_CODE (c))
+                           {
+                           case TRUTH_ANDIF_EXPR:
+                             update_code = TRUTH_AND_EXPR;
+                             break;
+                           case TRUTH_ORIF_EXPR:
+                             update_code = TRUTH_OR_EXPR;
+                             break;
+                           default:
+                             update_code = code;
+                             break;
+                           }
+                         x = build2 (update_code, TREE_TYPE (ivar), ivar, x);
                          gimplify_assign (ivar, x, &llist[2]);
                        }
                      tree ivar2 = ivar;
...


More information about the Gcc-bugs mailing list