public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1601] Handle const_int in expand_single_bit_test Date: Wed, 7 Jun 2023 03:03:47 +0000 (GMT) [thread overview] Message-ID: <20230607030347.C6FF6385700B@sourceware.org> (raw) https://gcc.gnu.org/g:3f085e45755643f13d4fa45a12a6ade45be98f95 commit r14-1601-g3f085e45755643f13d4fa45a12a6ade45be98f95 Author: Andrew Pinski <apinski@marvell.com> Date: Sun Jun 4 19:42:08 2023 -0700 Handle const_int in expand_single_bit_test After expanding directly to rtl instead of creating a tree, we could end up with a const_int which is not ready to be handled by extract_bit_field. So need to the constant folding here instead. OK? bootstrapped and tested on x86_64-linux-gnu with no regressions. PR middle-end/110117 gcc/ChangeLog: * expr.cc (expand_single_bit_test): Handle const_int from expand_expr. gcc/testsuite/ChangeLog: * gcc.dg/pr110117-1.c: New test. * gcc.dg/pr110117-2.c: New test. Diff: --- gcc/expr.cc | 10 +++++++--- gcc/testsuite/gcc.dg/pr110117-1.c | 31 +++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr110117-2.c | 7 +++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index 1c5874b0dd0..868fa6e4cca 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -12952,12 +12952,16 @@ expand_single_bit_test (location_t loc, enum tree_code code, rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL); + if (CONST_SCALAR_INT_P (inner0)) + { + wide_int t = rtx_mode_t (inner0, operand_mode); + bool setp = (wi::lrshift (t, bitnum) & 1) != 0; + return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx; + } int bitpos = bitnum; - scalar_int_mode imode = as_a <scalar_int_mode>(GET_MODE (inner0)); - if (BYTES_BIG_ENDIAN) - bitpos = GET_MODE_BITSIZE (imode) - 1 - bitpos; + bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos; inner0 = extract_bit_field (inner0, 1, bitpos, 1, target, operand_mode, mode, 0, NULL); diff --git a/gcc/testsuite/gcc.dg/pr110117-1.c b/gcc/testsuite/gcc.dg/pr110117-1.c new file mode 100644 index 00000000000..fd9a9e3268e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110117-1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop" } */ +int a, b, d; +unsigned c; +int main() { + char e = -10; + int f = 1, g = 0; + if (a) { + char h = e; + i: + c = ~h - (-g & f || e); + int j = b % c; + g = j % 9; + if (c) { + if (d) + e = 0; + while (!g) + ; + int k = 0; + l: + if (k) + goto i; + } + } + if (e > -10) { + if (g) + f = 0; + goto l; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr110117-2.c b/gcc/testsuite/gcc.dg/pr110117-2.c new file mode 100644 index 00000000000..2e353258084 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110117-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-tree-dominator-opts -fno-tree-vrp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre -fno-tree-copy-prop" } */ +int f() +{ + int t = 0; + return (t & 1) != 0; +}
reply other threads:[~2023-06-07 3:03 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=20230607030347.C6FF6385700B@sourceware.org \ --to=pinskia@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).