public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts
@ 2023-06-16 14:50 hubicka at gcc dot gnu.org
  2023-06-16 14:59 ` [Bug tree-optimization/110289] " hubicka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-06-16 14:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

            Bug ID: 110289
           Summary: Phiprop may be good idea in early opts
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

libstdc++ in push_back operation does equivalent of the following:

int max(int a, int b)
{
        int *ptr;
        if (a > b)
          ptr = &a;
        else
          ptr = &b;
        return *ptr;
}

this is a sily implementation of max operation that sadly is not optimized
until late phiprop pass and confuses inlining heuristics: memory load is
considered to be expensive.

I think this is win-win pass and not very expensive, so perhaps adding it to
early opts is possible?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/110289] Phiprop may be good idea in early opts
  2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
@ 2023-06-16 14:59 ` hubicka at gcc dot gnu.org
  2023-06-16 15:32 ` hubicka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-06-16 14:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

--- Comment #1 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
This is caused by the way libstdc++ defines max:

    constexpr
    inline const _Tp&
    max(const _Tp& __a, const _Tp& __b)
    {
      if (__a < __b)
 return __b;
      return __a;
    }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/110289] Phiprop may be good idea in early opts
  2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
  2023-06-16 14:59 ` [Bug tree-optimization/110289] " hubicka at gcc dot gnu.org
@ 2023-06-16 15:32 ` hubicka at gcc dot gnu.org
  2023-06-16 18:01 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-06-16 15:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
This patch fixes the problem
diff --git a/gcc/passes.def b/gcc/passes.def
index c9a8f19747b..faa5208b26b 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -88,6 +88,8 @@ along with GCC; see the file COPYING3.  If not see
          /* pass_build_ealias is a dummy pass that ensures that we
             execute TODO_rebuild_alias at this point.  */
          NEXT_PASS (pass_build_ealias);
+         /* Do phiprop before FRE so we optimize std::min and std::max well. 
*/
+         NEXT_PASS (pass_phiprop);
          NEXT_PASS (pass_fre, true /* may_iterate */);
          NEXT_PASS (pass_early_vrp);
          NEXT_PASS (pass_merge_phi);
diff --git a/gcc/tree-ssa-phiprop.cc b/gcc/tree-ssa-phiprop.cc
index 3cb4900b6be..5dc505df420 100644
--- a/gcc/tree-ssa-phiprop.cc
+++ b/gcc/tree-ssa-phiprop.cc
@@ -476,6 +476,7 @@ public:
   {}

   /* opt_pass methods: */
+  opt_pass * clone () final override { return new pass_phiprop (m_ctxt); }
   bool gate (function *) final override { return flag_tree_phiprop; }
   unsigned int execute (function *) final override;


and helps PR110287

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/110289] Phiprop may be good idea in early opts
  2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
  2023-06-16 14:59 ` [Bug tree-optimization/110289] " hubicka at gcc dot gnu.org
  2023-06-16 15:32 ` hubicka at gcc dot gnu.org
@ 2023-06-16 18:01 ` pinskia at gcc dot gnu.org
  2023-06-19  6:52 ` rguenth at gcc dot gnu.org
  2023-06-23 16:09 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-16 18:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2023-06-16
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this should definitely run after early inline in the early optimizations
because of C++ code.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/110289] Phiprop may be good idea in early opts
  2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-06-16 18:01 ` pinskia at gcc dot gnu.org
@ 2023-06-19  6:52 ` rguenth at gcc dot gnu.org
  2023-06-23 16:09 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-19  6:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
probably makes sense, yes.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/110289] Phiprop may be good idea in early opts
  2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-06-19  6:52 ` rguenth at gcc dot gnu.org
@ 2023-06-23 16:09 ` hubicka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-06-23 16:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110289

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Phiprop was enabled in g:7b34cacc5735385e7e2855d7c0a6fad60ef4a99b

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-23 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 14:50 [Bug tree-optimization/110289] New: Phiprop may be good idea in early opts hubicka at gcc dot gnu.org
2023-06-16 14:59 ` [Bug tree-optimization/110289] " hubicka at gcc dot gnu.org
2023-06-16 15:32 ` hubicka at gcc dot gnu.org
2023-06-16 18:01 ` pinskia at gcc dot gnu.org
2023-06-19  6:52 ` rguenth at gcc dot gnu.org
2023-06-23 16:09 ` hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).