https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115777

--- Comment #19 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #18)
> (In reply to Paul Menzel from comment #17)
[..]
> > Should I create a new issue?
> > 
> > [1]: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=bbb4d007316
> 
> No need, it was never fully fixed but as comment#14 suggests only
> -mtune=generic was.  I'll have a look again what happens.

So we're now BB vectorizing the loop body.  Mitigation is still in place:

t.c:12:5: note:   ==> examining statement: _7 = *_6;
t.c:12:5: missed:   using element-wise load to avoid disrupting cross iteration
store-to-load forwarding
t.c:12:5: missed:   not falling back to elementwise accesses
t.c:11:45: missed:   not vectorized: relevant stmt not supported: _7 = *_6;
t.c:12:5: note:   Building vector operands of 0x5373a40 from scalars instead
...
t.c:12:5: note: Costing subgraph:
t.c:12:5: note:    entry instance 0x52f1510 -> node 0x5373990
t.c:12:5: note: node 0x5373990 (refcnt=1) vector(2) unsigned int @*_6 = _4;
t.c:12:5: note: op template: *_3 = _7;
t.c:12:5: note:         stmt 0 *_3 = _7;
t.c:12:5: note:         stmt 1 *_6 = _4;
t.c:12:5: note:         children 0x5373af0
t.c:12:5: note: node 0x5373af0 (refcnt=2) vector(2) unsigned int @_7 = *_6;
t.c:12:5: note: op: VEC_PERM_EXPR
t.c:12:5: note:         stmt 0 _7 = *_6;
t.c:12:5: note:         stmt 1 _4 = *_3;
t.c:12:5: note:         lane permutation { 0[1] 0[0] } 
t.c:12:5: note:         children 0x5373a40
t.c:12:5: note: node (external) 0x5373a40 (refcnt=1) vector(2) unsigned int
(avoid-stlf-fail) @_7 = *_6;
t.c:12:5: note:         stmt 0 _4 = *_3;
t.c:12:5: note:         stmt 1 _7 = *_6;
...
t.c:12:5: note: Scalar cost for part in loop 2
_4 1 times scalar_store costs 12 in body
_7 1 times scalar_store costs 12 in body
t.c:12:5: note: Vector cost for part in loop 2
node 0x5373af0 1 times vec_perm costs 4 in body
node 0x5373a40 1 times vec_construct costs 4 in prologue
_7 1 times unaligned_store (misalign -1) costs 12 in body
t.c:12:5: note: Cost model analysis for whole subgraph:
  Vector cost: 20
  Scalar cost: 24
t.c:12:5: note: Basic block will be vectorized using SLP

and

.L8:
        subq    $4, %rax
.L4:
        movl    (%rax), %ecx
        movl    4(%rax), %edx
        cmpl    %ecx, %edx
        jnb     .L7
        vmovd   %edx, %xmm1
        vpinsrd $1, %ecx, %xmm1, %xmm0
        vmovq   %xmm0, (%rax)
        cmpq    %rax, %rdi
        jne     .L8
.L7:

the vector construct cost is underestimated (the permute cost is
unnecessary - we fail to merge that with the construct), I tested on
Zen where there's an extra penalty for GPR -> xmm;  we anticipate
merging with the loads but the scalar use in the compare prevents
this.  I suspect duplicating the load would speed the testcase up.

What changed from GCC 16 is that we no longer cost the unnecessary

*_6 1 times vec_to_scalar costs 4 in epilogue
*_6 1 times vec_to_scalar costs 4 in epilogue

which made vectorization not profitable there.

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index bc67904f4b9..b3008ee8ddc 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -27994,6 +27994,7 @@ ix86_vector_costs::add_slp_cost (slp_tree node,
             insert it via vpinsr with a memory operand.  */
          if (def
              && gimple_assign_load_p (def)
+             && has_single_use (gimple_assign_lhs (def))
              && tree_nop_conversion_p (TREE_TYPE (op),
                                        TREE_TYPE (gimple_assign_lhs (def)))
              && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op))) > 1

fixes it, properly assessing

node 0x5373a40 gpr->xmm moves costs 24 in prologue
node 0x5373a40 1 times vec_construct costs 4 in prologue

and flipping costs back to unprofitable.

Reply via email to