public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: "Thompson,
	Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC] via
	Fortran" <fortran@gcc.gnu.org>
Cc: Thomas Koenig <tkoenig@netcologne.de>
Subject: Re: [EXTERNAL] Re: Advice with finding speed between O2 and O3
Date: Thu, 25 May 2023 10:01:06 -0700	[thread overview]
Message-ID: <ZG+UUqGfELQfcqGk@troutmask.apl.washington.edu> (raw)
In-Reply-To: <075103A8-4E87-4FD1-ABA6-F5C5C6A2540E@nasa.gov>

On Thu, May 25, 2023 at 04:05:11PM +0000, Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC] via Fortran wrote:
> Thomas,
> 
> Well, the code did not change. Period. Neither did the compiler. It was 12.3. (We can't use GCC 13 because it seems not to like something in our advanced Fortran code (lots of OO, submodules, string fun...)).
> 
> And I did a run with essentially all the GNU checks on (our Debug build mode) and it happily runs!
> 
> That said, I did some further tests and I am *really* confused. This fails:
> 
> -O3 -march=haswell -mtune=generic -funroll-loops -g
> 
> And this works:
> 
> -O2 -march=haswell -mtune=generic -funroll-loops -g
> 
> Now I just tried:
> 
> -O2     -fgcse-after-reload    -fipa-cp-clone    -floop-interchange    -floop-unroll-and-jam    -fpeel-loops    -fpredictive-commoning    -fsplit-loops    -fsplit-paths    -ftree-loop-distribution    -ftree-partial-pre    -funroll-completely-grow-size    -funswitch-loops    -fversion-loops-for-strides  -march=haswell -mtune=generic -funroll-loops -g
> 
> which as far as I can see from the gcc man page:
> 
>        -O3 Optimize yet more.  -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags:
> 
>            -fgcse-after-reload -fipa-cp-clone -floop-interchange -floop-unroll-and-jam -fpeel-loops -fpredictive-commoning -fsplit-loops -fsplit-paths -ftree-loop-distribution -ftree-partial-pre -funswitch-loops
>            -fvect-cost-model=dynamic -fversion-loops-for-strides
> 
> means I am running essentially -O3.
> 
> But it works.
> 
> I'm...baffled. Is there something that *gfortran* enables with -O3 that isn't visible from the *gcc* man page?
> 

gcc/gcc/opts.cc also shows some fiddling with parameters.

  /* -O3 parameters.  */
  { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_auto_, NULL, 30 },
  { OPT_LEVELS_3_PLUS, OPT__param_early_inlining_insns_, NULL, 14 },
  { OPT_LEVELS_3_PLUS, OPT__param_inline_heuristics_hint_percent_, NULL, 600 },
  { OPT_LEVELS_3_PLUS, OPT__param_inline_min_speedup_, NULL, 15 },
  { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_single_, NULL, 200 },

AFAICT, gfortran does not add or change anything with -O3.
Out of curosity, does it compile and run with -O3 if you 
remove one or both of '-march=haswell -mtune=generic'?

One other possibility is an issue with signed integer overflow,
but I don't remember if the change that causes the issue has
reached 12.x.  Does the code run if you add -fwrapv to your
options list?
-- 
Steve

  reply	other threads:[~2023-05-25 17:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 15:31 Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC]
2023-05-22 21:36 ` Thomas Koenig
2023-05-25 16:05   ` [EXTERNAL] " Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC]
2023-05-25 17:01     ` Steve Kargl [this message]
2023-05-25 18:51       ` Harald Anlauf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZG+UUqGfELQfcqGk@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@gcc.gnu.org \
    --cc=tkoenig@netcologne.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).