https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125567
Bug ID: 125567
Summary: SLP build misses operand swapping for a commutative
scalar-vector add pattern
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: chenzhongyao.hit at gmail dot com
CC: rdapp at gcc dot gnu.org, rguenth at gcc dot gnu.org
Target Milestone: ---
I found this while refining the RISC-V RVV cost model.
This looks like a pre-existing SLP missed optimization for commutative operand
matching/swapping.
A small reproducer is here:
https://godbolt.org/z/vdz59bbKE
dump log shows:
/app/example.c:13:21: note: node 0x2cdfa9d0 (max_nunits=8, refcnt=2)
vector(8) unsigned short
/app/example.c:13:21: note: op template: _9 = _7 + tmp.1_8;
/app/example.c:13:21: note: stmt 0 _9 = _7 + tmp.1_8;
/app/example.c:13:21: note: stmt 1 _18 = tmp.1_8 + _17;
/app/example.c:13:21: note: stmt 2 _27 = tmp.1_8 + _26;
/app/example.c:13:21: note: stmt 3 _36 = tmp.1_8 + _35;
/app/example.c:13:21: note: stmt 4 _45 = tmp.1_8 + _44;
/app/example.c:13:21: note: stmt 5 _54 = tmp.1_8 + _53;
/app/example.c:13:21: note: stmt 6 _63 = tmp.1_8 + _62;
/app/example.c:13:21: note: stmt 7 _72 = tmp.1_8 + _71;
/app/example.c:13:21: note: stmt 8 _81 = tmp.1_8 + _80;
/app/example.c:13:21: note: stmt 9 _90 = tmp.1_8 + _89;
/app/example.c:13:21: note: stmt 10 _99 = tmp.1_8 + _98;
/app/example.c:13:21: note: stmt 11 _108 = tmp.1_8 + _107;
/app/example.c:13:21: note: stmt 12 _117 = tmp.1_8 + _116;
/app/example.c:13:21: note: stmt 13 _126 = tmp.1_8 + _125;
/app/example.c:13:21: note: stmt 14 _135 = tmp.1_8 + _134;
/app/example.c:13:21: note: stmt 15 _144 = tmp.1_8 + _143;
/app/example.c:13:21: note: children 0x2cdfaa88 0x2cdfacb0
......
......
app/example.c:13:34: note: Build SLP for _7 = (unsigned short) _6;
/app/example.c:13:34: note: Build SLP for tmp.1_8 = (unsigned short) tmp_154;
/app/example.c:13:34: note: vect_is_simple_use: operand *_5, type of def:
internal
/app/example.c:13:34: note: vect_is_simple_use: operand tmp_178 ^ 63, type of
def: internal
/app/example.c:13:34: note: starting SLP discovery for node 0x2cdfaf90
/app/example.c:13:34: note: get vectype for scalar type (group size 2): i16
/app/example.c:13:34: note: vectype: vector(2) short int
/app/example.c:13:34: note: nunits = 2
/app/example.c:13:34: note: Build SLP for _6 = *_5;
/app/example.c:13:34: note: Build SLP for tmp_154 = tmp_178 ^ 63;
/app/example.c:13:34: missed: Build SLP failed: different operation in stmt
tmp_154 = tmp_178 ^ 63;
/app/example.c:13:34: missed: original stmt _6 = *_5;
/app/example.c:13:34: note: SLP discovery for node 0x2cdfaf90 failed
I don't yet know the root cause. I am trying to debug & fix it.