public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333)
@ 2020-01-21 10:12 Jakub Jelinek
  2020-01-21 19:05 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-01-21 10:12 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-patches

Hi!

As mentioned in the PR, during combine rtx_costs can be called sometimes
even on RTL that has not been validated yet and so can contain even operands
that aren't valid in any instruction.

The following patch ought to fix this case, ok for trunk?

2020-01-21  Jakub Jelinek  <jakub@redhat.com>

	PR target/93333
	* config/riscv/riscv.c (riscv_rtx_costs) <case ZERO_EXTRACT>: Verify
	the last two operands are CONST_INT_P before using them as such.

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

--- gcc/config/riscv/riscv.c.jj	2020-01-21 09:14:07.500268371 +0100
+++ gcc/config/riscv/riscv.c	2020-01-21 09:27:37.629974828 +0100
@@ -1642,7 +1642,10 @@ riscv_rtx_costs (rtx x, machine_mode mod
 
     case ZERO_EXTRACT:
       /* This is an SImode shift.  */
-      if (outer_code == SET && (INTVAL (XEXP (x, 2)) > 0)
+      if (outer_code == SET
+	  && CONST_INT_P (XEXP (x, 1))
+	  && CONST_INT_P (XEXP (x, 2))
+	  && (INTVAL (XEXP (x, 2)) > 0)
 	  && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (x, 2)) == 32))
 	{
 	  *total = COSTS_N_INSNS (SINGLE_SHIFT_COST);
--- gcc/testsuite/gcc.c-torture/compile/pr93333.c.jj	2020-01-21 09:27:25.710155732 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr93333.c	2020-01-21 09:27:08.234420958 +0100
@@ -0,0 +1,10 @@
+/* PR target/93333 */
+
+unsigned
+foo (int b, int c, int d, unsigned long e, int x, int y, int g, int h,
+     unsigned i)
+{
+  e >>= b;
+  i >>= e & 31;
+  return i & 1;
+}

	Jakub

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

* Re: [PATCH] riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333)
  2020-01-21 10:12 [PATCH] riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333) Jakub Jelinek
@ 2020-01-21 19:05 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2020-01-21 19:05 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

On Tue, Jan 21, 2020 at 12:36 AM Jakub Jelinek <jakub@redhat.com> wrote:
> 2020-01-21  Jakub Jelinek  <jakub@redhat.com>
>
>         PR target/93333
>         * config/riscv/riscv.c (riscv_rtx_costs) <case ZERO_EXTRACT>: Verify
>         the last two operands are CONST_INT_P before using them as such.
>
>         * gcc.c-torture/compile/pr93333.c: New test.

Yes, this is OK.  I've already tested it with rtl-checking enabled builds.

Jim

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

end of thread, other threads:[~2020-01-21 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 10:12 [PATCH] riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333) Jakub Jelinek
2020-01-21 19:05 ` Jim Wilson

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