]> git.ipfire.org Git - thirdparty/gcc.git/commit
x86: Replace ne:CCC/ne:CCO with UNSPEC_CC_NE in neg patterns
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 20 Oct 2022 18:55:19 +0000 (11:55 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 27 Oct 2022 18:41:54 +0000 (11:41 -0700)
commit0e36a9c6915c713d30016cbade97a4b31dcc1350
tree19af9d463981225452ec3a82498371f9a269612b
parent1c2b53ce8bbf5bbe1ddb13bb6005f432726518ae
x86: Replace ne:CCC/ne:CCO with UNSPEC_CC_NE in neg patterns

In i386.md, neg patterns which set MODE_CC register like

(set (reg:CCC FLAGS_REG)
     (ne:CCC (match_operand:SWI48 1 "general_reg_operand") (const_int 0)))

can lead to errors when operand 1 is a constant value.  If FLAGS_REG in

(set (reg:CCC FLAGS_REG)
     (ne:CCC (const_int 2) (const_int 0)))

is set to 1, RTX simplifiers may simplify

(set (reg:SI 93)
     (neg:SI (ltu:SI (reg:CCC 17 flags) (const_int 0 [0]))))

as

(set (reg:SI 93)
     (neg:SI (ltu:SI (const_int 1) (const_int 0 [0]))))

which leads to incorrect results since LTU on MODE_CC register isn't the
same as "unsigned less than" in x86 backend.  To prevent RTL optimizers
from setting MODE_CC register to a constant, use UNSPEC_CC_NE to replace
ne:CCC/ne:CCO when setting FLAGS_REG in neg patterns.

gcc/

PR target/107172
* config/i386/i386.md (UNSPEC_CC_NE): New.
Replace ne:CCC/ne:CCO with UNSPEC_CC_NE in neg patterns.

gcc/testsuite/

PR target/107172
* gcc.target/i386/pr107172.c: New test.
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr107172.c [new file with mode: 0644]