See attached patch, 9/10 of v2 of the DO CONCURRENT to OpenMP series,
unchanged since v1. This one is in the middle end and needs an OpenMP
maintainer's review.
The change is in execute_omp_device_lower in omp-offload.cc: when the
function has variant constructs, the pass now returns TODO_cleanup_cfg
after resolving their cookies, so the branches that a constant
condition makes unreachable go away also at -O0. Functions without
variant constructs are unaffected. The rest of the diff only reindents
the resolution loop inside a block.
The change also applies to C and C++ declare variant, metadirective and
the like, so I ran the C and C++ gomp.exp and libgomp testsuites as
well, with no new failures.
Regards,
Jerry
---
openmp: [PR128590]-9 Clean up the CFG after resolving variant cookies
ompdevlow resolves the cookies of variant constructs, such as
OMP_TARGET_DEVICE_MATCHES, to constants, but without optimization the
code that they make unreachable stays, so each compiler still has to
compile and link it, even where it refers to something only another
device provides. Return TODO_cleanup_cfg after resolving them. The
next patch needs this: there the host branch of a DO CONCURRENT
construct in a PURE procedure calls omp_target_is_present, which the
device libgomp does not provide.
Assisted-by: Claude Opus 5.5
PR fortran/128590
gcc/ChangeLog:
* omp-offload.cc (execute_omp_device_lower): Return
TODO_cleanup_cfg after resolving the cookies of variant constructs.
>From 038739ebc4e596811cc2c7f4526b6c320f2bc1f5 Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Tue, 24 Nov 2026 17:23:35 -0800
Subject: [PATCH v2 9/10] openmp: [PR128590]-9 Clean up the CFG after resolving
variant cookies
ompdevlow resolves the cookies of variant constructs, such as
OMP_TARGET_DEVICE_MATCHES, to constants, but without optimization the
code that they make unreachable stays, so each compiler still has to
compile and link it, even where it refers to something only another
device provides. Return TODO_cleanup_cfg after resolving them. The
next patch needs this: there the host branch of a DO CONCURRENT
construct in a PURE procedure calls omp_target_is_present, which the
device libgomp does not provide.
Assisted-by: Claude Opus 5.5
PR fortran/128590
gcc/ChangeLog:
* omp-offload.cc (execute_omp_device_lower): Return
TODO_cleanup_cfg after resolving the cookies of variant constructs.
---
gcc/omp-offload.cc | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index 2caad760ff2..6ae78736d8e 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -2733,6 +2733,7 @@ execute_omp_device_lower ()
{
int vf = targetm.simt.vf ? targetm.simt.vf () : 1;
bool regimplify = false;
+ bool cleanup_cfg = false;
basic_block bb;
gimple_stmt_iterator gsi;
#ifdef ACCEL_COMPILER
@@ -2741,15 +2742,20 @@ execute_omp_device_lower ()
= builtin_decl_explicit (BUILT_IN_GOMP_TARGET_MAP_INDIRECT_PTR);
#endif
- /* Handle expansion of magic cookies for variant constructs first. */
+ /* Handle expansion of magic cookies for variant constructs first.
+ Remove the code that they make unreachable also without
+ optimization, as it may refer to what this compiler lacks. */
if (cgraph_node::get (cfun->decl)->has_omp_variant_constructs)
- FOR_EACH_BB_FN (bb, cfun)
- {
- for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- walk_gimple_op (gsi_stmt (gsi), resolve_omp_variant_cookies, NULL);
- for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
- walk_gimple_op (gsi_stmt (gsi), resolve_omp_variant_cookies, NULL);
- }
+ {
+ FOR_EACH_BB_FN (bb, cfun)
+ {
+ for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+ walk_gimple_op (gsi_stmt (gsi), resolve_omp_variant_cookies, NULL);
+ for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+ walk_gimple_op (gsi_stmt (gsi), resolve_omp_variant_cookies, NULL);
+ }
+ cleanup_cfg = true;
+ }
FOR_EACH_BB_FN (bb, cfun)
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -2897,7 +2903,7 @@ execute_omp_device_lower ()
}
if (vf != 1)
cfun->has_force_vectorize_loops = false;
- return 0;
+ return cleanup_cfg ? TODO_cleanup_cfg : 0;
}
namespace {
--
2.56.1