This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: eliminate dead stores across functions
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: "Bin.Cheng" <amker dot cheng at gmail dot com>
- Cc: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Tue, 6 Mar 2018 17:09:09 +0100
- Subject: Re: eliminate dead stores across functions
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjMkcuch04W94DB06Vv7oYZQPLk2VRN5ALd_0Vt=CmzZ=-w@mail.gmail.com> <CAFiYyc0ZwKqyfX2hyFS+s7tB=gaEJ5OS1zq6BciDFLnn=ynM3w@mail.gmail.com> <CAHFci2_vzxxtSjzSba7z-HZQJx29zJCWHBTTaQABeEytCa0yCw@mail.gmail.com>
On Tue, Mar 6, 2018 at 4:50 PM, Bin.Cheng <amker.cheng@gmail.com> wrote:
> On Tue, Mar 6, 2018 at 2:28 PM, Richard Biener
> <richard.guenther@gmail.com> wrote:
>> On Tue, Mar 6, 2018 at 1:00 PM, Prathamesh Kulkarni
>> <prathamesh.kulkarni@linaro.org> wrote:
>>> Hi,
>>> For the following test-case,
>>>
>>> int a;
>>>
>>> __attribute__((noinline))
>>> static void foo()
>>> {
>>> a = 3;
>>> }
>>>
>>> int main()
>>> {
>>> a = 4;
>>> foo ();
>>> return a;
>>> }
>>>
>>> I assume it's safe to remove "a = 4" since 'a' would be overwritten
>>> by call to foo ?
>>> IIUC, ipa-reference pass does mod/ref analysis to compute side-effects
>>> of function call,
>>> so could we perhaps use ipa_reference_get_not_written_global() in dse
>>> pass to check if a global variable will be killed on call to a
>>> function ? If not, I suppose we could write a similar ipa pass that
>>> computes the set of killed global variables per function but I am not
>>> sure if that's the correct approach.
>>
>> Do you think the situation happens often enough to make this worthwhile?
> There is one probably more useful case. Program may use global flags
> controlling
> how it does (heavy) computation. Such flags are only set couple of
> times in execution
> time. It would be useful if we can (IPA) propagate flags into computation heavy
> functions by versioning (if necessary). For example:
>
> int flag = 1;
> void foo ()
> {
> //heavy computation wrto to flag
> }
> void main()
> {
> flag = 2;
> foo();
> flag = 1;
> foo();
> }
Yeah, libquantum does this. There's also related example
from some SPEC fortran testcase:
vodi foo()
{
static int initialized;
static T data;
if (!initialized)
{
data.x = 1;
initialized = 1;
}
...
}
where we want to constant propagate from data.x. IIRC I tried
to work on this, not sure if I solved it yet...
Richard.
> Of course this may only be useful for LTO.
> Thanks,
> bin
>>
>> ipa-reference doesn't compute must-def, only may-def and may-use IIRC.
>>
>> Richard.
>>
>>> Thanks,
>>> Prathamesh