https://gcc.gnu.org/g:3456cc8dba75ea71ca099df75372f763bdb86d22

commit r17-3866-g3456cc8dba75ea71ca099df75372f763bdb86d22
Author: Roger Sayle <[email protected]>
Date:   Wed Sep 2 16:42:27 2026 +0100

    simplify-rtx: Canonicalize bswap (bitreverse x) as bitreverse (bswap x)
    
    This patch implements an RTL simplification (to help bitreverse on cris)
    which is for simplify-rtx and combine to canonicalize bswap(bitreverse x)
    as bitreverse(bswap x).  The two forms are equivalent, so canonicalizing
    simplifies machine descriptions.  The (otherwise arbitrary) choice to
    perform BSWAP first, is (1) to aid targets like powerpc that can perform
    bswap on load and (2) to place bswap next to bswap on targets that split
    bitreverse in a similar order to GCC's default optab expansion.
    
    2026-09-02  Roger Sayle  <[email protected]>
    
    gcc/ChangeLog
            * simplify-rtx.cc (simplify_unary_operation_1) <case BSWAP>:
            Canonicalize (BSWAP (BITREVERSE x)) as (BITREVERSE (BSWAP x)).

Diff:
---
 gcc/simplify-rtx.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 66d7bb8d88a8..38c8abfe3e78 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -1505,6 +1505,12 @@ simplify_context::simplify_unary_operation_1 (rtx_code 
code, machine_mode mode,
       /* (bswap (bswap x)) -> x.  */
       if (GET_CODE (op) == BSWAP)
        return XEXP (op, 0);
+      /* Canonicalize (bswap (bitreverse x)) as (bitreverse (bswap x)).  */
+      if (GET_CODE (op) == BITREVERSE)
+       return simplify_gen_unary (BITREVERSE, mode,
+                                  simplify_gen_unary (BSWAP, mode,
+                                                      XEXP (op, 0), mode),
+                                  mode);
       break;
 
     case BITREVERSE:

Reply via email to