This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix i386 legitimize_address (PR target/21297)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 2 May 2005 09:41:06 -0400
- Subject: [PATCH] Fix i386 legitimize_address (PR target/21297)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
i386.c legitimize_address "canonicalizes" ASHIFTs by 1, 2, 4, 8
into MULT by the same value, on the testcase below particularly
(plus:SI (ashift:SI (reg/v:SI 60 [ i ])
(const_int 1 [0x1]))
(reg/v/f:SI 61 [ x ]))
is "legitimized" into
(plus:SI (mult:SI (reg/v:SI 60 [ i ])
(const_int 1 [0x1]))
(reg/v/f:SI 61 [ x ]))
and
(plus:SI (ashift:SI (reg/v:SI 58 [ i ])
(const_int 2 [0x2]))
(reg/v/f:SI 59 [ x ]))
into
(plus:SI (mult:SI (reg/v:SI 58 [ i ])
(const_int 2 [0x2]))
(reg/v/f:SI 59 [ x ]))
The code in question has been there this way at least since day1
of egcs CVS.
Ok for 4.0/HEAD if bootstrap/regtesting succeeds?
Although this testcase doesn't exhibit this bug on 3.4 and earlier,
the bug is there, should we fix this in older GCCs as well?
2005-05-02 Jakub Jelinek <jakub@redhat.com>
PR target/21297
* config/i386/i386.c (legitimize_address): When canonicalizing
ASHIFT into MULT, multiply by 1 << shift_count instead of
1 << log2 (shift_count).
--- gcc/config/i386/i386.c.jj 2005-04-25 11:56:21.000000000 +0200
+++ gcc/config/i386/i386.c 2005-05-02 14:56:24.000000000 +0200
@@ -5902,9 +5902,10 @@ legitimize_address (rtx x, rtx oldx ATTR
/* Canonicalize shifts by 0, 1, 2, 3 into multiply */
if (GET_CODE (x) == ASHIFT
&& GET_CODE (XEXP (x, 1)) == CONST_INT
- && (log = (unsigned) exact_log2 (INTVAL (XEXP (x, 1)))) < 4)
+ && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
{
changed = 1;
+ log = INTVAL (XEXP (x, 1));
x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
GEN_INT (1 << log));
}
@@ -5915,9 +5916,10 @@ legitimize_address (rtx x, rtx oldx ATTR
if (GET_CODE (XEXP (x, 0)) == ASHIFT
&& GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
- && (log = (unsigned) exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4)
+ && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
{
changed = 1;
+ log = INTVAL (XEXP (XEXP (x, 0), 1));
XEXP (x, 0) = gen_rtx_MULT (Pmode,
force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
GEN_INT (1 << log));
@@ -5925,9 +5927,10 @@ legitimize_address (rtx x, rtx oldx ATTR
if (GET_CODE (XEXP (x, 1)) == ASHIFT
&& GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
- && (log = (unsigned) exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4)
+ && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
{
changed = 1;
+ log = INTVAL (XEXP (XEXP (x, 1), 1));
XEXP (x, 1) = gen_rtx_MULT (Pmode,
force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
GEN_INT (1 << log));
--- gcc/testsuite/gcc.c-torture/execute/20050502-2.c.jj 2005-05-02 15:09:29.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20050502-2.c 2005-05-02 15:07:17.000000000 +0200
@@ -0,0 +1,34 @@
+/* PR target/21297 */
+typedef __SIZE_TYPE__ size_t;
+extern int memcmp (const char *, const char *, size_t);
+extern void abort ();
+
+void
+foo (char *x)
+{
+ int i;
+ for (i = 0; i < 2; i++);
+ x[i + i] = '\0';
+}
+
+void
+bar (char *x)
+{
+ int i;
+ for (i = 0; i < 2; i++);
+ x[i + i + i + i] = '\0';
+}
+
+int
+main (void)
+{
+ char x[] = "IJKLMNOPQR";
+ foo (x);
+ if (memcmp (x, "IJKL\0NOPQR", sizeof x) != 0)
+ abort ();
+ x[4] = 'M';
+ bar (x);
+ if (memcmp (x, "IJKLMNOP\0R", sizeof x) != 0)
+ abort ();
+ return 0;
+}
Jakub