On Wed, Jan 19, 2022 at 11:29:18PM +0100, Thomas Schwinge wrote: > (The pass is still disabled by default, by the way.) > > We've found that 'gcc/omp-oacc-kernels-decompose.cc' is currently not at > all considerate of 'GIMPLE_DEBUG' statements -- and it's not always > straight forward how to handle these (not rocket science either; but > needs proper understanding and testing).
The general rule is that debug stmts shouldn't affect code generation decisions, so when deciding what to optimize/how, they should be ignored, and during actual transformation adjusted or worst case reset as needed. > Actually fixing it is a separate task, but it seems prudent to at least > catch it, and document via a few test cases. OK to push > "Catch 'GIMPLE_DEBUG' misbehavior in OpenACC 'kernels' decomposition > [PR100400, PR103836, PR104061]", see attached? > --- a/gcc/omp-oacc-kernels-decompose.cc > +++ b/gcc/omp-oacc-kernels-decompose.cc > @@ -1255,6 +1255,16 @@ decompose_kernels_region_body (gimple *kernels_region, > tree kernels_clauses) > gsi_next (&gsi_n); > > gimple *stmt = gsi_stmt (gsi); > + if (gimple_code (stmt) == GIMPLE_DEBUG) > + { > + if (flag_compare_debug_opt || flag_compare_debug) > + /* Let the usual '-fcompare-debug' analysis bail out, as > + necessary. */ > + ; > + else > + sorry_at (loc, "%qs not yet supported", > + gimple_code_name[gimple_code (stmt)]); > + } This is wrong. It shouldn't be dependent on flag_compare_debug* options, those are just debugging aids to verify that -g/-g0 don't affect code generation. With the above you'd pretend they don't, but they actually would (with -g you'd get sorry, without it it would compile fine). If this code is analysing whether the kernels region body should be decomposed or not, it should be if (is_gimple_debug (stmt)) continue; or whatever else to just ignore them (in some opts already during analysis phase we remember they are present and something about them, but not in a way that would actually affect the code generation decisions). And then when actually transforming it, it depends on what transformations are done to the variables/values referenced in the debug stmts. gimple_debug_bind_reset_value (stmt); update_stmt (stmt); is what resets them and can be used as last resort, it will keep saying that it describes some var, but will say that the var is optimized out. Jakub