]> git.ipfire.org Git - thirdparty/gcc.git/commit
i386: Return CCmode from ix86_cc_mode for unknown RTX code [PR112494]
authorUros Bizjak <ubizjak@gmail.com>
Mon, 13 Nov 2023 21:45:55 +0000 (22:45 +0100)
committerUros Bizjak <ubizjak@gmail.com>
Mon, 13 Nov 2023 21:45:55 +0000 (22:45 +0100)
commitc75bab7274fe60fb2def8acf06ee9f4f856ce1ac
treef369565e8affa4a2a9227629582bf5c1dacf6651
parent97e9cde758582cdb97e3af47df6f32a8413f291f
i386: Return CCmode from ix86_cc_mode for unknown RTX code [PR112494]

Combine wants to combine following instructions into an insn that can
perform both an (arithmetic) operation and set the condition code.  During
the conversion a new RTX is created, and combine passes the RTX code of the
innermost RTX expression of the CC use insn in which CC reg is used to
SELECT_CC_MODE, to determine the new mode of the comparison:

Trying 5 -> 8:
    5: r98:DI=0xd7
    8: flags:CCZ=cmp(r98:DI,0)
      REG_EQUAL cmp(0xd7,0)
Failed to match this instruction:
(parallel [
        (set (reg:CC 17 flags)
            (compare:CC (const_int 215 [0xd7])
                (const_int 0 [0])))
        (set (reg/v:DI 98 [ flags ])
            (const_int 215 [0xd7]))
    ])

where:

(insn 5 2 6 2 (set (reg/v:DI 98 [ flags ])
        (const_int 215 [0xd7])) "pr112494.c":8:8 84 {*movdi_internal}
     (nil))

(insn 8 7 11 2 (set (reg:CCZ 17 flags)
        (compare:CCZ (reg/v:DI 98 [ flags ])
            (const_int 0 [0]))) "pr112494.c":11:9 8 {*cmpdi_ccno_1}
     (expr_list:REG_EQUAL (compare:CCZ (const_int 215 [0xd7])
            (const_int 0 [0]))
        (nil)))

x86_cc_mode (AKA SELECT_CC_MODE) is not prepared to handle random RTX
codes and triggers gcc_unreachable() when SET RTX code is passed to it.
The patch removes gcc_unreachable() and returns CCmode for unknown
RTX codes, so combine can try various combinations involving CC reg
without triggering ICE.

Please note that x86 MOV instructions do not set flags, so the above
combination is not recognized as a valid x86 instruction.

PR target/112494

gcc/ChangeLog:

* config/i386/i386.cc (ix86_cc_mode) [default]: Return CCmode.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112494.c: New test.
gcc/config/i386/i386.cc
gcc/testsuite/gcc.target/i386/pr112494.c [new file with mode: 0644]