On 9/2/26 11:51 AM, Wang Yaduo wrote:
Recovered scalar types are needed by the base cost hook, but they must not
trigger vector-specific statement cost adjustments.

gcc/ChangeLog:

        * config/riscv/riscv-vector-costs.cc (costs::add_stmt_cost): Skip
        statement cost adjustments for scalar costing.
---
When costing scalar IL, vectype is null and 32dc4bc recovers a type from
the statement LHS.  The LHS can itself be vector-typed, however, so this
can produce a vectype that is wrong for the scalar cost being computed.

This happens for the 512-element constructor in combine-4.c.  Its root
statement has a vector(512) long int LHS.  Recovering that type while
computing SCALAR_COST lets adjust_stmt_cost apply M8 scaling, raising the
scalar cost from 1 to 8.  An SLP alternative using 512-byte vectors, whose
cost is 6, then appears profitable and expands the constructor through a
4096-byte stack temporary.  This removes one of the four expected
vslideup.vx instructions.

Require m_cost_type != SCALAR_COST before calling adjust_stmt_cost.  The
recovered type is still passed to builtin_vectorization_cost, but cannot
trigger vector-specific adjustments during scalar costing.

Tested the full gcc.target/riscv testsuite on rv64gcv, including execution
tests; no new FAIL, XPASS, UNRESOLVED, or ERROR results versus 32dc4bc^.
Just to be clear, that is not sufficient for a patch to the generic part of the compiler.   For such changes the minimum is to do a bootstrap and regression test on a platform like x86 or aarch64.

FTR, I had already thrown this into my tester several days ago.  So it's been through that bootstrap and regression test on x86_64, aarch64.

I'll take care of pushing it to the trunk.  Thanks.


Jeff


Reply via email to