Bug 63556 - gcc should dedup string postfixes
Summary: gcc should dedup string postfixes
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2014-10-16 08:53 UTC by Andi Kleen
Modified: 2024-04-11 00:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andi Kleen 2014-10-16 08:53:49 UTC
With this code:

extern void func(char *a, char *b);

void f(void)
{
        func("abc", "xabc");
        func("abc", "abc");
}

we get:

.LC0:
        .string "xabc"
.LC1:
        .string "abc"

So the "abc"s get deduped. But it could also dedup the postfix by pointing "abc" to "xabc" + 1. This would save some space.
Comment 1 Richard Biener 2014-10-16 09:07:23 UTC
Confirmed.  Constant/literal pool also misses merging V2DF { 0., 0. } with
DF 0. for example (and more).  There's another PR for that somewhere with
some hackish patch from me.
Comment 2 Andreas Schwab 2014-10-16 09:27:49 UTC
This is done by the linker, as part of the merge section handling.

Contents of section .rodata:
 4005b0 01000200 78616263 00                 ....xabc.