This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] SPARC ICE fix
- To: rth at cygnus dot com
- Subject: [PATCH] SPARC ICE fix
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Tue, 31 Oct 2000 17:02:56 +0100
- Cc: gcc-patches at gcc dot gnu dot org
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
The testcase below ICEs on SPARC (even with -O0). The reason is that if
gen_addsi3 is called with two const_ints where the former one is SMALL_INT
and the latter one is 4096, then we "optimize" it into (minus (const_int x) (const_int -4096))
but then the const_int does not match register_operand (unlike addsi3,
subsi3 has register_operand for the first one).
arith_operand allows either register_operand or SMALL_INT const_int, so it
is easy to do the addition on the constant and generate movsi.
Similarly with adddi3 (that code is for ARCH64 only, so arith_double_operand
guarantees operands[1] is a SMALL_INT in either CONST_INT or CONST_DOUBLE).
Ok to commit?
2000-10-31 Jakub Jelinek <jakub@redhat.com>
* config/sparc/sparc.md (adddi3): If operands[2] is 4096 and
operands[1] is constant, calculate the sum and generate movdi.
(addsi3): Similarly. Use SImode in call to arith_4096_operand.
(subsi3): Use SImode in call to arith_4096_operand.
* gcc.c-torture/execute/20001031-1.c: New test.
--- gcc/config/sparc/sparc.md.jj Fri Oct 13 16:51:43 2000
+++ gcc/config/sparc/sparc.md Tue Oct 31 16:45:36 2000
@@ -5539,6 +5539,8 @@
""
"
{
+ HOST_WIDE_INT i;
+
if (! TARGET_ARCH64)
{
emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2,
@@ -5551,9 +5553,17 @@
}
if (arith_double_4096_operand(operands[2], DImode))
{
- emit_insn (gen_rtx_SET (VOIDmode, operands[0],
- gen_rtx_MINUS (DImode, operands[1],
- GEN_INT(-4096))));
+ switch (GET_CODE (operands[1])
+ {
+ case CONST_INT: i = INTVAL (operands[1]); break;
+ case CONST_DOUBLE: i = CONST_DOUBLE_LOW (operands[1]); break;
+ default:
+ emit_insn (gen_rtx_SET (VOIDmode, operands[0],
+ gen_rtx_MINUS (DImode, operands[1],
+ GEN_INT(-4096))));
+ DONE;
+ }
+ emit_insn (gen_movdi (operands[0], GEN_INT (i + 4096)));
DONE;
}
}")
@@ -5768,11 +5778,15 @@
""
"
{
- if (arith_4096_operand(operands[2], DImode))
+ if (arith_4096_operand(operands[2], SImode))
{
- emit_insn (gen_rtx_SET (VOIDmode, operands[0],
- gen_rtx_MINUS (SImode, operands[1],
- GEN_INT(-4096))));
+ if (GET_CODE (operands[1]) == CONST_INT)
+ emit_insn (gen_movsi (operands[0],
+ GEN_INT (INTVAL (operands[1]) + 4096)));
+ else
+ emit_insn (gen_rtx_SET (VOIDmode, operands[0],
+ gen_rtx_MINUS (SImode, operands[1],
+ GEN_INT(-4096))));
DONE;
}
}")
@@ -5967,7 +5981,7 @@
""
"
{
- if (arith_4096_operand(operands[2], DImode))
+ if (arith_4096_operand(operands[2], SImode))
{
emit_insn (gen_rtx_SET (VOIDmode, operands[0],
gen_rtx_PLUS (SImode, operands[1],
--- gcc/testsuite/gcc.c-torture/execute/20001031-1.c.jj Tue Oct 31 16:30:36 2000
+++ gcc/testsuite/gcc.c-torture/execute/20001031-1.c Tue Oct 31 16:26:06 2000
@@ -0,0 +1,37 @@
+extern void abort (void);
+extern void exit (int);
+
+void t1 (int x)
+{
+ if (x != 4100)
+ abort ();
+}
+
+int t2 (void)
+{
+ int i;
+ t1 ((i = 4096) + 4);
+ return i;
+}
+
+void t3 (long long x)
+{
+ if (x != 0x80000fffULL)
+ abort ();
+}
+
+long long t4 (void)
+{
+ long long i;
+ t3 ((i = 4096) + 0x7fffffffULL);
+ return i;
+}
+
+main ()
+{
+ if (t2 () != 4096)
+ abort ();
+ if (t4 () != 4096)
+ abort ();
+ exit (0);
+}
Jakub