[Bug target/60520] stack adjustment are not merged anymore

2014-03-21 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

  Attachment #32399|0   |1
is obsolete||

--- Comment #13 from H.J. Lu hjl.tools at gmail dot com ---
Created attachment 32427
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32427action=edit
A patch with a target hook


[Bug target/60520] stack adjustment are not merged anymore

2014-03-19 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

  Attachment #32353|0   |1
is obsolete||

--- Comment #12 from H.J. Lu hjl.tools at gmail dot com ---
Created attachment 32399
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32399action=edit
An updated patch

This patch passed regression test on Linux/x86-64
and Linux/x86.  I am not sure if this patch is x86
specific.  If it is, we can turn it into a target hook.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-14 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #5 from Richard Biener rguenth at gcc dot gnu.org ---
(In reply to H.J. Lu from comment #4)
 This change:
 
 diff --git a/gcc/function.c b/gcc/function.c
 index a61e475..3b6718f 100644
 --- a/gcc/function.c
 +++ b/gcc/function.c
 @@ -6238,6 +6238,7 @@ thread_prologue_and_epilogue_insns (void)
   }
 /* Now duplicate the tails.  */
 if (!bitmap_empty_p (bb_tail))
 + {
   FOR_EACH_BB_REVERSE_FN (bb, cfun)
 {
   basic_block copy_bb, tbb;
 @@ -6304,6 +6305,17 @@ thread_prologue_and_epilogue_insns (void)
   if (bitmap_empty_p (bb_tail))
 break;
 }
 +
 + /* Basic blocks may have been changed.  Merge each basic block
 +with its successor if possible.  */
 + FOR_EACH_BB_FN (bb, cfun)
 +   if (single_succ_p (bb))
 + {
 +   basic_block succ_bb = single_succ (bb);
 +   if (can_merge_blocks_p (bb, succ_bb))
 + merge_blocks (bb, succ_bb);
 + }
 + }
   }
  
  fail_shrinkwrap:
 
 seems to work.

We have cfg_cleanup for this, no?

[Bug target/60520] stack adjustment are not merged anymore

2014-03-14 Thread jakub at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

Jakub Jelinek jakub at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||jakub at gcc dot gnu.org
 Resolution|--- |FIXED

--- Comment #6 from Jakub Jelinek jakub at gcc dot gnu.org ---
Furthermore, it is already fixed since r208551.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-14 Thread ubizjak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #7 from Uroš Bizjak ubizjak at gmail dot com ---
(In reply to Jakub Jelinek from comment #6)
 Furthermore, it is already fixed since r208551.

Indeed, the fix for PR57320 also fixed this one.

[Bug target/60520] stack adjustment are not merged anymore

2014-03-14 Thread jakub at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

Jakub Jelinek jakub at gcc dot gnu.org changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 CC||rth at gcc dot gnu.org
 Resolution|FIXED   |---

--- Comment #10 from Jakub Jelinek jakub at gcc dot gnu.org ---
Supposedly csa pass could remove sp additions followed by setting of sp to
something not based on sp?


[Bug target/60520] stack adjustment are not merged anymore

2014-03-14 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #11 from H.J. Lu hjl.tools at gmail dot com ---
Created attachment 32353
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32353action=edit
A patch

This patch checks LEAVE and remove stack deallocation.
It removes 5 stack deallocations in cc1plus on Linux/i686.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-13 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2014-03-13
 CC||hjl.tools at gmail dot com
 Ever confirmed|0   |1

--- Comment #1 from H.J. Lu hjl.tools at gmail dot com ---
It is due to

commit 283bfef29552fdda30d92acff64cf38f210a1e58
Author: hubicka hubicka@138bc75d-0d04-0410-961f-82ee72b054a4
Date:   Thu Jan 23 00:12:56 2014 +

  * config/i386/x86-tune.def (X86_TUNE_ACCUMULATE_OUTGOING_ARGS):
  Enable for generic and recent AMD targets.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206947
138bc75d-0d04-0410-961f-82ee72b054a4

Adding -maccumulate-outgoing-args restores the old behavior.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-13 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #2 from H.J. Lu hjl.tools at gmail dot com ---
pro_and_epilogue adds an epilogue after BB 4:

(insn 12 11 15 3 (parallel [
(set (reg/f:SI 7 sp)
(plus:SI (reg/f:SI 7 sp)
(const_int 16 [0x10])))
(clobber (reg:CC 17 flags))
]) pr60520.c:7 265 {*addsi_1}
 (expr_list:REG_ARGS_SIZE (const_int 0 [0])
(nil)))
;;  succ:   4 [100.0%]  (FALLTHRU)
;; lr  out  7 [sp]

;; basic block 4, loop depth 0, count 0, freq 3898, maybe hot
;;  prev block 3, next block 6, flags: (REACHABLE, RTL, MODIFIED)
;;  pred:   3 [100.0%]  (FALLTHRU)
;; bb 4 artificial_defs: { }
;; bb 4 artificial_uses: { u-1(7){ }}
;; lr  in   7 [sp]
;; lr  use  7 [sp]
;; lr  def 
(code_label 15 12 16 4 1  [0 uses])
(note 16 15 27 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
(note 27 16 28 4 NOTE_INSN_EPILOGUE_BEG)
(insn/f 28 27 32 4 (parallel [
(set (reg/f:SI 7 sp)
(plus:SI (reg/f:SI 7 sp)
(const_int 12 [0xc])))
(clobber (reg:CC 17 flags))
(clobber (mem:BLK (scratch) [0  A8]))
]) pr60520.c:8 -1
 (expr_list:REG_CFA_ADJUST_CFA (set (reg/f:SI 7 sp)
(plus:SI (reg/f:SI 7 sp)
(const_int 12 [0xc])))
(nil)))
;;  succ:   6 [100.0%]  (FALLTHRU)
;; lr  out  7 [sp]

It is quite hard to optimize 2 stack adjustment cross basic blocks.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-13 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #3 from H.J. Lu hjl.tools at gmail dot com ---
With -O -m32 -fno-shrink-wrap, I got

test:
.LFB0:
.cfi_startproc
subl$12, %esp
.cfi_def_cfa_offset 16
movlbar, %eax
cmpl$0, (%eax)
je.L1
subl$12, %esp
.cfi_def_cfa_offset 28
pushl%eax
.cfi_def_cfa_offset 32
callfoo
addl$16, %esp
.cfi_def_cfa_offset 16
.L1:
addl$12, %esp
.cfi_def_cfa_offset 4
ret

shrink-wrap doesn't add epilogue in such a way that stack
adjustment can be easily optimized.


[Bug target/60520] stack adjustment are not merged anymore

2014-03-13 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60520

--- Comment #4 from H.J. Lu hjl.tools at gmail dot com ---
This change:

diff --git a/gcc/function.c b/gcc/function.c
index a61e475..3b6718f 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -6238,6 +6238,7 @@ thread_prologue_and_epilogue_insns (void)
 }
   /* Now duplicate the tails.  */
   if (!bitmap_empty_p (bb_tail))
+{
 FOR_EACH_BB_REVERSE_FN (bb, cfun)
   {
 basic_block copy_bb, tbb;
@@ -6304,6 +6305,17 @@ thread_prologue_and_epilogue_insns (void)
 if (bitmap_empty_p (bb_tail))
   break;
   }
+
+/* Basic blocks may have been changed.  Merge each basic block
+   with its successor if possible.  */
+FOR_EACH_BB_FN (bb, cfun)
+  if (single_succ_p (bb))
+{
+  basic_block succ_bb = single_succ (bb);
+  if (can_merge_blocks_p (bb, succ_bb))
+merge_blocks (bb, succ_bb);
+}
+}
 }

 fail_shrinkwrap:

seems to work.