https://gcc.gnu.org/g:5715865108d7e76bea4cceace38e91b9a28558f8

commit r16-1517-g5715865108d7e76bea4cceace38e91b9a28558f8
Author: Jiawei <jia...@iscas.ac.cn>
Date:   Fri Jun 13 18:25:56 2025 +0800

    simplify-rtx.cc:Simplify XOR(AND(ROTATE(~1) A) ASHIFT(1 A)) to IOR.
    
    This patch adds a new simplification rule to `simplify-rtx.cc` that
    handles a common bit manipulation pattern involving a single-bit set
    and clear followed by XOR.
    
    The transformation targets RTL of the form:
    
      (xor (and (rotate (~1) A) B) (ashift 1 A))
    
    which is semantically equivalent to:
    
      B | (1 << A)
    
    - v3 log:
      Update RTL format, remove commas.
      Only apply on SHIFT_COUNT_TRUNCATED target.
      check '!side_effects_p' on XEXP (op1, 1).
    
    gcc/ChangeLog:
    
            * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): 
Handle
            more logical simplifications.

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

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index b34fd2f4b9ea..cbe61b49bf69 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4063,6 +4063,20 @@ simplify_context::simplify_binary_operation_1 (rtx_code 
code,
          && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1))
        return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
 
+      /* Convert (xor (and (rotate (~1) A) B) (ashift 1 A))
+        into B | (1 << A).  */
+      if (SHIFT_COUNT_TRUNCATED
+         && GET_CODE (op0) == AND
+         && GET_CODE (XEXP (op0, 0)) == ROTATE
+         && CONST_INT_P (XEXP (XEXP (op0, 0), 0))
+         && INTVAL (XEXP (XEXP (op0, 0), 0)) == -2
+         && GET_CODE (op1) == ASHIFT
+         && CONST_INT_P (XEXP (op1, 0))
+         && INTVAL (XEXP (op1, 0)) == 1
+         && rtx_equal_p (XEXP (XEXP (op0, 0), 1), XEXP (op1, 1))
+         && !side_effects_p (XEXP (op1, 1)))
+       return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
+
       tem = simplify_with_subreg_not (code, mode, op0, op1);
       if (tem)
        return tem;

Reply via email to