public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Question about merging two instructions.
@ 2005-08-21 13:52 Leehod Baruch
  2005-08-21 16:55 ` Roger Sayle
  0 siblings, 1 reply; 11+ messages in thread
From: Leehod Baruch @ 2005-08-21 13:52 UTC (permalink / raw)
  To: gcc; +Cc: Steven Bosscher, Roger Sayle, Paolo Bonzini, Mircea Namolaru

Hello,

I'm working on a the sign extension elimination pass.
(see http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01087.html for details)
I would like to merge these two instructions:

(insn 1 0 2 0 (set (reg/v:Xmode r)
        (sign_extend:Xmode (op:Ymode (...))))
(insn 2 1 3 0 (set (lhs) (rhs)))

where:
1. Xmode > Ymode
2. rhs and/or lhs may contain: (subreg:Ymode (reg/v:Xmode r) lowpart)

The extension may be redundant here.
I would like to merge these instructions and eliminate the extension, 
if possible.

I tried to use simplify_replace_rtx to replace any use of (reg r) with 
the right-hand-side of the extension and simplify the result.
But, it didn't work till I added this change:

Index: simplify-rtx.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.243
diff -c -3 -p -r1.243 simplify-rtx.c
*** simplify-rtx.c      16 Aug 2005 02:01:27 -0000      1.243
--- simplify-rtx.c      21 Aug 2005 12:07:57 -0000
*************** simplify_replace_rtx (rtx x, rtx old_rtx
*** 319,325 ****
        return simplify_gen_ternary (code, mode, op_mode, op0, op1, op2);

      case RTX_EXTRA:
-       /* The only case we try to handle is a SUBREG.  */
        if (code == SUBREG)
        {
          op0 = simplify_replace_rtx (SUBREG_REG (x), old_rtx, new_rtx);
--- 319,324 ----
*************** simplify_replace_rtx (rtx x, rtx old_rtx
*** 329,334 ****
--- 328,341 ----
                                     GET_MODE (SUBREG_REG (x)),
                                     SUBREG_BYTE (x));
          return op0 ? op0 : x;
+       }
+       if (code == SET)
+       {
+         op0 = simplify_replace_rtx (XEXP (x, 0), old_rtx, new_rtx);
+         op1 = simplify_replace_rtx (XEXP (x, 1), old_rtx, new_rtx);
+         if ((op0 == XEXP (x, 0)) && (op1 == XEXP (x, 1)))
+           return x;
+         return gen_rtx_SET (VOIDmode, op0, op1);
        }
        break;

This way, when the replacement succeeds and the result instruction 
is recognizable, I can eliminate the extension.

Does it seem like a good change?
Does anyone have a better solution?


Thanks,
Leehod.

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

end of thread, other threads:[~2005-08-22 16:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-21 13:52 Question about merging two instructions Leehod Baruch
2005-08-21 16:55 ` Roger Sayle
2005-08-21 17:54   ` Leehod Baruch
2005-08-22  7:38     ` Paolo Bonzini
2005-08-22 13:33       ` Leehod Baruch
2005-08-22 13:37         ` Paolo Bonzini
2005-08-22 16:30           ` Richard Henderson
2005-08-22 13:49     ` Roger Sayle
2005-08-22  7:10   ` Paolo Bonzini
2005-08-22 14:12     ` Leehod Baruch
2005-08-22 14:42       ` Paolo Bonzini

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