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