https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129273
Bug ID: 129273
Summary: x86: missed inlining of local helpers with different
target_clones lists
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: adamant.pwn at gmail dot com
Target Milestone: ---
Created attachment 66388
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66388&action=edit
Compatible target clones in the ordinary IPA inliner (LLM-generated
experimental diff)
On x86_64-linux, GCC 17 r17-7089 (with the PR95796 fix) emits a jump to the inc
dispatcher in f.avx2 at -std=c23 -O2 -S:
[[gnu::target_clones("default", "sse4.2", "avx")]]
static unsigned inc(unsigned x) { return x + 1; }
[[gnu::target_clones("default", "avx2")]]
unsigned f(unsigned x) { return inc(x); }
Every implementation of inc computes x + 1. Adding avx2 to its clone list lets
GCC emit the addition directly in f.avx2. Could the IPA inliner also consider a
compatible implementation when the clone lists differ?
The attached experiment considers compatible local clones that can stand in for
every possible resolver outcome. It offers the ordinary IPA inliner the
candidate with the lowest estimated inline time, breaking ties by estimated
code growth. All three tie here, and GCC inlines the first (default), producing
lea/ret. If the inliner declines, the original dispatcher call survives.
For loops, the cost of keeping the call can depend on which implementation the
resolver selects. In a population-count benchmark on Zen 4, inlining won at one
word and calling the AVX-512 implementation won at 64. GCC's IPA time estimates
were identical at those two lengths. A separate optimization could dispatch to
a version of the whole loop so that the vectorizer can see the selected helper
body.
Report and experimental diff prepared with OpenAI Codex.