]> git.ipfire.org Git - thirdparty/gcc.git/commit
PR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc
authorRoger Sayle <roger@nextmovesoftware.com>
Tue, 30 May 2023 13:40:50 +0000 (14:40 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Tue, 30 May 2023 13:43:27 +0000 (14:43 +0100)
commit69185294f322dd53d4e1592115014c5488302e2e
treed8c4110b42e7fb8d3b7715dedbee9107cde316cb
parenta899401404186843f38462c8fc9de733f19ce864
PR target/107172: Avoid "unusual" MODE_CC comparisons in simplify-rtx.cc

I believe that a better (or supplementary) fix to PR target/107172 is to
avoid producing incorrect (but valid) RTL in
simplify_const_relational_operation when presented with questionable
(obviously invalid) expressions, such as those produced during combine.
Just as with the "first do no harm" clause with the Hippocratic Oath,
simplify-rtx (probably) shouldn't unintentionally transform invalid RTL
expressions, into incorrect (non-equivalent) but valid RTL that may be
inappropriately recognized by recog.

In this specific case, many GCC backends represent their flags register via
MODE_CC, whose representation is intentionally "opaque" to the middle-end.
The only use of MODE_CC comprehensible to the middle-end's RTL optimizers
is relational comparisons between the result of a COMPARE rtx (op0) and zero
(op1).  Any other uses of MODE_CC should be left alone, and some might argue
indicate representational issues in the backend.

In practice, CPUs occasionally have numerous instructions that affect the
flags register(s) other than comparisons [AVR's setc, powerpc's mtcrf,
x86's clc, stc and cmc and x86_64's ptest that sets C and Z flags in
non-obvious ways, c.f. PR target/109973].  Currently care has to be taken,
wrapping these in UNSPEC, to avoid combine inappropriately merging flags
setters with flags consumers (such as conditional jumps).  It's safer to
teach simplify_const_relational_operation not to modify expressions that
it doesn't understand/recognize.

2023-05-30  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/107172
* simplify-rtx.cc (simplify_const_relational_operation): Return
early if we have a MODE_CC comparison that isn't a COMPARE against
const0_rtx.
gcc/simplify-rtx.cc