[Bug ipa/68930] New: Aggregate replacements not applied to inline function bodies.
hubicka at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Dec 16 05:48:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68930
Bug ID: 68930
Summary: Aggregate replacements not applied to inline function
bodies.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: hubicka at gcc dot gnu.org
Target Milestone: ---
The following testcase:
struct a
{
int a, b;
};
static inline int
t (struct a a)
{
if (!__builtin_constant_p (a.a))
__builtin_abort ();
}
static int __attribute__ ((noinline)) q (struct a a)
{
t (a);
}
int
main (int argc)
{
struct a a;
int i;
for (i = 0; i < 10000; i++)
{
a.a = 1;
a.b = 2;
q (a);
}
return 0;
}
Fails when compiled with
./xgcc -B ./ -O3 t.c -S -fdump-ipa-cp -fno-ipa-sra -fno-early-inlining
ipa-cp correctly identifies the inlining oppurtunity:
Estimating effects for main/2, base_time: 1588.
Estimating body: main/2
Known to be false:
size:10 time:1588
- context independent values, size: 10, time_benefit: 1
good_cloning_opportunity_p (time: 1, size: 10, freq_sum: 0, single_call)
-> evaluation: 0, threshold: 500
Not cloning for all contexts because !good_cloning_opportunity_p.
Estimating effects for q/1, base_time: 13.
Estimating body: q/1
Known to be false:
size:5 time:13
- context independent values, size: 5, time_benefit: 0
Decided to specialize for all known contexts, code not going to grow.
Estimating effects for t/0, base_time: 5.
Estimating body: t/0
Known to be false: op0[offset: 0] changed
size:4 time:2
- context independent values, size: 4, time_benefit: 3
Decided to specialize for all known contexts, code not going to grow.
however because the ipa-cp adjustments are applied to the body of q before
inlining we end up with:
__attribute__((noinline))
q.constprop (struct a a)
{
struct a a;
int _2;
int _3;
<bb 2>:
a = a;
_2 = a.a;
_3 = __builtin_constant_p (_2);
if (_3 == 0)
goto <bb 3>;
else
goto <bb 4>;
<bb 3>:
__builtin_abort ();
<bb 4>:
return;
}
i.e. we lose the track that a.a==1
Modification phase of node q.constprop/5
Aggregate replacements: 0[0]=1, 0[32]=2
__attribute__((noinline))
q.constprop (struct a a)
{
<bb 3>:
<bb 2>:
t (a);
return;
}
here t is not inlined yet and the clone of t is not modified because it is
inline clone but it should be because it is inline clone of ipa-cp clone.
I wonder if we should not apply the replacements only after inlining. Even if
ipa-cp decided to not clone the callee, inliner might have inlined it and we
ought to use the known constants when optimizing the function body.
More information about the Gcc-bugs
mailing list