public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] simplify-rtx: Fix compare of comparisons (PR60818)
@ 2017-03-31 22:50 Segher Boessenkool
  2017-04-03 17:01 ` Jeff Law
  2017-05-01  9:13 ` Segher Boessenkool
  0 siblings, 2 replies; 4+ messages in thread
From: Segher Boessenkool @ 2017-03-31 22:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool

The function simplify_binary_operation_1 has code that does
/* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags).  */
but this transformation is only valid if "flags" has the same machine
mode as the outer compare.  This fixes it.

Bootstrapped and tested on powerpc64-linux {-m32,-m64} (and tested the
new testcase with {-m32,-m64}{,-misel}).  Is this okay for trunk?


Segher


2017-03-31  Segher Boessenkool  <segher@kernel.crashing.org>

	PR rtl-optimization/60818
	* simplify-rtx.c (simplify_binary_operation_1): Do not replace
	a compare of comparisons with the thing compared if this results
	in a different machine mode.

gcc/testsuite/
	PR rtl-optimization/60818
	* gcc.c-torture/compile/pr60818.c: New testcase.

---
 gcc/simplify-rtx.c                            | 6 +++---
 gcc/testsuite/gcc.c-torture/compile/pr60818.c | 5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr60818.c

diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 3022779..10c2800 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -2367,10 +2367,10 @@
 	      return xop00;
 
 	    if (REG_P (xop00) && REG_P (xop10)
-		&& GET_MODE (xop00) == GET_MODE (xop10)
 		&& REGNO (xop00) == REGNO (xop10)
-		&& GET_MODE_CLASS (GET_MODE (xop00)) == MODE_CC
-		&& GET_MODE_CLASS (GET_MODE (xop10)) == MODE_CC)
+		&& GET_MODE (xop00) == mode
+		&& GET_MODE (xop10) == mode
+		&& GET_MODE_CLASS (mode) == MODE_CC)
 	      return xop00;
 	}
       break;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr60818.c b/gcc/testsuite/gcc.c-torture/compile/pr60818.c
new file mode 100644
index 0000000..b6171bb
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr60818.c
@@ -0,0 +1,5 @@
+int
+lx (int oi, int mb)
+{
+  return (oi < mb) < (mb < oi);
+}
-- 
1.9.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] simplify-rtx: Fix compare of comparisons (PR60818)
  2017-03-31 22:50 [PATCH] simplify-rtx: Fix compare of comparisons (PR60818) Segher Boessenkool
@ 2017-04-03 17:01 ` Jeff Law
  2017-04-03 17:19   ` Segher Boessenkool
  2017-05-01  9:13 ` Segher Boessenkool
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff Law @ 2017-04-03 17:01 UTC (permalink / raw)
  To: Segher Boessenkool, gcc-patches

On 03/31/2017 03:40 PM, Segher Boessenkool wrote:
> The function simplify_binary_operation_1 has code that does
> /* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags).  */
> but this transformation is only valid if "flags" has the same machine
> mode as the outer compare.  This fixes it.
>
> Bootstrapped and tested on powerpc64-linux {-m32,-m64} (and tested the
> new testcase with {-m32,-m64}{,-misel}).  Is this okay for trunk?
>
>
> Segher
>
>
> 2017-03-31  Segher Boessenkool  <segher@kernel.crashing.org>
>
> 	PR rtl-optimization/60818
> 	* simplify-rtx.c (simplify_binary_operation_1): Do not replace
> 	a compare of comparisons with the thing compared if this results
> 	in a different machine mode.
>
> gcc/testsuite/
> 	PR rtl-optimization/60818
> 	* gcc.c-torture/compile/pr60818.c: New testcase.
Doesn't seem like a regression.  But I can't see how it could possibly 
result in any correctness issues -- the absolute worst would be a 
performance issue and even that seems highly unlikely.

OK for the trunk if you think it's worth fixing for gcc-7.  Else it's 
pre-approved for gcc-8.


jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] simplify-rtx: Fix compare of comparisons (PR60818)
  2017-04-03 17:01 ` Jeff Law
@ 2017-04-03 17:19   ` Segher Boessenkool
  0 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2017-04-03 17:19 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches

On Mon, Apr 03, 2017 at 11:01:23AM -0600, Jeff Law wrote:
> >	PR rtl-optimization/60818
> >	* simplify-rtx.c (simplify_binary_operation_1): Do not replace
> >	a compare of comparisons with the thing compared if this results
> >	in a different machine mode.
> >
> >gcc/testsuite/
> >	PR rtl-optimization/60818
> >	* gcc.c-torture/compile/pr60818.c: New testcase.
> Doesn't seem like a regression.  But I can't see how it could possibly 
> result in any correctness issues -- the absolute worst would be a 
> performance issue and even that seems highly unlikely.

It ICEs with trunk, it didn't ICE with 6.

The problem is that changing the mode of the CC in the producer, while
not changing the mode in the consumer, is very wrong, and runs into
asserts later on.

> OK for the trunk if you think it's worth fixing for gcc-7.  Else it's 
> pre-approved for gcc-8.

I'll commit it then.  Thanks,


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] simplify-rtx: Fix compare of comparisons (PR60818)
  2017-03-31 22:50 [PATCH] simplify-rtx: Fix compare of comparisons (PR60818) Segher Boessenkool
  2017-04-03 17:01 ` Jeff Law
@ 2017-05-01  9:13 ` Segher Boessenkool
  1 sibling, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2017-05-01  9:13 UTC (permalink / raw)
  To: gcc-patches

Hi!

Is this okay for backport to 5 and 6?


Segher


On Fri, Mar 31, 2017 at 09:40:34PM +0000, Segher Boessenkool wrote:
> The function simplify_binary_operation_1 has code that does
> /* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags).  */
> but this transformation is only valid if "flags" has the same machine
> mode as the outer compare.  This fixes it.
> 
> Bootstrapped and tested on powerpc64-linux {-m32,-m64} (and tested the
> new testcase with {-m32,-m64}{,-misel}).  Is this okay for trunk?
> 
> 
> Segher
> 
> 
> 2017-03-31  Segher Boessenkool  <segher@kernel.crashing.org>
> 
> 	PR rtl-optimization/60818
> 	* simplify-rtx.c (simplify_binary_operation_1): Do not replace
> 	a compare of comparisons with the thing compared if this results
> 	in a different machine mode.
> 
> gcc/testsuite/
> 	PR rtl-optimization/60818
> 	* gcc.c-torture/compile/pr60818.c: New testcase.
> 
> ---
>  gcc/simplify-rtx.c                            | 6 +++---
>  gcc/testsuite/gcc.c-torture/compile/pr60818.c | 5 +++++
>  2 files changed, 8 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr60818.c
> 
> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
> index 3022779..10c2800 100644
> --- a/gcc/simplify-rtx.c
> +++ b/gcc/simplify-rtx.c
> @@ -2367,10 +2367,10 @@
>  	      return xop00;
>  
>  	    if (REG_P (xop00) && REG_P (xop10)
> -		&& GET_MODE (xop00) == GET_MODE (xop10)
>  		&& REGNO (xop00) == REGNO (xop10)
> -		&& GET_MODE_CLASS (GET_MODE (xop00)) == MODE_CC
> -		&& GET_MODE_CLASS (GET_MODE (xop10)) == MODE_CC)
> +		&& GET_MODE (xop00) == mode
> +		&& GET_MODE (xop10) == mode
> +		&& GET_MODE_CLASS (mode) == MODE_CC)
>  	      return xop00;
>  	}
>        break;
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr60818.c b/gcc/testsuite/gcc.c-torture/compile/pr60818.c
> new file mode 100644
> index 0000000..b6171bb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr60818.c
> @@ -0,0 +1,5 @@
> +int
> +lx (int oi, int mb)
> +{
> +  return (oi < mb) < (mb < oi);
> +}
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-01  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 22:50 [PATCH] simplify-rtx: Fix compare of comparisons (PR60818) Segher Boessenkool
2017-04-03 17:01 ` Jeff Law
2017-04-03 17:19   ` Segher Boessenkool
2017-05-01  9:13 ` Segher Boessenkool

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).