public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case
@ 2015-05-05  7:24 vries at gcc dot gnu.org
  2015-05-05  7:33 ` [Bug tree-optimization/66013] " vries at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-05  7:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66013
           Summary: Missed optimization after inlining va_list parameter,
                    -m32 case
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

[ -m32 twin PR of PR66010 ]

Consider this test-case (based on gcc.dg/tree-ssa/stdarg-2.c, f15):
...
#include <stdarg.h>

int
f1 (int i, ...)
{
  int res;
  va_list ap;

  va_start (ap, i);
  res = va_arg (ap, int);
  va_end (ap);

  return res;
}

inline int __attribute__((always_inline))
f2_1 (va_list ap)
{
  return va_arg (ap, int);
}

int
f2 (int i, ...)
{
  int res;
  va_list ap;

  va_start (ap, i);
  res = f2_1 (ap);
  va_end (ap);

  return res;
}
...

When compiling at -O2 with -m32, the optimized dump for f1 and f2 are very
similar:
...
   # .MEM_9 = VDEF <.MEM_1(D)>
   # USE = anything 
   # CLB = anything 
-  ap_8 = __builtin_next_argD.993 (0);
-  ap_6 = ap_8;
+  ap_11 = __builtin_next_argD.993 (0);
+  ap_6 = ap_11;
   # PT = nonlocal 
-  ap_7 = ap_6;
+  ap_3 = ap_6;
   # VUSE <.MEM_9>
-  res_4 = MEM[(intD.1 *)ap_7];
+  _7 = MEM[(intD.1 *)ap_3];
   GIMPLE_NOP
   # VUSE <.MEM_9>
-  return res_4;
+  return _7;
 ;;    succ:       EXIT [100.0%] 
...

However, at pass_stdarg, we see on one hand:
...
f1: va_list escapes 0, needs to save 4 GPR units and all FPR units.
...

but OTOH:
...
f2: va_list escapes 1, needs to save all GPR units and all FPR units.
...

Still the .s code is identical for f1 and f2:
...
        .cfi_startproc
        movl    8(%esp), %eax
        ret
        .cfi_endproc
...

This is because ix86_setup_incoming_varargs doesn't do anything for -m32:
...
static void
ix86_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode,
                             tree type, int *, int no_rtl)
{
  CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  CUMULATIVE_ARGS next_cum;
  tree fntype;

  /* This argument doesn't appear to be used anymore.  Which is good,
     because the old code here didn't suppress rtl generation.  */
  gcc_assert (!no_rtl);

  if (!TARGET_64BIT)
    return;
...


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
@ 2015-05-05  7:33 ` vries at gcc dot gnu.org
  2015-05-05  7:34 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-05  7:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from vries at gcc dot gnu.org ---
Before pass_stdarg, we observe in f1 that va_start and va_arg use the same
argument:
...
  # .MEM_2 = VDEF <.MEM_1(D)>
  # USE = nonlocal escaped
  # CLB = nonlocal escaped { D.1806 } (escaped)
  __builtin_va_startD.1021 (&apD.1806, 0);

  # .MEM_3 = VDEF <.MEM_2>
  # USE = nonlocal null { D.1806 } (escaped)
  # CLB = nonlocal null { D.1806 } (escaped)
  res_4 = VA_ARG (&apD.1806, 0B);
...

Before pass_stdarg, we observe in f2 that va_start and va_arg do not use the
same argument:
...
  # .MEM_2 = VDEF <.MEM_1(D)>
  # USE = nonlocal escaped
  # CLB = nonlocal escaped { D.1814 }
  __builtin_va_startD.1021 (&apD.1814, 0);

  # VUSE <.MEM_2>
  # PT = nonlocal
  ap.0_3 = apD.1814;

  # .MEM_4 = VDEF <.MEM_2>
  apD.1830 = ap.0_3;

  # .MEM_8 = VDEF <.MEM_4>
  # USE = nonlocal null { D.1830 } (escaped)
  # CLB = nonlocal null { D.1830 } (escaped)
  _7 = VA_ARG (&apD.1830, 0B);
...


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
  2015-05-05  7:33 ` [Bug tree-optimization/66013] " vries at gcc dot gnu.org
@ 2015-05-05  7:34 ` vries at gcc dot gnu.org
  2015-05-05  7:41 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-05  7:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from vries at gcc dot gnu.org ---
And in the pass_stdarg dump, for f2 we see why the va_list escapes:
...
va_list escapes in # .MEM_4 = VDEF <.MEM_2>
apD.1830 = ap.0_3;
...


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
  2015-05-05  7:33 ` [Bug tree-optimization/66013] " vries at gcc dot gnu.org
  2015-05-05  7:34 ` vries at gcc dot gnu.org
@ 2015-05-05  7:41 ` vries at gcc dot gnu.org
  2015-05-07 22:17 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-05  7:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from vries at gcc dot gnu.org ---
Before postponing expansion of va_arg to pass_stdarg, we had at pass_stdarg:
...
f2: va_list escapes 0, needs to save 4 GPR units and all FPR units.
...

On one hand, the optimization in pass_stdarg has regressed. OTOH, that hasn't
brought a regression in code generation.

So I'm not sure if this should be marked as a '6 Regression', and/or tagged
with missing optimization.


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-05-05  7:41 ` vries at gcc dot gnu.org
@ 2015-05-07 22:17 ` vries at gcc dot gnu.org
  2015-05-08 15:37 ` vries at gcc dot gnu.org
  2015-06-08 12:29 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-07 22:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from vries at gcc dot gnu.org ---
Tentative patch:
...
diff --git a/gcc/tree-stdarg.c b/gcc/tree-stdarg.c
index efabda7..b334e79 100644
--- a/gcc/tree-stdarg.c
+++ b/gcc/tree-stdarg.c
@@ -62,6 +62,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfg.h"
 #include "tree-pass.h"
 #include "tree-stdarg.h"
+#include "tree-ssa.h"

 /* A simple pass that attempts to optimize stdarg functions on architectures
    that need to save register arguments to stack on entry to stdarg functions.
@@ -1111,6 +1112,7 @@ expand_ifn_va_arg_1 (function *fun)

   free_dominance_info (CDI_DOMINATORS);
   update_ssa (TODO_update_ssa);
+  execute_update_addresses_taken ();
 }

 /* Expand IFN_VA_ARGs in FUN, if necessary.  */
...

We just update address_taken between ifn_va_arg expansion and the pass_stdarg
optimization.


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2015-05-07 22:17 ` vries at gcc dot gnu.org
@ 2015-05-08 15:37 ` vries at gcc dot gnu.org
  2015-06-08 12:29 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-05-08 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #5 from vries at gcc dot gnu.org ---
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00685.html


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

* [Bug tree-optimization/66013] Missed optimization after inlining va_list parameter, -m32 case
  2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-05-08 15:37 ` vries at gcc dot gnu.org
@ 2015-06-08 12:29 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2015-06-08 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|patch                       |

--- Comment #6 from vries at gcc dot gnu.org ---
Removing patch keyword. Discussed patch in
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00886.html .


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

end of thread, other threads:[~2015-06-08 12:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-05  7:24 [Bug tree-optimization/66013] New: Missed optimization after inlining va_list parameter, -m32 case vries at gcc dot gnu.org
2015-05-05  7:33 ` [Bug tree-optimization/66013] " vries at gcc dot gnu.org
2015-05-05  7:34 ` vries at gcc dot gnu.org
2015-05-05  7:41 ` vries at gcc dot gnu.org
2015-05-07 22:17 ` vries at gcc dot gnu.org
2015-05-08 15:37 ` vries at gcc dot gnu.org
2015-06-08 12:29 ` vries 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).