public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-10091] openmp - Fix up && and || reductions [PR94366]
@ 2022-05-11 6:21 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-05-11 6:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:26c58b164fd78db4ce25f0183ed0225c08018f3f
commit r9-10091-g26c58b164fd78db4ce25f0183ed0225c08018f3f
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Jul 1 08:55:49 2021 +0200
openmp - Fix up && and || reductions [PR94366]
As the testcase shows, the special treatment of && and || reduction combiners
where we expand them as omp_out = (omp_out != 0) && (omp_in != 0) (or with ||)
is not needed just for &&/|| on floating point or complex types, but for all
&&/|| reductions - when expanded as omp_out = omp_out && omp_in (not in C but
GENERIC) it is actually gimplified into NOP_EXPRs to bool from both operands,
which turns non-zero values multiple of 2 into 0 rather than 1.
This patch just treats all &&/|| the same and furthermore uses bool type
instead of int for the comparisons.
2021-07-01 Jakub Jelinek <jakub@redhat.com>
PR middle-end/94366
gcc/
* omp-low.c (lower_rec_input_clauses): Rename is_fp_and_or to
is_truth_op, set it for TRUTH_*IF_EXPR regardless of new_var's type,
use boolean_type_node instead of integer_type_node as NE_EXPR type.
(lower_reduction_clauses): Likewise.
libgomp/
* testsuite/libgomp.c-c++-common/pr94366.c: New test.
(cherry picked from commit 91c771ec8a3b649765de3e0a7b04cf946c6649ef)
Diff:
---
gcc/omp-low.c | 55 +++++++++++-------------
libgomp/testsuite/libgomp.c-c++-common/pr94366.c | 17 ++++++++
2 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 89075dd54a0..0b79500ca2c 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -5177,11 +5177,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
if (code == MINUS_EXPR)
code = PLUS_EXPR;
- /* C/C++ permits FP/complex with || and &&. */
- bool is_fp_and_or
- = ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
- && (FLOAT_TYPE_P (TREE_TYPE (new_var))
- || TREE_CODE (TREE_TYPE (new_var)) == COMPLEX_TYPE));
+ bool is_truth_op
+ = (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR);
tree new_vard = new_var;
if (is_simd && omp_is_reference (var))
{
@@ -5209,17 +5206,18 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
}
tree ivar2 = ivar;
tree ref2 = ref;
- if (is_fp_and_or)
+ if (is_truth_op)
{
tree zero = build_zero_cst (TREE_TYPE (ivar));
ivar2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, ivar,
+ boolean_type_node, ivar,
zero);
ref2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, ref, zero);
+ boolean_type_node, ref,
+ zero);
}
x = build2 (code, TREE_TYPE (ref), ref2, ivar2);
- if (is_fp_and_or)
+ if (is_truth_op)
x = fold_convert (TREE_TYPE (ref), x);
ref = build_outer_var_ref (var, ctx);
gimplify_assign (ref, x, &llist[1]);
@@ -5241,19 +5239,19 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
tree ref = build_outer_var_ref (var, ctx);
tree new_var2 = new_var;
tree ref2 = ref;
- if (is_fp_and_or)
+ if (is_truth_op)
{
tree zero = build_zero_cst (TREE_TYPE (new_var));
new_var2
= fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, new_var,
+ boolean_type_node, new_var,
zero);
ref2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, ref,
+ boolean_type_node, ref,
zero);
}
x = build2 (code, TREE_TYPE (ref2), ref2, new_var2);
- if (is_fp_and_or)
+ if (is_truth_op)
x = fold_convert (TREE_TYPE (new_var), x);
ref = build_outer_var_ref (var, ctx);
gimplify_assign (ref, x, dlist);
@@ -5974,12 +5972,7 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
if (code == MINUS_EXPR)
code = PLUS_EXPR;
- /* C/C++ permits FP/complex with || and &&. */
- bool is_fp_and_or = ((code == TRUTH_ANDIF_EXPR
- || code == TRUTH_ORIF_EXPR)
- && (FLOAT_TYPE_P (TREE_TYPE (new_var))
- || (TREE_CODE (TREE_TYPE (new_var))
- == COMPLEX_TYPE)));
+ bool is_truth_op = (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR);
if (count == 1)
{
tree addr = build_fold_addr_expr_loc (clause_loc, ref);
@@ -5988,17 +5981,17 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
ref = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (addr)), addr);
tree new_var2 = new_var;
tree ref2 = ref;
- if (is_fp_and_or)
+ if (is_truth_op)
{
tree zero = build_zero_cst (TREE_TYPE (new_var));
new_var2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, new_var, zero);
- ref2 = fold_build2_loc (clause_loc, NE_EXPR, integer_type_node,
+ boolean_type_node, new_var, zero);
+ ref2 = fold_build2_loc (clause_loc, NE_EXPR, boolean_type_node,
ref, zero);
}
x = fold_build2_loc (clause_loc, code, TREE_TYPE (new_var2), ref2,
new_var2);
- if (is_fp_and_or)
+ if (is_truth_op)
x = fold_convert (TREE_TYPE (new_var), x);
x = build2 (OMP_ATOMIC, void_type_node, addr, x);
OMP_ATOMIC_MEMORY_ORDER (x) = OMP_MEMORY_ORDER_RELAXED;
@@ -6106,16 +6099,16 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
{
tree out2 = out;
tree priv2 = priv;
- if (is_fp_and_or)
+ if (is_truth_op)
{
tree zero = build_zero_cst (TREE_TYPE (out));
out2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, out, zero);
+ boolean_type_node, out, zero);
priv2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, priv, zero);
+ boolean_type_node, priv, zero);
}
x = build2 (code, TREE_TYPE (out2), out2, priv2);
- if (is_fp_and_or)
+ if (is_truth_op)
x = fold_convert (TREE_TYPE (out), x);
out = unshare_expr (out);
gimplify_assign (out, x, &sub_seq);
@@ -6152,16 +6145,16 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx)
{
tree new_var2 = new_var;
tree ref2 = ref;
- if (is_fp_and_or)
+ if (is_truth_op)
{
tree zero = build_zero_cst (TREE_TYPE (new_var));
new_var2 = fold_build2_loc (clause_loc, NE_EXPR,
- integer_type_node, new_var, zero);
- ref2 = fold_build2_loc (clause_loc, NE_EXPR, integer_type_node,
+ boolean_type_node, new_var, zero);
+ ref2 = fold_build2_loc (clause_loc, NE_EXPR, boolean_type_node,
ref, zero);
}
x = build2 (code, TREE_TYPE (ref), ref2, new_var2);
- if (is_fp_and_or)
+ if (is_truth_op)
x = fold_convert (TREE_TYPE (new_var), x);
ref = build_outer_var_ref (var, ctx);
gimplify_assign (ref, x, &sub_seq);
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr94366.c b/libgomp/testsuite/libgomp.c-c++-common/pr94366.c
new file mode 100644
index 00000000000..5837cd01a47
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/pr94366.c
@@ -0,0 +1,17 @@
+/* PR middle-end/94366 */
+
+int
+main ()
+{
+ int a = 2;
+ #pragma omp parallel reduction(&& : a)
+ a = a && 1;
+ if (!a)
+ __builtin_abort ();
+ a = 4;
+ #pragma omp parallel reduction(|| : a)
+ a = a || 0;
+ if (!a)
+ __builtin_abort ();
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-11 6:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11 6:21 [gcc r9-10091] openmp - Fix up && and || reductions [PR94366] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).