This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question about merging two instructions.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]