Hi Mikael, Thomas!

Am 07.08.24 um 11:11 schrieb Mikael Morin:
Hello,

Le 06/08/2024 à 22:57, Thomas Koenig a écrit :
Hi Mikael and Harald,

- inline expansion is inhibited at -Os.  But wouldn't it be good if
   we make this expansion also dependent on -ffrontend-optimize?
   (This was the case for rank-1 before your patch).

By the way, I disabled the minmaxloc frontend optimization without too much thought, because it was preventing me from seeing the effects of my patches in the dumps.  Now that both of you have put some focus on it, I think the optimization should be completely removed instead, because the patches make it unreachable.

The original idea was to have -ffrontend-optimize as a check if anything
went wrong with front-end optimization in particular - if the bug went
away with -fno-frontend-optimize, we knew where to look (and I knew
I had to look).

It also provides a way for users to workaround bugs in frontend optimizations.  If inline expansion were dependent on the flag, it would also provide the same benefit, but it would be using the flag outside of its intended scope, so I would rather not do it.

So, probably better to not do this at -Os.  One thought: Should we
also do the inlining without optimization?

At -Os: no inline expansion.  Don't we all agree on that?
I'm fine with also disabling expansion at -O0.

The following change to patch 2/8 does what I had in mind:

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 9f3c3ce47bc..cc0d00f4e39 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -11650,6 +11650,29 @@ gfc_inline_intrinsic_function_p (gfc_expr *expr)
     case GFC_ISYM_TRANSPOSE:
       return true;

+    case GFC_ISYM_MINLOC:
+    case GFC_ISYM_MAXLOC:
+      {
+       /* Disable inline expansion if code size matters.  */
+       if (optimize_size)
+         return false;

        /* Disable inline expansion if frontend optimization is disabled.  */
        if (!flag_frontend_optimize)
          return false;


As a result, the following happens:

- at -Os, inlining will never happen (as you had it)
- at -O0, the default is -fno-frontend-optimize, and we get the
  library implementation.  Inlining is forced with -ffrontend-optimize.
- at higher -Ox, the default is -ffrontend-optimize.

I believe this is also what Thomas' original motivation was.

(This flag actually helps to see that the inlining code in gcc-14
is currently broken for minloc/maxloc and optinional back argument).

As we are not planning to remove the library implementation (-Os!),
this is also the best way to compare library to inline code.

Cheers,
Harald

Mikael



Reply via email to