[m-rev.] for review: add a workaround for Mantis bug #492
Peter Wang
novalazy at gmail.com
Thu Jan 16 22:18:06 AEDT 2020
On Thu, 16 Jan 2020 18:58:55 +1100 (AEDT), Julien Fischer <jfischer at opturion.com> wrote:
>
> For review by anyone.
>
> Branches: master, 20.01
>
> --------------------------
>
> Add a workaround for Mantis bug #492.
>
> In debug grades that use global register variables, the generated C code is
> triggering an internal error in GCC 9 on x86_64 machines. Force GCC to compile
> at -O0 in this case as that seems to be the only workaround for the issue.
>
> scripts/mgnuc.in:
> Force GCC to use -O0 in the above case.
>
> compiler/compile_target_code.m:
> Do the same when GCC is invoked directly by the Mercury compiler.
>
> Re-arrange some of the code that applies C compiler bug workarounds
> to make this possible.
>
> Add an XXX about an overly broad bug workaround on darwin; I'll look
> into that separately.
>
> Julien.
> @@ -442,12 +443,33 @@ gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
> AppleGCCRegWorkaroundOpt = ""
> ),
>
> - % Workaround performance problem(s) with gcc that causes the C files
> - % generated in debugging grades to compile very slowly at -O1 and above.
> - % (Changes here need to be reflected in scripts/mgnuc.in.)
> + % Last resort workarounds for C compiler bugs.
> + % Changes here need to be reflected in scripts/mgnuc.in.
> + %
> + globals.lookup_bool_option(Globals, exec_trace, ExecTrace),
> ( if
> - globals.lookup_bool_option(Globals, exec_trace, yes),
> - arch_is_apple_darwin(TargetArch)
> + % We need to disable C compiler optimizations in debugging grades
> + % in either of the two situations described below.
> + ExecTrace = yes,
> + (
> + % 1. On Apple Darwin systems there are performance problems with
> + % GCC that cause it to compile the C files generated in debugging
> + % grades very slowly at -O1 or greater.
> + %
> + % XXX we are also enabling this for clang; does it have the
> + % same performance problems?
> + %
> + arch_is_apple_darwin(TargetArch)
> + ;
> + % 2. There is a bug in GCC 9.[12] that results in an internal error
> + % in the LRA pass when compiling generated C files in debugging
> + % grades that also use global registers on x86_64 machines.
> + % See: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91430>
> + %
> + GlobalRegisters = yes,
> + C_CompilerType = cc_gcc(yes(9), _, _),
> + string.prefix(TargetArch, "x86_64")
> + )
The bug is supposed to be fixed but the fix didn't make it into
gcc 9.2, so maybe limit the workaround to gcc 9.1 and gcc 9.2.
I'll try verify a gcc snapshot tomorrow.
Looks fine otherwise.
Peter
More information about the reviews
mailing list