[gcc r17-3535] forwprop: Swap the comparisons for the match and the shift amount equality

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

commit r17-3535-g65814ca6027f373806edd21b0125f87359ebdcf2
Author: Andrea Pinski <[email protected]>
Date:   Fri Aug 21 19:07:46 2026 -0700

    forwprop: Swap the comparisons for the match and the shift amount equality
    
    The current code does:
    ```
      if (gimple_mul_low_sum (sum, sum_ops, NULL)
          && shift_amt == halfwidth)
    ```
    
    But the shift amount check is a much cheaper check than calling
    gimple_mul_low_sum so it should be moved first.
    
    Pushed as obvious after a bootstrapp/test on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * tree-ssa-forwprop.cc (match_long_mul_phi): Swap the shift
            amount check with gimple_mul_low_sum/gimple_mul_cross_sum
            checks.
    
    Signed-off-by: Andrea Pinski <[email protected]>

Diff:
---
 gcc/tree-ssa-forwprop.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 34acbcf033ee..2b832b0041b5 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4700,8 +4700,8 @@ match_long_mul_phi (gphi *phi)
   unsigned HOST_WIDE_INT halfwidth = TYPE_PRECISION (lhs_type) / 2;
   carry.shift = shift_amt;
 
-  if (gimple_mul_low_sum (sum, sum_ops, NULL)
-      && shift_amt == halfwidth)
+  if (shift_amt == halfwidth
+      && gimple_mul_low_sum (sum, sum_ops, NULL))
     {
       /* mul_carry_low_sum's flat form ties the outer lshift amount to
 	 the inner mul_hi's INTEGER_CST@0 via match.pd capture re-use;
@@ -4713,8 +4713,8 @@ match_long_mul_phi (gphi *phi)
       carry.hilo1 = sum_ops[2];
       carry.hilo2 = sum_ops[3];
     }
-  else if (gimple_mul_cross_sum (sum, sum_ops, NULL)
-	   && shift_amt == halfwidth)
+  else if (shift_amt == halfwidth
+	   && gimple_mul_cross_sum (sum, sum_ops, NULL))
     {
       /* mul_cross_sum is just (plus:c @0 @1) with no half-width
 	 constraint.  Gate here to mirror mul_carry_cross_sum;
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.