Hi Richi,

Thanks for the insightful comments!

on 2022/7/1 16:40, Richard Biener wrote:
> On Thu, Jun 23, 2022 at 4:03 AM Kewen.Lin <li...@linux.ibm.com> wrote:
>>
>> Hi,
>>
>> Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596212.html
>>
>> BR,
>> Kewen
>>
>> on 2022/6/6 14:20, Kewen.Lin via Gcc-patches wrote:
>>> Hi,
>>>
>>> PR105459 exposes one issue in inline_call handling that when it
>>> decides to copy FP flags from callee to caller and rebuild the
>>> optimization node for caller fndecl, it's possible that the target
>>> option node is also necessary to be rebuilt.  Without updating
>>> target option node early, it can make nodes share the same target
>>> option node wrongly, later when we want to unshare it somewhere
>>> (like in target hook) it can get unexpected results, like ICE on
>>> uninitialized secondary member of target globals exposed in this PR.
> 
> I think that
> 
>   /* Reload global optimization flags.  */
>   if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
>     set_cfun (cfun, true);
> 
> is supposed to do that via ix86_set_current_function which will eventually
> re-build the target optimization node exactly for this reason.
> 
> But with LTO we arrive here during WPA time only and there cfun is NULL
> (and so is DECL_STRUCT_FUNCTION (to->decl)), so the target doesn't
> get the chance to fix things up here.
> 

Yes, when I read this code, I was thinking if we can do some similar to get
the hook to update target node, but as you pointed out, the cfun is NULL
here.  :(

> Now, it should be fine to delay this fixup until we set the cfun at LTRANS
> time but there we run into
> 
>   if (old_tree != new_tree)
>     {
>       cl_target_option_restore (&global_options, &global_options_set,
>                                 TREE_TARGET_OPTION (new_tree));
> ...
>     }
>   else if (flag_unsafe_math_optimizations
>            != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations
>            || (flag_excess_precision
>                != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision))
>     {
> ... FIXUP! ...
> 
> and old_tree != new_tree disables the fixup.
> 
> When we refactor the above to always consider the FP flag change (so apply it
> lazily), then this fixes the testcase in the PR as well.  Thus something like
> the attached.

Good idea!  Previously following the code for reload_optimization_node, I 
thought
it's good to update the target node information up to date at the same time, but
your proposal with delaying fixup till LTRANS looks better, IIUC WPA passes 
won't
care about this information out of date or not.

> 
> Ideally this stuff would be refactored to a target hook that can work without
> the set_cfun, also working towards merging the target and optimization node
> since they have to be kept in sync ...
> 
> I think your proposed patch makes another variant through the maze to
> do something at WPA time but that makes it all even more complicated :/
> 
> Sorry for the delay btw.
> 

No problem!  Thanks again!!

BR,
Kewen

Reply via email to