Re: {patch tree-ssa-math-opts]: Change searching direction for bswap

2011-06-28 Thread Richard Guenther
On Mon, Jun 27, 2011 at 7:33 PM, Kai Tietz kti...@redhat.com wrote:
 Hello,

 this is the separated patch for issues noticed by doing type-sinking on 
 bitwise-operations.  The tests exposed that bswap pattern-matching searches 
 from top to down for each BB. As it replaces the found match for a bswap in 
 tree, but doesn't know about handling its inserted builtin-swap on 
 pattern-matching for wider-mode bswap, search failed.
 By reversing search order within BB from last to first, this issue can be 
 fixed.

 ChangeLog

 2011-06-27  Kai Tietz  kti...@redhat.com

        * tree-ssa-math-opts.c (execute_optimize_bswap): Search
        within BB from last to first.

 Bootstrapped and regression-tested for x86_64-pc-linux-gnu. Ok for apply?

 Regards,
 Kai

 Index: gcc-head/gcc/tree-ssa-math-opts.c
 ===
 --- gcc-head.orig/gcc/tree-ssa-math-opts.c
 +++ gcc-head/gcc/tree-ssa-math-opts.c
 @@ -1820,8 +1820,10 @@ execute_optimize_bswap (void)
   FOR_EACH_BB (bb)
     {
       gimple_stmt_iterator gsi;
 -
 +/*
       for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (gsi))
 + */
 +      for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (gsi))
         {

Err ... please 1) don't comment out stuff this way, 2) add a comment
why we loop backwards

Richard.

          gimple stmt = gsi_stmt (gsi);
          tree bswap_src, bswap_type;



Re: {patch tree-ssa-math-opts]: Change searching direction for bswap

2011-06-28 Thread Kai Tietz
Oh, missed to fill comment.

Thanks,
Kai

Index: gcc-head/gcc/tree-ssa-math-opts.c
===
--- gcc-head.orig/gcc/tree-ssa-math-opts.c
+++ gcc-head/gcc/tree-ssa-math-opts.c
@@ -1821,7 +1821,11 @@ execute_optimize_bswap (void)
 {
   gimple_stmt_iterator gsi;

-  for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (gsi))
+  /* We scan for bswap patterns reverse for making sure we get
+widest match.  As bswap pattern matching doesn't handle
+previously inserted smaller bswap replacements as sub-
+patterns, the wider variant wouldn't be detected.  */
+  for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (gsi))
 {
  gimple stmt = gsi_stmt (gsi);
  tree bswap_src, bswap_type;


Re: {patch tree-ssa-math-opts]: Change searching direction for bswap

2011-06-28 Thread Richard Guenther
On Tue, Jun 28, 2011 at 11:29 AM, Kai Tietz kti...@redhat.com wrote:
 Oh, missed to fill comment.



 Thanks,
 Kai

 Index: gcc-head/gcc/tree-ssa-math-opts.c
 ===
 --- gcc-head.orig/gcc/tree-ssa-math-opts.c
 +++ gcc-head/gcc/tree-ssa-math-opts.c
 @@ -1821,7 +1821,11 @@ execute_optimize_bswap (void)
     {
       gimple_stmt_iterator gsi;

 -      for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (gsi))
 +      /* We scan for bswap patterns reverse for making sure we get

We do a reverse scan for bswap patterns to make sure we get the widest match.

Ok with that change.

Richard.

 +        widest match.  As bswap pattern matching doesn't handle
 +        previously inserted smaller bswap replacements as sub-
 +        patterns, the wider variant wouldn't be detected.  */
 +      for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (gsi))
         {
          gimple stmt = gsi_stmt (gsi);
          tree bswap_src, bswap_type;



{patch tree-ssa-math-opts]: Change searching direction for bswap

2011-06-27 Thread Kai Tietz
Hello,

this is the separated patch for issues noticed by doing type-sinking on 
bitwise-operations.  The tests exposed that bswap pattern-matching searches 
from top to down for each BB. As it replaces the found match for a bswap in 
tree, but doesn't know about handling its inserted builtin-swap on 
pattern-matching for wider-mode bswap, search failed.
By reversing search order within BB from last to first, this issue can be fixed.

ChangeLog

2011-06-27  Kai Tietz  kti...@redhat.com

* tree-ssa-math-opts.c (execute_optimize_bswap): Search
within BB from last to first.

Bootstrapped and regression-tested for x86_64-pc-linux-gnu. Ok for apply?

Regards,
Kai

Index: gcc-head/gcc/tree-ssa-math-opts.c
===
--- gcc-head.orig/gcc/tree-ssa-math-opts.c
+++ gcc-head/gcc/tree-ssa-math-opts.c
@@ -1820,8 +1820,10 @@ execute_optimize_bswap (void)
   FOR_EACH_BB (bb)
 {
   gimple_stmt_iterator gsi;
-
+/*
   for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (gsi))
+ */
+  for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (gsi))
 {
  gimple stmt = gsi_stmt (gsi);
  tree bswap_src, bswap_type;