public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>, Jeff Law <jeffreyalaw@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] reassoc: Fix up recent regression in optimize_range_tests_cmp_bitwise [PR106958]
Date: Sat, 17 Sep 2022 08:02:36 +0200	[thread overview]
Message-ID: <YyVi/MnQt5Er2V37@tucnak> (raw)

Hi!

As the following testcase reduced from glibc fmtmsg.c shows
(it doesn't ICE on x86_64/i686 unfortunately, but does on various other
arches), my last optimize_range_tests_cmp_bitwise change wasn't fully
correct.  The intent was to let all pointer operands be cast to
pointer_sized_int_node first in addition to the other casts (to type1)
which are done for id >= l cases.
But one spot I've touched used always cast to type1 (note, the (b % 4) == 3
case is impossible for pointer operands because that is for !TYPE_UNSIGNED
operands and pointers are TYPE_UNSIGNED) and in the other spot the cast
would be done only for id >= l if not useless, but for pointers we need
to cast it always.

The following patch fixes that, bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk?

2022-09-17  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/106958
	* tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): If
	id >= l, cast op to type1, otherwise to pointer_sized_int_node.
	If type has pointer type, cast exp to pointer_sized_int_node
	even when id < l.

	* gcc.c-torture/compile/pr106958.c: New test.

--- gcc/tree-ssa-reassoc.cc.jj	2022-09-14 12:36:28.902351064 +0200
+++ gcc/tree-ssa-reassoc.cc	2022-09-16 22:25:23.671110030 +0200
@@ -3680,15 +3680,18 @@ optimize_range_tests_cmp_bitwise (enum t
 	    if (id == l || POINTER_TYPE_P (TREE_TYPE (op)))
 	      {
 		code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR;
-		g = gimple_build_assign (make_ssa_name (type1), code, op);
+		tree type3 = id >= l ? type1 : pointer_sized_int_node;
+		g = gimple_build_assign (make_ssa_name (type3), code, op);
 		gimple_seq_add_stmt_without_update (&seq, g);
 		op = gimple_assign_lhs (g);
 	      }
 	    tree type = TREE_TYPE (r->exp);
 	    tree exp = r->exp;
-	    if (id >= l && !useless_type_conversion_p (type1, type))
+	    if (POINTER_TYPE_P (type)
+		|| (id >= l && !useless_type_conversion_p (type1, type)))
 	      {
-		g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, exp);
+		tree type3 = id >= l ? type1 : pointer_sized_int_node;
+		g = gimple_build_assign (make_ssa_name (type3), NOP_EXPR, exp);
 		gimple_seq_add_stmt_without_update (&seq, g);
 		exp = gimple_assign_lhs (g);
 	      }
--- gcc/testsuite/gcc.c-torture/compile/pr106958.c.jj	2022-09-16 22:27:53.143079198 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr106958.c	2022-09-16 22:27:25.196458901 +0200
@@ -0,0 +1,13 @@
+/* PR tree-optimization/106958 */
+
+int a;
+void bar (int);
+
+void
+foo (char *x, char *y)
+{
+  int b = a != 0;
+  int c = x != 0;
+  int d = y != 0;
+  bar (b | c | d);
+}

	Jakub


             reply	other threads:[~2022-09-17  6:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  6:02 Jakub Jelinek [this message]
2022-09-17  6:09 ` Richard Biener

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=YyVi/MnQt5Er2V37@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=rguenther@suse.de \
    /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).