This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Constant fold "bitop" builtins at the tree-level.
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 Aug 2003 19:36:17 -0600 (MDT)
- Subject: Re: [PATCH] Constant fold "bitop" builtins at the tree-level.
Hi Richard,
On Mon, 25 Aug 2003, Richard Henderson wrote:
> On Sun, Aug 24, 2003 at 09:01:40PM -0600, Roger Sayle wrote:
> > Whilst I was working on this patch, I also noticed that the CONST_DOUBLE
> > forms of the CLZ and CTZ RTL simplifiers weren't honoring the target
> > macros CLZ_DEFINED_VALUE_AT_ZERO and CTZ_DEFINED_VALUE_AT_ZERO. These
> > macros are already being honored in the CONST_INT RTL simplifiers.
>
> A zero const_double would be non-canonical.
Indeed. I must admit that I hadn't originally considered that.
However, it turns out that these hunks are still needed as the code
controlling that section is governed by:
> /* We can do some operations on integer CONST_DOUBLEs. Also allow
> for a DImode operation on a CONST_INT. */
> else if (GET_MODE (trueop) == VOIDmode
> && width <= HOST_BITS_PER_WIDE_INT * 2
> && (GET_CODE (trueop) == CONST_DOUBLE
> || GET_CODE (trueop) == CONST_INT))
> {
> unsigned HOST_WIDE_INT l1, lv;
> HOST_WIDE_INT h1, hv;
>
> if (GET_CODE (trueop) == CONST_DOUBLE)
> l1 = CONST_DOUBLE_LOW (trueop), h1 = CONST_DOUBLE_HIGH (trueop);
> else
> l1 = INTVAL (trueop), h1 = HWI_SIGN_EXTEND (l1);
So it looks like the code above is catching the explicit case where the
canonical form of an operand is a CONST_INT rather than a CONST_DOUBLE.
I'm guessing I used completely the wrong terminology in my description
of the patch. I should have used the phrase "DImode forms of clz and
ctz". Actually, I think even that's wrong: DImode is a target concept
whilst HOST_WIDE_INT is a host concept. It should really be "when the
argument is wider than HOST_WIDE_INT".
How about exactly the same patch with the following revised ChangeLog?
2003-08-25 Roger Sayle <roger@eyesopen.com>
* builtins.c (fold_builtin_bitop): New function to perform constant
folding of ffs, clz, ctz, popcount and parity builtin functions
and their long and long long variants (such as ffsl and ffsll).
(fold_builtin): fold_builtin_bitop when appropriate.
* simplify-rtx.c (simplify_unary_operation): Honor both
CLZ_DEFINED_VALUE_AT_ZERO and CTZ_DEFINED_VALUE_AT_ZERO when
evaluating clz and ctz at compile-time, for operands wider
than HOST_WIDE_INT.
Sorry for the confusion.
Roger
--