https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114711
Bug ID: 114711 Summary: Missed optimization: fold load of global constant array if there is obivous pattern Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- Godbolt link: https://godbolt.org/z/MMxoGaj9T ``` static char* const names[3] = {"abc", "cdf", "dsadsa"}; char** const id2name[3] = {names, names + 1, names + 2}; void* src(size_t idx){ return id2name[idx]; } ``` can be folded to: ``` static char* const names[3] = {"abc", "cdf", "dsadsa"}; void* tgt(size_t idx){ return names + idx; } ``` This is a real pattern from openssl.