Bug 114942 - [14/15 Regression] ICE on valid code at -O1 with "-fno-tree-sra -fno-guess-branch-probability": in extract_constrain_insn, at recog.cc:2713
Summary: [14/15 Regression] ICE on valid code at -O1 with "-fno-tree-sra -fno-guess-br...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: 14.2
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, ra
Depends on:
Blocks:
 
Reported: 2024-05-03 22:13 UTC by Zhendong Su
Modified: 2024-06-17 15:18 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2024-05-03 22:13:41 UTC
It appears to be a recent regression as it doesn't reproduce with 13.2 and earlier.

Compiler Explorer: https://godbolt.org/z/av9hr4933

[648] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap --enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk --enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240503 (experimental) (GCC)
[649] %
[649] % gcctk -O1 -c -fno-tree-sra -fno-guess-branch-probability small.c
small.c: In function ‘main’:
small.c:21:1: error: insn does not satisfy its constraints:
   21 | }
      | ^
(insn 39 56 57 6 (parallel [
            (set (strict_low_part (reg:QI 2 cx [orig:108 f ] [108]))
                (ior:QI (subreg:QI (zero_extract:HI (reg/v:HI 2 cx [orig:108 f ] [108])
                            (const_int 8 [0x8])
                            (const_int 8 [0x8])) 0)
                    (reg:QI 0 ax [orig:121 _7 ] [121])))
            (clobber (reg:CC 17 flags))
        ]) "small.c":19:7 626 {*iorqi_exthi_1_slp}
     (nil))
during RTL pass: reload
small.c:21:1: internal compiler error: in extract_constrain_insn, at recog.cc:2713
0x83dea6 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
        ../../gcc-trunk/gcc/rtl-error.cc:108
0x83ded2 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
        ../../gcc-trunk/gcc/rtl-error.cc:118
0x83c10c extract_constrain_insn(rtx_insn*)
        ../../gcc-trunk/gcc/recog.cc:2713
0xf55a67 check_rtl
        ../../gcc-trunk/gcc/lra.cc:2189
0xf5aef1 lra(_IO_FILE*, int)
        ../../gcc-trunk/gcc/lra.cc:2610
0xf0b1ff do_reload
        ../../gcc-trunk/gcc/ira.cc:5973
0xf0b1ff execute
        ../../gcc-trunk/gcc/ira.cc:6161
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
[650] %
[650] % cat small.c
extern void a();
struct b {
  char c;
  char d;
} e;
int main() {
  struct b f = e;
  char i = 0;
 L1:
  if (!f.c)
    goto L2;
  if (e.c)
    a();
  else
    return 0;
  f.d = 0;
  i = 1 % ((1 & f.c) - 2);
 L2:
  f.c = ~(i & ~f.d);
  goto L1;
}
Comment 1 Andrew Pinski 2024-05-03 22:25:35 UTC
Confirmed. Looks like it was introduced with r14-5456-gb42a09b258c3ed .
Comment 2 Uroš Bizjak 2024-05-04 08:28:49 UTC
This is the insn in question:

;; Alternative 1 is needed to work around LRA limitation, see PR82524.
 (define_insn_and_split "*<code>qi_ext<mode>_1_slp"
   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+Q,&Q"))
         (any_logic:QI
           (subreg:QI
             (match_operator:SWI248 3 "extract_operator"
               [(match_operand 2 "int248_register_operand" "Q,Q")
                (const_int 8)
                (const_int 8)]) 0)
           (match_operand:QI 1 "nonimmediate_operand" "0,!qm")))
    (clobber (reg:CC FLAGS_REG))]

When targeting alternative 1, reload should use some other register for operand 2.
Comment 3 Uroš Bizjak 2024-05-05 19:32:58 UTC
Reload starts with:

(insn 39 38 48 6 (parallel [
            (set (strict_low_part (subreg:QI (reg/v:HI 108 [ f ]) 0))
                (ior:QI (subreg:QI (zero_extract:HI (reg/v:HI 108 [ f ])
                            (const_int 8 [0x8])
                            (const_int 8 [0x8])) 0)
                    (reg:QI 121 [ _7 ])))
            (clobber (reg:CC 17 flags))
        ]) "pr114942.c":19:7 626 {*iorqi_exthi_1_slp}
     (expr_list:REG_DEAD (reg:QI 121 [ _7 ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

      Choosing alt 1 in insn 39:  (0) &Q  (1) !qm  (2) Q {*iorqi_exthi_1_slp}

and then allocates:

(insn 39 56 57 6 (parallel [
            (set (strict_low_part (reg:QI 2 cx [orig:108 f ] [108]))
                (ior:QI (subreg:QI (zero_extract:HI (reg/v:HI 2 cx [orig:108 f ] [108])
                            (const_int 8 [0x8])
                            (const_int 8 [0x8])) 0)
                    (reg:QI 0 ax [orig:121 _7 ] [121])))
            (clobber (reg:CC 17 flags))
        ]) "pr114942.c":19:7 626 {*iorqi_exthi_1_slp}

not taking into account the earlyclobber of operand 0.
Comment 4 Richard Biener 2024-05-07 07:46:08 UTC
GCC 14.1 is being released, retargeting bugs to GCC 14.2.
Comment 5 Vladimir Makarov 2024-05-08 17:11:55 UTC
I've started to work on this PR.  I hope a patch will be ready on this or the next week.
Comment 6 GCC Commits 2024-05-10 16:29:39 UTC
The master branch has been updated by Vladimir Makarov <vmakarov@gcc.gnu.org>:

https://gcc.gnu.org/g:9585317f0715699197b1313bbf939c6ea3c1ace6

commit r15-364-g9585317f0715699197b1313bbf939c6ea3c1ace6
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Fri May 10 09:15:50 2024 -0400

    [PR114942][LRA]: Don't reuse input reload reg of inout early clobber operand
    
      The insn in question has the same reg in inout operand and input
    operand.  The inout operand is early clobber.  LRA reused input reload
    reg of the inout operand for the input operand which is wrong.  It
    were a good decision if the inout operand was not early clobber one.
    The patch rejects the reuse for the PR test case.
    
    gcc/ChangeLog:
    
            PR target/114942
            * lra-constraints.cc (struct input_reload): Add new member early_clobber_p.
            (get_reload_reg): Add new arg early_clobber_p, don't reuse input
            reload with true early_clobber_p member value, use the arg for new
            element of curr_insn_input_reloads.
            (match_reload): Assign false to early_clobber_p member.
            (process_addr_reg, simplify_operand_subreg, curr_insn_transform):
            Adjust get_reload_reg calls.
    
    gcc/testsuite/ChangeLog:
    
            PR target/114942
            * gcc.target/i386/pr114942.c: New.
Comment 7 Andrew Pinski 2024-06-17 15:18:50 UTC
*** Bug 115521 has been marked as a duplicate of this bug. ***