public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10688] match.pd: Don't create BIT_NOT_EXPRs for COMPLEX_TYPE [PR104675] Date: Tue, 10 May 2022 08:24:38 +0000 (GMT) [thread overview] Message-ID: <20220510082438.C5380388703B@sourceware.org> (raw) https://gcc.gnu.org/g:1a8b7fb748f95646f314d5dd7a5af48542c3e925 commit r10-10688-g1a8b7fb748f95646f314d5dd7a5af48542c3e925 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Feb 25 10:55:17 2022 +0100 match.pd: Don't create BIT_NOT_EXPRs for COMPLEX_TYPE [PR104675] We don't support BIT_{AND,IOR,XOR,NOT}_EXPR on complex types, &/|/^ are just rejected for them, and ~ is parsed as CONJ_EXPR. So, we should avoid simplifications which turn valid complex type expressions into something that will ICE during expansion. 2022-02-25 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/104675 * match.pd (-A - 1 -> ~A, -1 - A -> ~A): Don't simplify for COMPLEX_TYPE. * gcc.dg/pr104675-1.c: New test. * gcc.dg/pr104675-2.c: New test. (cherry picked from commit 758671b88b78d7629376b118ec6ca6bcfbabbd36) Diff: --- gcc/match.pd | 4 +++- gcc/testsuite/gcc.dg/pr104675-1.c | 29 +++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr104675-2.c | 18 ++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 590934fcf9a..16d376453f6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2346,13 +2346,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (minus (convert? (negate @0)) integer_each_onep) (if (!TYPE_OVERFLOW_TRAPS (type) + && TREE_CODE (type) != COMPLEX_TYPE && tree_nop_conversion_p (type, TREE_TYPE (@0))) (bit_not (convert @0)))) /* -1 - A -> ~A */ (simplify (minus integer_all_onesp @0) - (bit_not @0)) + (if (TREE_CODE (type) != COMPLEX_TYPE) + (bit_not @0))) /* (T)(P + A) - (T)P -> (T) A */ (simplify diff --git a/gcc/testsuite/gcc.dg/pr104675-1.c b/gcc/testsuite/gcc.dg/pr104675-1.c new file mode 100644 index 00000000000..af0b4390c30 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104675-1.c @@ -0,0 +1,29 @@ +/* PR tree-optimization/104675 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +_Complex int +foo (_Complex int a) +{ + return (-1 + -1i) - a; +} + +_Complex int +bar (_Complex int a) +{ + return -a - (1 + 1i); +} + +_Complex int +baz (_Complex int a) +{ + _Complex int b = -1 + -1i; + return b - a; +} + +_Complex int +qux (_Complex int a) +{ + _Complex int b = 1 + 1i; + return -a - b; +} diff --git a/gcc/testsuite/gcc.dg/pr104675-2.c b/gcc/testsuite/gcc.dg/pr104675-2.c new file mode 100644 index 00000000000..037d0c4f10d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104675-2.c @@ -0,0 +1,18 @@ +/* PR tree-optimization/104675 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void baz (int i); + +void +bar (_Complex int c, short s) +{ + c -= s; + baz (__real__ c + __imag__ c); +} + +void +foo (void) +{ + bar (-1 - 1i, 0); +}
reply other threads:[~2022-05-10 8:24 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220510082438.C5380388703B@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).