https://gcc.gnu.org/g:9b9d605d68cf27a24e8ed9d4f1ead1f00131cec1

commit r16-100-g9b9d605d68cf27a24e8ed9d4f1ead1f00131cec1
Author: Jan Hubicka <hubi...@ucw.cz>
Date:   Wed Apr 23 17:04:32 2025 +0200

    Cost truth_value exprs in i386 vectorizer costs.
    
    this patch implements costing of truth_value exprs.  I.e.
      a = b < c;
    Those seems to be now the most common operations that goes to the addss path
    except for in->fp and fp->int conversions.
    
    For integer we use setcc, for FP there is CMccSS and variants which sets the
    destination register a s a mast (i.e. -1 on true and 0 on false).  
Technically
    these needs res&1 to get into 1 on true, 0 on false, but looking on examples
    where this is used, it is common that the resulting code is optimized 
avoiding
    need for this (except for cases wehre result is directly saved to memory).
    For this reason I am accounting only one sse_op (CMccSS) itself.
    
    gcc/ChangeLog:
    
            * config/i386/i386.cc (ix86_vector_costs::add_stmt_cost): Cost 
truth_value
            exprs.

Diff:
---
 gcc/config/i386/i386.cc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index aef41454d9d5..3b4dfd9a9903 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -25464,7 +25464,25 @@ ix86_vector_costs::add_stmt_cost (int count, 
vect_cost_for_stmt kind,
          else
            stmt_cost = ix86_cost->add;
          break;
+
        default:
+         if (truth_value_p (subcode))
+           {
+             if (SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
+               /* CMPccS? insructions are cheap, so use sse_op.  While they
+                  produce a mask which may need to be turned to 0/1 by and,
+                  expect that this will be optimized away in a common case.  */
+               stmt_cost = ix86_cost->sse_op;
+             else if (X87_FLOAT_MODE_P (mode))
+               /* fcmp + setcc.  */
+               stmt_cost = ix86_cost->fadd + ix86_cost->add;
+             else if (VECTOR_MODE_P (mode))
+               stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
+             else
+               /* setcc.  */
+               stmt_cost = ix86_cost->add;
+             break;
+           }
          break;
        }
     }

Reply via email to