[gcc r17-3526] match: Use match to match mult for mul_ladder_sum1 [PR126954]

Andrea Pinski via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:ac1c1f64e11b84ba6a5e8dbef4589f8369df7d08

commit r17-3526-gac1c1f64e11b84ba6a5e8dbef4589f8369df7d08
Author: Andrea Pinski <[email protected]>
Date:   Thu Aug 20 23:37:54 2026 -0700

    match: Use match to match mult for mul_ladder_sum1 [PR126954]
    
    While reading match patterns I noticed that currently
    mul_ladder_sum1 does this:
    ```
        @mul_hilo1)
      (with {
        tree_code mul_hilo_code = TREE_CODE (@mul_hilo1);
        tree_code rhs_code = ERROR_MARK;
        if (mul_hilo_code == SSA_NAME)
          {
            gimple *def = SSA_NAME_DEF_STMT (@mul_hilo1);
            if (def && gimple_code (def) == GIMPLE_ASSIGN)
              rhs_code = gimple_assign_rhs_code (def);
          } }
      (if (rhs_code == MULT_EXPR))))
    ```
    
    Which is exactly the same thing if the match pattern did:
        (mult@mul_hilo1 @2 @3)))
    
    Which is easier to understand and will use the valueizier if
    there is one instead of a straight walk backwards on the ssa names.
    
    I also checked the generated code from genmatch to see it was similar
    in what was done manually.
    
    Pushed as obvious after a bootstrap/test for x86_64-linux-gnu.
    
            PR tree-optimization/126954
    
    gcc/ChangeLog:
    
            * match.pd (mul_ladder_sum1): Change over to match syntax
            instead of doing it manually.
    
    Signed-off-by: Andrea Pinski <[email protected]>

Diff:
---
 gcc/match.pd | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 51f825ec3279..4e28b5d9ded0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -12916,17 +12916,7 @@ and,
     (plus:c
       (mul_lo @mul_hilo0 INTEGER_CST@0)
       (mul_hi (mul_lolo @op0 @op1 INTEGER_CST@0) INTEGER_CST@1))
-    @mul_hilo1)
-  (with {
-    tree_code mul_hilo_code = TREE_CODE (@mul_hilo1);
-    tree_code rhs_code = ERROR_MARK;
-    if (mul_hilo_code == SSA_NAME)
-      {
-	gimple *def = SSA_NAME_DEF_STMT (@mul_hilo1);
-	if (def && gimple_code (def) == GIMPLE_ASSIGN)
-	  rhs_code = gimple_assign_rhs_code (def);
-      } }
-  (if (rhs_code == MULT_EXPR))))
+    (mult@mul_hilo1 @2 @3)))
 /* Partial ladder sum: (xl*yl >> N) + hilo.  */
 (match (mul_ladder_part_sum @op0 @op1 @mul_hilo0 @0 @1)
   (plus:c
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.