Bug 104466 - Inlining functions with restrict parameters can inhibit lim (e.g. in 554.roms_r)
Summary: Inlining functions with restrict parameters can inhibit lim (e.g. in 554.roms_r)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks: spec
  Show dependency treegraph
 
Reported: 2022-02-09 13:53 UTC by Martin Jambor
Modified: 2022-05-06 11:37 UTC (History)
0 users

See Also:
Host: x86_64-linux
Target: x86_64-linux
Build:
Known to work: 12.0
Known to fail:
Last reconfirmed: 2022-02-09 00:00:00


Attachments
Test-case (844 bytes, text/plain)
2022-02-09 14:57 UTC, Martin Jambor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Jambor 2022-02-09 13:53:29 UTC
We have noticed that a bit more performance can be squeezed out of
554.roms_r benchmark from the SPEC 2017 FPrate suite by using option
-fno-inline-functions-called-once, even at -O2 (but also at -Ofast).
At least one potential reason is that without inlining, loop invariant
motion is able to disambiguate memory references better because of
restrict qualified parameters.  When it cannot, it can be observed by
lim not taking place, at -O2 at least (which in turn affects other
passes).

I tried to create a small-ish reproducer and am attaching the result.
Compile with: -std=legacy -O2 --param max-inline-insns-auto=0 --param max-inline-insns-single=0  

with and without -fno-inline-functions-called-once and look for lim of
a load from array n in the lim2 dump.
Comment 1 Martin Jambor 2022-02-09 14:57:13 UTC
Created attachment 52393 [details]
Test-case

Forgotten testcase
Comment 2 Richard Biener 2022-02-09 15:14:47 UTC
I will have a look.
Comment 3 Andrew Pinski 2022-02-09 18:53:27 UTC
Isn't this a dup of bug 60712?
Comment 4 Richard Biener 2022-02-10 08:03:27 UTC
Bah, what stupid cut&paste error ...



diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index d434446a997..3e8d2455ba5 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2420,12 +2420,12 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
          rbase2 = TREE_OPERAND (rbase2, 0);
     }
   if (rbase1 && rbase2
-      && (TREE_CODE (base1) == MEM_REF || TREE_CODE (base1) == TARGET_MEM_REF)
-      && (TREE_CODE (base2) == MEM_REF || TREE_CODE (base2) == TARGET_MEM_REF)
+      && (TREE_CODE (rbase1) == MEM_REF || TREE_CODE (rbase1) == TARGET_MEM_REF)
+      && (TREE_CODE (rbase2) == MEM_REF || TREE_CODE (rbase2) == TARGET_MEM_REF)
       /* If the accesses are in the same restrict clique... */
-      && MR_DEPENDENCE_CLIQUE (base1) == MR_DEPENDENCE_CLIQUE (base2)
+      && MR_DEPENDENCE_CLIQUE (rbase1) == MR_DEPENDENCE_CLIQUE (rbase2)
       /* But based on different pointers they do not alias.  */
-      && MR_DEPENDENCE_BASE (base1) != MR_DEPENDENCE_BASE (base2))
+      && MR_DEPENDENCE_BASE (rbase1) != MR_DEPENDENCE_BASE (rbase2))
     return false;
 
   ind1_p = (TREE_CODE (base1) == MEM_REF
Comment 5 Richard Biener 2022-02-10 08:16:59 UTC
So yes, __restrict info _does_ survive inlining.
Comment 6 Richard Biener 2022-02-10 08:33:24 UTC
The typos have been there and unnoticed since the original r5-5305 ... :/
Comment 7 GCC Commits 2022-02-10 09:55:08 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:1b72d456b2a88218ed440655ef0b9e29b4ef63a9

commit r12-7173-g1b72d456b2a88218ed440655ef0b9e29b4ef63a9
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Feb 10 09:03:48 2022 +0100

    tree-optimization/104466 - fix cut&paste error perventing alias disambiguation
    
    The following fixes a cut&paste error in disambiguating using restrict
    info.  Instead of using the for this purpose computed rbase1/rbase2
    which preserve MEM_REF bases even when they are based on a decl the
    code performs the check on the bases that drop info for those ...
    
    2022-02-10  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/104466
            * tree-ssa-alias.cc (refs_may_alias_p_2): Use rbase1/rbase2
            for the MR_DEPENDENCE checks as intended.
    
            * gfortran.dg/pr104466.f90: New testcase.
Comment 8 Richard Biener 2022-02-10 09:55:52 UTC
Fixed on trunk, I'm considering backporting to GCC 11 eventually.
Comment 9 Richard Biener 2022-05-06 11:37:29 UTC
Fixed for GCC 12, not backporting.