diff mbox series

[V2] Fix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P

Message ID 20240611144001.2744558-1-hongtao.liu@intel.com
State New
Headers show
Series [V2] Fix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P | expand

Commit Message

liuhongt June 11, 2024, 2:40 p.m. UTC
>
> I think if you only handle CONST_INT_P, you should check just for that, and
> in both places where you check for CONST_VECTOR_DUPLICATE_P (there is one
> spot 2 lines above this).
> So add
> && CONST_INT_P (XVECEXP (XEXP (op0, 1), 0, 0))
> and
> && CONST_INT_P (XVECEXP (op1, 0, 0))
> tests right below those && CONST_VECTOR_DUPLICATE_P (something) tests.
Changed.

The patch add extra check to make sure the component of CONST_VECTOR
is CONST_INT_P.

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?

gcc/ChangeLog:

	PR target/115384
	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
	Only do the simplification of (AND (ASHIFTRT A imm) mask)
	to (LSHIFTRT A imm) when the component of const_vector is
	CONST_INT_P.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr115384.c: New test.
---
 gcc/simplify-rtx.cc                      |  6 ++++--
 gcc/testsuite/gcc.target/i386/pr115384.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr115384.c

Comments

Jakub Jelinek June 11, 2024, 2:43 p.m. UTC | #1
On Tue, Jun 11, 2024 at 10:40:01PM +0800, liuhongt wrote:
> gcc/ChangeLog:
> 
> 	PR target/115384
> 	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
> 	Only do the simplification of (AND (ASHIFTRT A imm) mask)
> 	to (LSHIFTRT A imm) when the component of const_vector is
> 	CONST_INT_P.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/i386/pr115384.c: New test.

LGTM, except

> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr115384.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile { target { ! ia32 } } } */

Maybe just int128 target instead of { ! ia32 } would be more appropriate.

Ok either way.

> +/* { dg-options "-O" } */
> +
> +typedef __attribute__((__vector_size__(sizeof(__int128)))) __int128 W;
> +
> +W w;
> +
> +void
> +foo()
> +{
> +  w = w >> 4 & 18446744073709551600llu;
> +}

	Jakub
diff mbox series

Patch

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 9bc3ef9ad9f..3ee95f74d3d 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4072,9 +4072,11 @@  simplify_context::simplify_binary_operation_1 (rtx_code code,
       if (VECTOR_MODE_P (mode) && GET_CODE (op0) == ASHIFTRT
 	  && (CONST_INT_P (XEXP (op0, 1))
 	      || (GET_CODE (XEXP (op0, 1)) == CONST_VECTOR
-		  && CONST_VECTOR_DUPLICATE_P (XEXP (op0, 1))))
+		  && CONST_VECTOR_DUPLICATE_P (XEXP (op0, 1))
+		  && CONST_INT_P (XVECEXP (XEXP (op0, 1), 0, 0))))
 	  && GET_CODE (op1) == CONST_VECTOR
-	  && CONST_VECTOR_DUPLICATE_P (op1))
+	  && CONST_VECTOR_DUPLICATE_P (op1)
+	  && CONST_INT_P (XVECEXP (op1, 0, 0)))
 	{
 	  unsigned HOST_WIDE_INT shift_count
 	    = (CONST_INT_P (XEXP (op0, 1))
diff --git a/gcc/testsuite/gcc.target/i386/pr115384.c b/gcc/testsuite/gcc.target/i386/pr115384.c
new file mode 100644
index 00000000000..3ba7a0b8115
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115384.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O" } */
+
+typedef __attribute__((__vector_size__(sizeof(__int128)))) __int128 W;
+
+W w;
+
+void
+foo()
+{
+  w = w >> 4 & 18446744073709551600llu;
+}