public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Xiong Hu Luo <luoxhu@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1184] if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
Date: Tue, 21 Jun 2022 09:29:45 +0000 (GMT)	[thread overview]
Message-ID: <20220621092945.70DDA3857415@sourceware.org> (raw)

https://gcc.gnu.org/g:57424087e82db140c06d4ea73f9700d5291c5bc2

commit r13-1184-g57424087e82db140c06d4ea73f9700d5291c5bc2
Author: Xionghu Luo <xionghuluo@tencent.com>
Date:   Thu Jun 9 15:46:30 2022 +0800

    if-to-switch: Don't skip the first condition bb when find_conditions in if-to-switch [PR105740]
    
    The if condition is at last of first bb, so side effect statement in first BB
    doesn't matter, then the first if condition could also be folded to switch
    table.
    
    gcc/ChangeLog:
    
            PR target/105740
            * gimple-if-to-switch.cc (find_conditions): Don't skip the first
            condition bb.
    
    gcc/testsuite/ChangeLog:
    
            PR target/105740
            * gcc.dg/tree-ssa/if-to-switch-11.c: New test.
    
    Signed-off-by: Xionghu Luo <xionghuluo@tencent.com>

Diff:
---
 gcc/gimple-if-to-switch.cc                      |  4 +++-
 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c | 28 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index 5dcfe5b77e0..ca276d790c3 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -389,7 +389,9 @@ find_conditions (basic_block bb,
   if (cond == NULL)
     return;
 
-  if (!no_side_effect_bb (bb))
+  /* An empty conditions_in_bbs indicates we are processing the first
+     basic-block then no need check side effect.  */
+  if (!conditions_in_bbs->is_empty () && !no_side_effect_bb (bb))
     return;
 
   tree lhs = gimple_cond_lhs (cond);
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c
new file mode 100644
index 00000000000..3dffee04812
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-11.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-iftoswitch-optimized" } */
+
+struct f {
+  int len;
+  int arr[4];
+};
+
+int
+test (struct f const *const f)
+{
+  if (f->arr[3] == 1) {
+    return 12;
+  } else if (f->arr[3] == 2) {
+    return 27;
+  } else if (f->arr[3] == 3) {
+    return 38;
+  } else if (f->arr[3] == 4) {
+    return 18;
+  } else if (f->arr[3] == 5) {
+    return 58;
+  } else if (f->arr[3] == 6) {
+    return 68;
+  }
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "Canonical GIMPLE case clusters: 1 2 3 4 5 6" "iftoswitch" } } */


                 reply	other threads:[~2022-06-21  9:29 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=20220621092945.70DDA3857415@sourceware.org \
    --to=luoxhu@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: link
Be 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).