public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Exploiting dual mode operation
@ 2004-06-07 17:17 Mircea Namolaru
  0 siblings, 0 replies; 8+ messages in thread
From: Mircea Namolaru @ 2004-06-07 17:17 UTC (permalink / raw)
  To: gcc; +Cc: joern.rennecke, Leehod Baruch

Hello,

Following our message ( http://gcc.gnu.org/ml/gcc/2004-04/msg00970.html )
regarding expoiting dual mode operations, we enclose an overview of our 
algorithm.

In order to support 32 bit computations on a 64 bit machine, sign 
extension
instructions are generated to ensure the correctness of the computation.
A possible policy (currently implemented in gcc) is to generate a sign
extension after each 32 bit computation. Depending on the instruction set 
of
the architecture some of these sign extension instructions may be 
redundant.

There are two cases:

Case1: 
The instruction using the 64bit operands (after they are sign-extended)
has a dual mode that works with 32bit operands.

For example:

int32 a, b;

a = ....                               a = ....
a = sign extend a          <-->
b = ....                               b = ....
b = sign extend a          <-->

cmpd a, b                              cmpw a, b  //half word compare

Case2:
The instruction defining the 64bit operand (which is later sign-extended)
has a dual mode that defines and sign-extends a 32bit operand.

For example:

int32 a;

ld a                                   lwa a     // load half and sign 
extend
a = sign extend a          <-->

return a                               return a


We'll present the algorithm on the following example:

Example:

We have two definitions of int32, and multiple uses as below:
Source:

                         def1           def2
                          | \           / |
                          |  \         /  |
                          |   \       /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                        use1    use12    use2

Assume that only a single sign extend (se) instruction is needed on the 
path
between def1 and use12 - for all other paths, the se can be combined with
either the def or the use.

0. Initial code, as currently generated by gcc.
   (There are sign extension after each definition)

                         def1           def2
                          se             se
                          | \           / |
                          |  \         /  |
                          |   \       /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                        use1    use12    use2

1. Combine
1.a prepare for combine 
   (Redundant) sign extensions generated also before uses.

                         def1           def2
                          se             se
                          | \           / |
                          |  \         /  |
                          |   \       /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                         se      se       se
                        use1    use12    use2


1.b combine
   - Combine tries to merge se's with defs and with uses.
   Assume it succeeds for def2 and use1:

                         def1           def2
                          se            [se removed]
                          | \           / |
                          |  \         /  |
                          |   \       /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                   [se removed]  se       se
                        use1    use12    use2

2. PRE
2.a  prepare for PRE
  - if combine did not remove an se after a def (as in def1), we remove it 
now
  (recall that it is redundant) - PRE should compute an optimal placement 
of
  se's which may or may not include this after-the-def location.
  - if combine did remove an se after a def (as in def2), we want PRE to 
know
  that the new def contains an se, so that it will remove other redundant 
se's.
  So we regenerate the se explicitly, and remove it eventually.

  - Note that if combine removed an se before a use, this use no longer 
requires
  an se, so PRE needs not consider this use any longer (and hence we do 
not
  regenerate the se).

                         def1           def2
                     [se removed]        se [regenerated]
                          | \           / |
                          |  \         /  |
                          |   \       /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                                 se       se
                        use1    use12    use2

2.b PRE
   An optimal placement is:

                         def1           def2
                                         se [regenerated]
                          | \           / |
                          |  \         /  |
                          |   se      /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                        use1    use12    use2

4. Cleanup
   - The regenerated sign extension after def2 is removed.

                         def1           def2
                                     [se removed] 
                          | \           / |
                          |  \         /  |
                          |   se      /   |
                          |    \     /    |
                          |     \   /     |
                          |      \ /      |
                        use1    use12    use2

Finally we got the best placement for the sign extensions as required.

We will soon post part of code for review. 

Comments welcomed. Thanks,

Mircea and Leehod


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Exploiting dual mode operation
@ 2004-04-22 13:58 Leehod Baruch
  2004-04-22 14:59 ` Joern Rennecke
  0 siblings, 1 reply; 8+ messages in thread
From: Leehod Baruch @ 2004-04-22 13:58 UTC (permalink / raw)
  To: Joern Rennecke; +Cc: gcc, Mircea Namolaru

Hello,

Thank you for your message.

We see redundant sign extension removal as a partial 
redundancy problem. This will give us not only the redundant 
sign extensions, but also better placement for the 
remaining ones. As a result sign extension instructions 
may be moved and instructions that uses the highpart
may be replaced with others that doesn't use it.

This is not equivalent with live information for the highest 
part of the registers. 

Our approach will not require changes in the description file 
(which in our opinion is a major problem with your code) and will 
limit the changes to much fewer files.

Leehod and Mircea 






Joern Rennecke <joern.rennecke@superh.com>
21/04/2004 09:26 PM
 
        To:     Mircea Namolaru/Haifa/IBM@IBMIL
        cc:     gcc@gcc.gnu.org, Leehod Baruch/Haifa/IBM@IBMIL
        Subject:        Re: Exploiting dual mode operation


> We are working on an optimization for eliminating redundant sign 
extension
> instructions by making use of this duality. Currently this is done only 
in 
> very 
> simple cases.

I have already submitted a patch for this:
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg03259.html

It is still waiting for review.


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Exploiting dual mode operation
@ 2004-04-21 14:33 Mircea Namolaru
  2004-04-21 18:42 ` Joern Rennecke
  0 siblings, 1 reply; 8+ messages in thread
From: Mircea Namolaru @ 2004-04-21 14:33 UTC (permalink / raw)
  To: gcc; +Cc: Leehod Baruch

Hello,

For a 64-bit architecture, values defined as 32-bit values in a program 
must
be sign extended (or zero extended, in the case of unsigned values) to 
make 
them 64-bit values.
Some 64-bit architectures support certain operations in both 64-bit and 
32-bit form.
We are working on an optimization for eliminating redundant sign extension
instructions by making use of this duality. Currently this is done only in 
very 
simple cases.

For example in the following code there are explicit sign extension
instructions that could be eliminated :

i2 = extsw i1      //  i1, j1 are 32-bit integers in 64-bits architecture.
j2 = extsw j1
.......
cmpd i2, j2        // This compare is for double word (64-bits).

But, if a half-word compare instruction is available, we could use it and
remove the sign extensions:

cmpw i1, j1        // This compare is for single word (32-bits).

The sign extension instructions are generated after each definition of a
32-bit integer. By examining all the uses of a sign extension instruction
we can decide whether it is redundent or not.

Comments welcome. Thanks,

Leehod and Mircea

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-07 17:17 Exploiting dual mode operation Mircea Namolaru
  -- strict thread matches above, loose matches on Subject: below --
2004-04-22 13:58 Leehod Baruch
2004-04-22 14:59 ` Joern Rennecke
2004-04-26 16:41   ` Mircea Namolaru
2004-04-26 16:57     ` Joern Rennecke
2004-04-29 14:26       ` Mircea Namolaru
2004-04-21 14:33 Mircea Namolaru
2004-04-21 18:42 ` Joern Rennecke

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