]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
simplify-rtx: Simplify `(zero_extend (and x CST))` -> (and (subreg x) CST)
authorAndrew Pinski <quic_apinski@quicinc.com>
Wed, 5 Feb 2025 22:44:25 +0000 (14:44 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sat, 26 Apr 2025 04:09:27 +0000 (21:09 -0700)
This adds the simplification of a ZERO_EXTEND of an AND. This optimization
was already handled in combine via combine_simplify_rtx and the handling
there of compound_operations (ZERO_EXTRACT).

Build and tested for aarch64-linux-gnu.
Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* simplify-rtx.cc (simplify_context::simplify_unary_operation_1) <case ZERO_EXTEND>:
Add simplifcation for and with a constant.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/simplify-rtx.cc

index 88d31a71c05a90e1862b6be8bcd54ad6524e1f0f..06b52ca80037c65ac59d939ea43f4cf9e9976139 100644 (file)
@@ -1709,6 +1709,17 @@ simplify_context::simplify_unary_operation_1 (rtx_code code, machine_mode mode,
       if (GET_MODE (op) == mode)
        return op;
 
+      /* (zero_extend:SI (and:QI X (const))) -> (and:SI (lowpart:SI X) const)
+        where const does not sign bit set. */
+      if (GET_CODE (op) == AND
+         && CONST_INT_P (XEXP (op, 1))
+         && INTVAL (XEXP (op, 1)) > 0)
+       {
+         rtx tem = rtl_hooks.gen_lowpart_no_emit (mode, XEXP (op, 0));
+         if (tem)
+           return simplify_gen_binary (AND, mode, tem, XEXP (op, 1));
+       }
+
       /* Check for a zero extension of a subreg of a promoted
         variable, where the promotion is zero-extended, and the
         target mode is the same as the variable's promotion.  */