On Thu, Aug 19, 2021 at 4:18 PM Roger Sayle <ro...@nextmovesoftware.com> wrote:
>
>
> Whilst working on a backend patch, I noticed that the middle-end's
> RTL optimizers weren't simplifying a truncation of a paradoxical
> subreg extension, though it does transform closely related (more
> complex) expressions.  The main (first) part of this patch
> implements this simplification, reusing much of the logic already
> in place.
>
> I briefly considered suggesting that it's difficult to provide a new
> testcase for this change, but then realized the reviewer's response
> would be that this type of transformation should be self-tested
> in simplify-rtx, so this patch adds a bunch of tests that integer
> extensions and truncations are simplified as expected.  No good
> deed goes unpunished and I was equally surprised to see that we
> don't currently simplify/check/defend (zero_extend:SI (reg:SI)),
> i.e. useless no-op extensions to the same mode.  So I've added
> some logic to simplify (or more accurately prevent us generating
> dubious RTL for) those.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and "make -k check" with no new failures.
>
> Ok for mainline?

The main target I know of that uses truncate a lot is MIPS64 which has
TARGET_TRULY_NOOP_TRUNCATION defined to be:
static bool
mips_truly_noop_truncation (poly_uint64 outprec, poly_uint64 inprec)
{
  return !TARGET_64BIT || inprec <= 32 || outprec > 32;
}

So you might want to make sure this is still correct for this case.

Thanks,
Andrew Pinski


>
>
> 2021-08-20  Roger Sayle  <ro...@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * simplify-rtx.c (simplify_truncation): Generalize simplification
>         of (truncate:A (subreg:B X)).
>         (simplify_unary_operation_1) [FLOAT_TRUNCATE, FLOAT_EXTEND,
>         SIGN_EXTEND, ZERO_EXTEND]: Handle cases where the operand
>         already has the desired machine mode.
>         (test_scalar_int_ops): Add tests that useless extensions and
>         truncations are optimized away.
>         (test_scalar_int_ext_ops): New self-test function to confirm
>         that truncations of extensions are correctly simplified.
>         (test_scalar_int_ext_ops2): New self-test function to check
>         truncations of truncations, extensions of extensions, and
>         truncations of extensions.
>         (test_scalar_ops): Call the above two functions with a
>         representative sampling of integer machine modes.
>
> Roger
> --
> Roger Sayle
> NextMove Software
> Cambridge, UK
>

Reply via email to