public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-15 22:42 Robert Dewar
  2004-03-15 23:08 ` Richard Henderson
  0 siblings, 1 reply; 38+ messages in thread
From: Robert Dewar @ 2004-03-15 22:42 UTC (permalink / raw)
  To: alexr, rth; +Cc: gcc

> (1) MIN/MAX have better floating-point properties than conditional move.
>     Consider 
> 
>         a = 0; b = NaN;
> 
>         c = a < b ? b : a;              // 0
>     vs
>         c = a > b ? a : b;              // NaN
>     vs
>         c = max(a, b);                  // Undefined

Does the C standard really specify that the < and > here are unordered
comparisons? 

^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-16 12:27 Robert Dewar
  2004-03-16 18:32 ` Richard Henderson
  0 siblings, 1 reply; 38+ messages in thread
From: Robert Dewar @ 2004-03-16 12:27 UTC (permalink / raw)
  To: dewar, rth; +Cc: alexr, gcc

> I might possibly agree to that for C99 (since there is a standardized
> way to accomplish the stated goal), but not for C89.

I don't understand the argument for C89. Why prevent a useful
optimization in order to enable incorrect code that just happens 
to work to keep working.

^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-16  5:33 Robert Dewar
  2004-03-16  6:54 ` Richard Henderson
  0 siblings, 1 reply; 38+ messages in thread
From: Robert Dewar @ 2004-03-16  5:33 UTC (permalink / raw)
  To: dewar, rth; +Cc: alexr, gcc

> However, if fp exceptions are disabled (as they ususally are),
> then the above will work as shown for almost all targets.

Yes, but they are not required to work, so the fact that they happen to
work is not a legitimate reason to avoid optimization.

^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-16  3:46 Chris Lattner
  0 siblings, 0 replies; 38+ messages in thread
From: Chris Lattner @ 2004-03-16  3:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc, Diego Novillo, Devang Patel


Richard Henderson wrote:
> This mere fact might argue for the creation of a boolean temporary for
> the comparison.

FWIW, this is exactly what we do in LLVM (all binary branches and select
instructions require a boolean argument, not a conditional).  Also,
amusingly we have a select instruction that acts exactly as was described
and even has the same name, though I do know you chose to use "COND_EXPR"
as the name in the end.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/

^ permalink raw reply	[flat|nested] 38+ messages in thread
* Fw: [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-14 10:57 Dorit Naishlos
  2004-03-14 19:22 ` Andrew Pinski
  0 siblings, 1 reply; 38+ messages in thread
From: Dorit Naishlos @ 2004-03-14 10:57 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc, Devang Patel

> I will also be doing the following soon (after MIN/MAX becomes gimple
> which has already be discussed and approved):

I seem to have missed the MIN/MAX discussion thread. Do you have a link to
that, or was it off the mailing list? just curious when is it planned to
add the MIN/MAX tree codes to gimple and who is responsible for that?

> But I have not thought about the if-conversions which you are asking
> for yet.

Since the ABS, MIN/MAX, etc. are special cases of the if-conversion we are
proposing, it looks like there will be an overlap between what we plan to
implement, and the transformations that will take place during phiopt,
which made us wonder whether it would make sense to implement our
transformation during phiopt as well. For example, in the case of ABS:

bb0:
      x = src[i]
      if (x < 0) GOTO BB1
            else GOTO BB2
bb1:
      x' = -x
bb2:
      x'' = PHI <x', x>
      dst[i] = x''

In the general case, the if-conversion we're proposing would transform it
into:

bb0:
      x = src[i]
      C = CMP (x < 0)
      x' = -x
      x'' = "SELECT" C, x', x
      dst[i] = x''

and in special cases (like ABS, saturation, etc) we would then (or before
hand) detect the special pattern and further optimize it as follows:

bb0:
      x = src[i]
      x'' = ABS x
      dst[i] = x''

Our main concern is that we don't know that this transformation is
desirable in the general case - we know its desirable when it enables
vectorization, but we're not sure we want to be blindly replacing
IF-THEN-ELSE's with SELECT's (or COND_EXPR) all over the place (it would
result in doing a lot of transform-IF-THEN-ELSE-into-SELECT during phiopt
followed by expand-SELECT-into-IF-THEN-ELSE during RTL expand).

Therefore, we originally thought of creating the "SELECT" patterns just
before the vectorizer, in places that are candidate for vectorization
(loops), and revert them back to if-then-else right after vectorization if
they don't get vectorized. This way, "SELECT"s will only be present after
vectorization, and only in vector form (operating on vector data types),
which is somewhat less intrusive (only passes that come after vectorization
may encounter SELECTs, and we also won't need to worry about expanding
SELECTs back to if-the-else during RTL expand).

However, considering that a lot of ifcvt functionality is going to take
place in phiopt, maybe phiopt is the right place for our ifcvt after all?
this way, there would be only one pass that performs all ifcvt-related
opts, and no danger of duplicating work (we don't want to end up
implementing a pass that will become obsolete as phiopt pass is being
enhanced). Please advise...

thanks,
Dorit and Devang



                                                                                                                                
                      Andrew Pinski                                                                                             
                      <pinskia@physics.        To:       Devang Patel <dpatel@apple.com>                                        
                      uc.edu>                  cc:       "gcc@gcc.gnu.org list" <gcc@gcc.gnu.org>, Dorit                        
                                                Naishlos/Haifa/IBM@IBMIL, Andrew Pinski <pinskia@physics.uc.edu>                
                      04/03/2004 22:12         Subject:  Re: [lno] [RFC] if-conversion and auto vectorizer                      
                                                                                                                                




There are already some if-conversions on the tree-ssa right now, they
are
called PHI OPTs and in tree-ssa-phiopt.c, I am trying to add some more
right
now but they most likely will be added to the LNO branch after an other
merge from the tree-ssa branch.

Right now on the tree-ssa the following optimization is done:
if (a == b) 1 else 0 into a == b

Right now I add the following:

if (a >= 0) a else -a into ABS (a).
if (a != b) a else b into a.

I will also be doing the following soon (after MIN/MAX becomes gimple
which has already be discussed and approved):
if (a >= b) a else b into MAX (a, b)
if (a <= b) a else b into MIN (a, b).

But I have not thought about the if-conversions which you are asking
for yet.

Thanks,
Andrew Pinski




^ permalink raw reply	[flat|nested] 38+ messages in thread
* [lno] [RFC] if-conversion and auto vectorizer
@ 2004-03-04 19:59 Devang Patel
  2004-03-04 20:12 ` Andrew Pinski
  2004-03-04 21:03 ` Richard Henderson
  0 siblings, 2 replies; 38+ messages in thread
From: Devang Patel @ 2004-03-04 19:59 UTC (permalink / raw)
  To: gcc@gcc.gnu.org list; +Cc: Dorit Naishlos

We are planning to add an if-conversion pass at the tree-ssa level, that
would collapse if-then-else control flow constructs into straight line
conditional code. The primary goal of this transformation is to  
facilitate
vecorization of loops that contain if-then-else constructs (as  
described on
the vectorizer's todo list:
http://gcc.gnu.org/projects/tree-ssa/vectorization.html#cond
http://gcc.gnu.org/projects/tree-ssa/ 
vectorization.html#IdiomRecognition).

This is what we have in mind:

The if-conversion pass will transform control dependency such as this:
EXAPLE1:
       if (x > 0)
         a = y
       else
         a = z
into data dependency, such as this:
EXAMPLE2:
       a = y if (x > 0)
       a = z if !(x > 0)
The most intuitive way to express the conditional operations is with
predication, but people had already mentioned that there aren't many
tree-codes available, so adding a conditional/predicated form to a lot  
of
tree-codes would probably not be feasible. Therefore, we were planning  
to
express conditional operations using only a single new tree-code:  
SELECT.
i.e, the above code would be transformed into:
EXAMPLE3:
       c = compare (x > 0)
       a1 = y
       a2 = z
       a = select a1, a2, c

Replacing "if" statements with straight line scalar operations prior to
vectorization pass will allow the vectorizer to continue applying the
simple scheme of one-to-one replacement of scalar operations with vector
operations.

We would need to address the issues of handling such {compare/select}
sequences for architectures that have a different kind of support for
conditional code (e.g. predication, masking), probably in the RTL  
expander?

Since it is mostly intended as a preprocessing pass for the vectorizer,  
we
were thinking to apply it only to loops, and revert it if vectorization
wasn't successful (using loop versioning). Is there a benefit in trying  
to
apply this to any if-then-else in the function? it seemed to us that
applying such a transformation in the general case would be driven by
considerations that are too low level for the tree-level.

Speaking of low level - from a brief look at the current RTL level
if-conversion it seems that there isn't much potential to reuse pieces  
of
that code. Are there parts of the current RTL level if-conversion pass  
that
can be adapted to achieve the functionality we described above at tree
level?

We welcome any comments/suggestions

thanks,

Dorit and Devang.

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

end of thread, other threads:[~2004-03-16 23:37 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-15 22:42 [lno] [RFC] if-conversion and auto vectorizer Robert Dewar
2004-03-15 23:08 ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2004-03-16 12:27 Robert Dewar
2004-03-16 18:32 ` Richard Henderson
2004-03-16 22:51   ` Toon Moene
2004-03-16 23:10     ` Joseph S. Myers
2004-03-16 23:28       ` Toon Moene
2004-03-16 23:37     ` Richard Henderson
2004-03-16 23:42       ` Toon Moene
2004-03-16  5:33 Robert Dewar
2004-03-16  6:54 ` Richard Henderson
2004-03-16  3:46 Chris Lattner
2004-03-14 10:57 Fw: " Dorit Naishlos
2004-03-14 19:22 ` Andrew Pinski
2004-03-14 22:31   ` Daniel Berlin
2004-03-15  2:29   ` Alex Rosenberg
2004-03-15 22:38     ` Richard Henderson
2004-03-15 23:08       ` Devang Patel
2004-03-15 23:20         ` Richard Henderson
2004-03-16  0:02           ` Devang Patel
2004-03-16  0:07             ` Diego Novillo
2004-03-16  0:45               ` Richard Henderson
2004-03-16  3:02                 ` Diego Novillo
2004-03-16  3:33                   ` Richard Henderson
2004-03-16  6:33                     ` Devang Patel
2004-03-04 19:59 Devang Patel
2004-03-04 20:12 ` Andrew Pinski
2004-03-04 20:39   ` Devang Patel
2004-03-04 21:03 ` Richard Henderson
2004-03-05 19:06   ` Devang Patel
2004-03-05 19:17     ` Diego Novillo
2004-03-05 19:22       ` Diego Novillo
2004-03-05 19:28       ` Devang Patel
2004-03-05 19:41         ` Diego Novillo
2004-03-05 19:44           ` Diego Novillo
2004-03-12 18:45             ` Devang Patel
2004-03-13  9:24               ` Zdenek Dvorak
2004-03-13 22:41                 ` Devang Patel
2004-03-14 10:59                 ` Dorit Naishlos

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