This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA:] Adjust documentation for LEGITIMATE_CONSTANT_P et al to match reality, take 2
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 08 Oct 2008 20:01:17 +0100
- Subject: Re: [RFA:] Adjust documentation for LEGITIMATE_CONSTANT_P et al to match reality, take 2
- References: <200810052135.m95LZdjY002343@ignucius.se.axis.com>
Here's the patch to remove the (const (minus ...)) code.
Bootstrapped & regression-tested on x86_64-linux-gnu. Also tested
by comparing the before and after assembly output for:
gcc.c-torture gcc.dg g++.dg
on these targets:
powerpc-darwin powerpc64-darwin i386-darwin x86_64-darwin
powerpc-linux-gnu powerpc64-linux-gnu powerpc-ibm-aix5.3.0
using the options "-O2 -fpic". The output was the same.
However, I grepped for all gen_rtx_CONSTs in gcc/, and I noticed
that there are still some dodgy cases in arm, m68hc11, s390 and sh.
(m68hc11's only transgression is to wrap a bare symbol_ref in a const;
it doesn't use minus.) So I'd better fix those before submitting the
patch properly.
For reference, I've also attached a cse patch (not yet tested)
and a patch to the const documentation.
Richard
Index: gcc/gcc/simplify-rtx.c
===================================================================
--- gcc.orig/gcc/simplify-rtx.c 2008-10-08 05:15:29.000000000 +0100
+++ gcc/gcc/simplify-rtx.c 2008-10-08 19:53:13.000000000 +0100
@@ -3678,24 +3678,6 @@ simplify_plus_minus (enum rtx_code code,
one CONST_INT, and the sort will have ensured that it is last
in the array and that any other constant will be next-to-last. */
- if (GET_CODE (ops[n_ops - 1].op) == CONST_INT)
- i = n_ops - 2;
- else
- i = n_ops - 1;
-
- if (i >= 1
- && ops[i].neg
- && !ops[i - 1].neg
- && CONSTANT_P (ops[i].op)
- && GET_CODE (ops[i].op) == GET_CODE (ops[i - 1].op))
- {
- ops[i - 1].op = gen_rtx_MINUS (mode, ops[i - 1].op, ops[i].op);
- ops[i - 1].op = gen_rtx_CONST (mode, ops[i - 1].op);
- if (i < n_ops - 1)
- ops[i] = ops[i + 1];
- n_ops--;
- }
-
if (n_ops > 1
&& GET_CODE (ops[n_ops - 1].op) == CONST_INT
&& CONSTANT_P (ops[n_ops - 2].op))
============================================================================
Index: gcc/gcc/cse.c
===================================================================
--- gcc.orig/gcc/cse.c 2008-10-08 19:54:25.000000000 +0100
+++ gcc/gcc/cse.c 2008-10-08 19:55:42.000000000 +0100
@@ -3170,33 +3170,15 @@ fold_rtx (rtx x, rtx insn)
{
case RTX_UNARY:
{
- int is_const = 0;
-
/* We can't simplify extension ops unless we know the
original mode. */
if ((code == ZERO_EXTEND || code == SIGN_EXTEND)
&& mode_arg0 == VOIDmode)
break;
- /* If we had a CONST, strip it off and put it back later if we
- fold. */
- if (const_arg0 != 0 && GET_CODE (const_arg0) == CONST)
- is_const = 1, const_arg0 = XEXP (const_arg0, 0);
-
new_rtx = simplify_unary_operation (code, mode,
const_arg0 ? const_arg0 : folded_arg0,
mode_arg0);
- /* NEG of PLUS could be converted into MINUS, but that causes
- expressions of the form
- (CONST (MINUS (CONST_INT) (SYMBOL_REF)))
- which many ports mistakenly treat as LEGITIMATE_CONSTANT_P.
- FIXME: those ports should be fixed. */
- if (new_rtx != 0 && is_const
- && GET_CODE (new_rtx) == PLUS
- && (GET_CODE (XEXP (new_rtx, 0)) == SYMBOL_REF
- || GET_CODE (XEXP (new_rtx, 0)) == LABEL_REF)
- && GET_CODE (XEXP (new_rtx, 1)) == CONST_INT)
- new_rtx = gen_rtx_CONST (mode, new_rtx);
}
break;
============================================================================
Index: gcc/gcc/doc/rtl.texi
===================================================================
--- gcc.orig/gcc/doc/rtl.texi 2008-10-08 19:53:13.000000000 +0100
+++ gcc/gcc/doc/rtl.texi 2008-10-08 20:00:03.000000000 +0100
@@ -1582,13 +1582,22 @@ Usually that is the only mode for which
@findex const
@item (const:@var{m} @var{exp})
Represents a constant that is the result of an assembly-time
-arithmetic computation. The operand, @var{exp}, is an expression that
-contains only constants (@code{const_int}, @code{symbol_ref} and
-@code{label_ref} expressions) combined with @code{plus} and
-@code{minus}. However, not all combinations are valid, since the
-assembler cannot do arbitrary arithmetic on relocatable symbols.
+arithmetic computation. The valid values of @var{exp} are:
-@var{m} should be @code{Pmode}.
+@itemize
+@item @samp{(unspec:@var{m} @var{v} @var{c})}
+@item @samp{(plus:@var{m} (unspec:@var{m} @var{v} @var{c}) (const_int @var{offset}))}
+@item @samp{(plus:@var{m} (symbol_ref:@var{m} @var{base}) (const_int @var{offset}))}
+@item @samp{(plus:@var{m} (label_ref:@var{m} @var{base}) (const_int @var{offset}))}
+@end itemize
+
+There is no defined way for target-independent code to tell whether a
+particular @code{unspec} expression can be wrapped in a @code{const}.
+Target-independent code should therefore only create the first two
+forms if it knows that the same @samp{(unspec:@var{m} @var{v} @var{c})}
+occurs somewhere within another @code{const}'s @var{exp}.
+
+@var{m} is usually @code{Pmode}.
@findex high
@item (high:@var{m} @var{exp})