public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [lno] [patch] "while" with unknown loop bound
@ 2004-06-09 15:59 Dorit Naishlos
  0 siblings, 0 replies; 2+ messages in thread
From: Dorit Naishlos @ 2004-06-09 15:59 UTC (permalink / raw)
  To: Olga Golovanevsky; +Cc: Devang Patel, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2096 bytes --]


committed, along with the test-case below.

dorit

(See attached file: tree-ssa-vect-30.c)



                                                                                                                                     
                      Olga Golovanevsky                                                                                              
                                               To:       Dorit Naishlos/Haifa/IBM@IBMIL                                              
                      06/06/2004 15:35         cc:       Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>, Sebastian Pop             
                                                <sebastian.pop@cri.ensmp.fr>, Devang Patel <dpatel@apple. com>,                      
                                                gcc-patches@gcc.gnu.org                                                              
                                               From:     Olga Golovanevsky/Haifa/IBM@IBMIL                                           
                                               Subject:  [lno] [patch] "while" with unknown loop bound                               
                                                                                                                                     



This patch allows vectorizing of "while" loop with unknown loop bound.
Thus, for example, the following loop will vectorize now:

  while (n--) {
    a[i] = b[i];
    i++;
  }

The patch also contains correction in cfg construction for
loop duplication in function tree_duplicate_loop_to_exit_cfg.

Bootstrapped on powerpc-apple-darwin7.0.0.

ChangeLog:

             * tree-vctorizer.c
             (vect_update_initial_conditions_of_duplicated_loop):
             Handle general form of "init" and "step" of access function.
             * tree-ssa-loop-manip.c (tree_duplicate_loop_to_exit_cfg):
             The exit from loop is taken from bb previous to latch instead
             of latch itself.



#### diffJ6_2.txt has been removed from this note on June 09, 2004 by Dorit
Naishlos

[-- Attachment #2: tree-ssa-vect-30.c --]
[-- Type: application/octet-stream, Size: 1295 bytes --]

/* { dg-do run { target powerpc*-*-* } } */
/* { dg-do compile { target i?86-*-* } } */
/* { dg-options "-O2 -ftree-vectorize -fdump-tree-vect-stats -maltivec" { target powerpc*-*-* } } */
/* { dg-options "-O2 -ftree-vectorize -fdump-tree-vect-stats -msse2" { target i?86-*-* } } */

#include <stdarg.h>
#include <signal.h>

#define N 16

float b[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
float a[N];
float c[N];

int main1 (int n)
{
  int i=0;

  /* Vectorized: unknown loop bound.  */
  while (n--) {
    a[i] = b[i];
    i++;
  }

  /* check results:  */
  for (i = 0; i < n; i++)
    {
      if (a[i] != b[i])
        abort ();
    }

  return 0;
}

int main2 (unsigned int n)
{
  int i=0;

  /* Vectorized: unknown loop bound.  */
  while (n--) {
    c[i] = b[i];
    i++;
  }

  /* check results:  */
  for (i = 0; i < n; i++)
    {
      if (c[i] != b[i])
        abort ();
    }

  return 0;
}

void
sig_ill_handler (int sig)
{   
    exit(0);
}

int main (void)
{ 
  /* Exit on systems without altivec.  */
  signal (SIGILL, sig_ill_handler);
  /* Altivec instruction, 'vor %v0,%v0,%v0'.  */
  asm volatile (".long 0x10000484");
  signal (SIGILL, SIG_DFL);
  
  return main1 (N);
  return main2 (N);
}

/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" } } */

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

* [lno] [patch] "while" with unknown loop bound
@ 2004-06-06 13:57 Olga Golovanevsky
  0 siblings, 0 replies; 2+ messages in thread
From: Olga Golovanevsky @ 2004-06-06 13:57 UTC (permalink / raw)
  To: Dorit Naishlos; +Cc: Zdenek Dvorak, Sebastian Pop, Devang Patel, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 738 bytes --]

This patch allows vectorizing of "while" loop with unknown loop bound.
Thus, for example, the following loop will vectorize now:

  while (n--) {
    a[i] = b[i];
    i++;
  }

The patch also contains correction in cfg construction for
loop duplication in function tree_duplicate_loop_to_exit_cfg.

Bootstrapped on powerpc-apple-darwin7.0.0.

ChangeLog:

             * tree-vctorizer.c
             (vect_update_initial_conditions_of_duplicated_loop):
             Handle general form of "init" and "step" of access function.
             * tree-ssa-loop-manip.c (tree_duplicate_loop_to_exit_cfg):
             The exit from loop is taken from bb previous to latch instead
             of latch itself.

(See attached file: diffJ6_2.txt)

[-- Attachment #2: diffJ6_2.txt --]
[-- Type: text/plain, Size: 4394 bytes --]

cvs diff: Diffing .
Index: tree-ssa-loop-manip.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-loop-manip.c,v
retrieving revision 1.1.2.17
diff -c -3 -p -r1.1.2.17 tree-ssa-loop-manip.c
*** tree-ssa-loop-manip.c	29 May 2004 22:09:03 -0000	1.1.2.17
--- tree-ssa-loop-manip.c	6 Jun 2004 12:04:16 -0000
*************** tree_duplicate_loop_to_exit_cfg (struct 
*** 1092,1098 ****
  				 struct loop **new_loop_p)
  {
    struct loop *target;
-   basic_block latch = loop->latch; 
    basic_block *new_bbs, *bbs;
    edge latch_edge;
  
--- 1092,1097 ----
*************** tree_duplicate_loop_to_exit_cfg (struct 
*** 1173,1180 ****
    
    redirect_edge_and_branch_force (loop->exit_edges[0],
  				  new_bbs[0]);
!   set_immediate_dominator (CDI_DOMINATORS, new_bbs[0], latch);
!   set_immediate_dominator (CDI_DOMINATORS, exit_dest, new_loop->latch);
    
    free (new_bbs);
    free (bbs);
--- 1172,1179 ----
    
    redirect_edge_and_branch_force (loop->exit_edges[0],
  				  new_bbs[0]);
!   set_immediate_dominator (CDI_DOMINATORS, new_bbs[0], loop->exit_edges[0]->src); 
!   set_immediate_dominator (CDI_DOMINATORS, exit_dest, new_loop->header);
    
    free (new_bbs);
    free (bbs);
Index: tree-vectorizer.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-vectorizer.c,v
retrieving revision 1.1.2.34
diff -c -3 -p -r1.1.2.34 tree-vectorizer.c
*** tree-vectorizer.c	29 May 2004 22:09:03 -0000	1.1.2.34
--- tree-vectorizer.c	6 Jun 2004 12:04:17 -0000
*************** vect_update_initial_conditions_of_duplic
*** 1357,1363 ****
        tree evolution_part;
        tree init_expr;
        tree step_expr;
!       tree var, stmt, var_name1, var_name2;
        basic_block new_bb;
        int i, num_elem1, num_elem2;
        tree phi1;
--- 1357,1363 ----
        tree evolution_part;
        tree init_expr;
        tree step_expr;
!       tree var, stmt, ni, ni_name;
        basic_block new_bb;
        int i, num_elem1, num_elem2;
        tree phi1;
*************** vect_update_initial_conditions_of_duplic
*** 1386,1418 ****
        step_expr = evolution_part;
        init_expr = initial_condition (access_fn);
  
!       /* create temporary variable */
!       var = create_tmp_var (TREE_TYPE (step_expr), "tmp1");
!       add_referenced_tmp_var (var);
! 
!       var_name1 = make_ssa_name (var, NULL_TREE);
! 
!       stmt = build (MODIFY_EXPR, void_type_node, var_name1,
! 		build (MULT_EXPR, TREE_TYPE (niters),
! 		       niters, step_expr));
  
!       SSA_NAME_DEF_STMT (var_name1) = stmt;
!       new_bb = bsi_insert_on_edge_immediate (pe, stmt);
! 
!       /* We should not generate new bb here, only use already existing one.  */
!       if (new_bb)
! 	abort ();            
!             
!       var = create_tmp_var (TREE_TYPE (init_expr), "tmp2");
        add_referenced_tmp_var (var);
  
!       var_name2 = make_ssa_name (var, NULL_TREE);
! 
!       stmt = build (MODIFY_EXPR, void_type_node, var_name2,
! 		build (PLUS_EXPR, TREE_TYPE (init_expr),
! 		       init_expr, var_name1));
!       
!       SSA_NAME_DEF_STMT (var_name2) = stmt;
        new_bb = bsi_insert_on_edge_immediate (pe, stmt);
  
        /* We should not generate new bb here, only use already existing one.  */
--- 1386,1399 ----
        step_expr = evolution_part;
        init_expr = initial_condition (access_fn);
  
!       ni = build (PLUS_EXPR, TREE_TYPE (init_expr),
! 		  build (MULT_EXPR, TREE_TYPE (niters),
! 		       niters, step_expr), init_expr);
  
!       var = create_tmp_var (TREE_TYPE (init_expr), "tmp");
        add_referenced_tmp_var (var);
  
!       ni_name = force_gimple_operand (ni, &stmt, false, var);
        new_bb = bsi_insert_on_edge_immediate (pe, stmt);
  
        /* We should not generate new bb here, only use already existing one.  */
*************** vect_update_initial_conditions_of_duplic
*** 1433,1439 ****
  		for (i = 0; i < num_elem2; i++)
  		  if (PHI_ARG_DEF (phi1, i) == def)
  		    {
! 		      PHI_ARG_DEF (phi1, i) = var_name2;
  		      PHI_ARG_EDGE (phi1, i) = pe;
  		      break;
   		    }		    
--- 1414,1420 ----
  		for (i = 0; i < num_elem2; i++)
  		  if (PHI_ARG_DEF (phi1, i) == def)
  		    {
! 		      PHI_ARG_DEF (phi1, i) = ni_name;
  		      PHI_ARG_EDGE (phi1, i) = pe;
  		      break;
   		    }		    

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

end of thread, other threads:[~2004-06-09 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-09 15:59 [lno] [patch] "while" with unknown loop bound Dorit Naishlos
  -- strict thread matches above, loose matches on Subject: below --
2004-06-06 13:57 Olga Golovanevsky

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).