On Wed, Sep 11, 2024 at 10:26 AM Eric Botcazou <botca...@adacore.com> wrote:
>
> Hi,
>
> the attached Ada testcase compiled with -O -flto exhibits a wrong code issue
> when the 3 optimizations NRV + RSO + inlining are applied to the same call: if
> the LHS of the call is marked write-only before inlining, then it will keep
> the mark after inlining although it may be read in GIMPLE from that point on.
>
> The proposed fix is to always clear the flag during inlining in the RSO case.
> Tested on x86-64/Linux, OK for the mainline?

Hmm, it looks to me that the IPA analysis marking the variable readonly
in the first place is wrong - or that NRV may not be applied to such a variable
later.  Is NRV ever applied to say

static const S s = ...;

s = foo ();

thus a readonly declared LHS?

I think adjusting the varpool flag just during inline materialization
doesn't resolve
issues that appear when the wrong flag caused other wrong IPA
decisions for example.

Richard.

>
> 2024-09-11  Eric Botcazou  <ebotca...@adacore.com>
>
>         * tree-inline.cc (declare_return_variable): Clear writeonly flag on
>         a global variable used directly as the return slot.
>
> 2024-09-11  Eric Botcazou  <ebotca...@adacore.com>
>
>         * gnat.dg/lto27.adb: New test.
>         * gnat.dg/lto27_pkg1.ads, gnat.dg/lto27_pkg2.ads,
>         gnat.dg/lto27_pkg2.adb, gnat.dg/lto27_pkg3.ads: New helper.
>
>
> --
> Eric Botcazou

Reply via email to