Bug 116562 - wrong cost of gather load preventing loop from vectored
Summary: wrong cost of gather load preventing loop from vectored
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2024-09-02 00:14 UTC by kugan
Modified: 2024-09-02 12:56 UTC (History)
2 users (show)

See Also:
Host:
Target: aarch64
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kugan 2024-09-02 00:14:17 UTC
typedef int real_t;
extern __attribute__((aligned(64))) real_t a[32000],b[32000],c[32000],d[32000];

void s4117()
{
  for (int i = 0; i < 32000; i++) {
      a[i] = b[i] + c[i/2] * d[i];
  }
}
is not vectored for AdvSIMD due to wrong cost calculation.

Compiler option used: cc1plus -Ofast -fdump-tree-vect-all -mcpu=neoverse-v2 --param=aarch64-autovec-preference=1

tt.c:6:21: note:  Cost model analysis:
  Vector inside of loop cost: 64
  Vector prologue cost: 0
  Vector epilogue cost: 0
  Scalar iteration cost: 15
  Scalar outside cost: 0
  Vector outside cost: 0
  prologue iterations: 0
  epilogue iterations: 0
tt.c:6:21: missed:  cost model: the vector iteration cost = 64 divided by the scalar iteration cost = 15 is greater or equal to the vectorization factor = 4.
tt.c:6:21: missed:  not vectorized: vectorization not profitable.
tt.c:6:21: missed:  not vectorized: vector version will never be profitable.
tt.c:6:21: missed:  Loop costings may not be worthwhile.
tt.c:6:21: note:  ***** Analysis failed with vector mode V4SI



We cost this c[i/2] as having the cost of 4 loads and one construct. I think we should special case these sort of gather loads which as lower cost in practice?

11233                   if (costing_p)
11234                     {
11235                       /* For emulated gathers N offset vector element
11236                          offset add is consumed by the load).  */
11237                       inside_cost = record_stmt_cost (cost_vec, const_nunits,
11238                                                       vec_to_scalar, stmt_info,
11239                                                       0, vect_body);
11240                       /* N scalar loads plus gathering them into a
11241                          vector.  */
11242                       inside_cost
11243                         = record_stmt_cost (cost_vec, const_nunits, scalar_load,
11244                                             stmt_info, 0, vect_body);
11245                       inside_cost
11246                         = record_stmt_cost (cost_vec, 1, vec_construct,
11247                                             stmt_info, 0, vect_body);
11248                       continue;
11249                     }
Comment 1 Andrew Pinski 2024-09-02 03:40:56 UTC
I think I saw the same effect on another testcase too.
Comment 3 Richard Biener 2024-09-02 12:56:21 UTC
But it's emulated so exactly what we emit?