Mercury Bugs - mercury
View Issue Details
0000520mercuryBugpublic2020-09-18 02:232020-10-02 17:46
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000520: possible GCC ICE when compiling library/int.m in grade with -O1
DescriptionI'm not really sure this is even a Mercury bug.

When mercury is configured with --enabled-trail-grades an internal compiler error may occur when compiling library/int.m or library/uint.m in the grade and -O2 optimizations exist in CFLAGS.

To reproduce:

$ ./configure --enable-trail-grades
$ echo "EXTRA_CFLAGS = -O1" >> Mmake.params
$ make
$ make install

Alternatively, if mercury is already installed with a grade:

$ cd mercury-srcdist/library
$ mmc --compile-to-c --grade int
$ mgnuc --grade -- -O1 -c int.c int.o

In both cases the following ICE has been observed:

int.c: In function 'int_module123':
int.c:21687:1: error: unable to generate reloads for:
(insn 162 161 163 11 (parallel [
            (set (reg/v:DI 43 r15 [ MR_mr3 ])
                (ashift:DI (reg/v:DI 42 r14 [ MR_mr2 ])
                    (const_int 6 [0x6])))
            (clobber (reg:CC 17 flags))
        ]) "int.m":1013:18 520 {*ashldi3_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
during RTL pass: reload
int.c21687:1: internal compiler error: in curr_insn_transform, at lra-constraints.c:3962

The ICE only seems to occur with GCC 9.x. I've tried the following versions of GCC:

* 8.3.0: no ICE
* 9.2.0: ICE
* 9.3.0: ICE
* 10.2.0: no ICE
TagsNo tags attached.
Attached Files

2020-09-18 16:28   
It's a Mercury bug to the extent that we would ideally apply workarounds to avoid the bugs in the affected versions of GCC.
2020-10-02 17:46   
This is the issue from bug 0000492. The compiler already has a workaround for the problem, but by setting EXTRA_CFLAGS=-O1 you are overriding that workaround.

The underlying issue is not present in the GCC 8 and 10 branches, but seems to affect all versions of GCC 9 for x86_64.

Issue History
2020-09-18 02:23keriNew Issue
2020-09-18 16:28juliensfNote Added: 0001104
2020-10-02 17:46juliensfNote Added: 0001106