[gcc/devel/ranger] riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333)

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 18:09:11 GMT 2020


https://gcc.gnu.org/g:bd0a3e244d94ad4a5e41f01ebf285f0861cb4a03

commit bd0a3e244d94ad4a5e41f01ebf285f0861cb4a03
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 21 21:43:03 2020 +0100

    riscv: Fix up riscv_rtx_costs for RTL checking (PR target/93333)
    
    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.
    
    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.

Diff:
---
 gcc/ChangeLog                                 |  6 ++++++
 gcc/config/riscv/riscv.c                      |  5 ++++-
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/compile/pr93333.c | 10 ++++++++++
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e2f3d0db2cd..e7ae5bbefa1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
 2020-01-21  Richard Sandiford  <richard.sandiford@arm.com>
 
 	* config/aarch64/aarch64-sve-builtins.def: Use get_typenode_from_name
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 573024074e3..e0205c66f26 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1642,7 +1642,10 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
 
     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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b164f3156c7..e8561cca412 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93333
+	* gcc.c-torture/compile/pr93333.c: New test.
+
 2020-01-21  Sandra Loosemore  <sandra@codesourcery.com>
 
 	* g++.dg/coroutines/torture/mid-suspend-destruction-0.C: Generalize
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93333.c b/gcc/testsuite/gcc.c-torture/compile/pr93333.c
new file mode 100644
index 00000000000..801959bea75
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr93333.c
@@ -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;
+}


More information about the Gcc-cvs mailing list