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]

Trivial patch to ssa.c


This is a follow-on patch to the one that got applied here:
http://gcc.gnu.org/ml/gcc-patches/2002-05/msg02303.html

This is the exact same issue as before, and is described in this email:
http://gcc.gnu.org/ml/gcc/2002-03/msg00676.html

In this case, the following code:
struct DWstruct { char high, low; };

typedef union {
  struct DWstruct s;
  short ll;
} DWunion;

short __udivmodhi4 (char n1, char bm) {
  DWunion rr;
  if (bm == 0)
    rr.s.high = n1;
  else
    rr.s.high = bm;
  return rr.ll;
}

Generates the following bogus SSA code for me:

True branch:
(insn 18 46 19 (set (reg:HI 110)
        (zero_extend:HI (reg/v:QI 107))) -1 (nil)
    (nil))
(insn 19 18 20 (set (reg/v:HI 109)
        (and:HI (reg:HI 113)
            (const_int -256 [0xffffff00]))) -1 (nil)
    (nil))
(insn 20 19 21 (set (reg:HI 114)
        (ior:HI (reg/v:HI 109)
            (reg:HI 110))) -1 (nil)
    (nil))

False Branch:
(insn 27 47 28 (set (reg:HI 111)
        (zero_extend:HI (reg/v:QI 108))) -1 (nil)
    (nil))
(insn 28 27 29 (set (reg:HI 115)
        (and:HI (reg/v:HI 109)
            (const_int -256 [0xffffff00]))) -1 (nil)
    (nil))
(insn 29 28 30 (set (reg:HI 116)
        (ior:HI (reg:HI 115)
            (reg:HI 111))) -1 (nil)
    (nil))

Note that the false branch refers to register #109, which is defined in
the true branch, which does not dominate the use.  This patch fixes this
case, causing it to refer to a new, undefined, register:

===================================================================
RCS file: /cvs/gcc/gcc/gcc/ssa.c,v
retrieving revision 1.54
diff -r1.54 ssa.c
927c938
<         if (new_reg != RENAME_NO_RTX)
---
>         if (new_reg != RENAME_NO_RTX && new_reg != NULL_RTX)
929,940c940,942
<             if (new_reg != NULL_RTX)
<               {
<                 if (GET_MODE (x) != GET_MODE (new_reg))
<                   abort ();
<                 *ptr = new_reg;
<               }
<             else
<               {
<                 /* Undefined value used, rename it to a new pseudo register so
<                    that it cannot conflict with an existing register */
<                 *ptr = gen_reg_rtx (GET_MODE(x));
<               }
---
>             if (GET_MODE (x) != GET_MODE (new_reg))
>               abort ();
>             *ptr = new_reg;
941a944,949
>         else
>             {
>               /* Undefined value used, rename it to a new pseudo register so
>                  that it cannot conflict with an existing register */
>               *ptr = gen_reg_rtx(GET_MODE(x));
>             }

Or, in unified format for easy reading:

@@ -924,21 +935,18 @@
        {
          rtx new_reg = ssa_rename_to_lookup (x);

-         if (new_reg != RENAME_NO_RTX)
+         if (new_reg != RENAME_NO_RTX && new_reg != NULL_RTX)
            {
-             if (new_reg != NULL_RTX)
-               {
-                 if (GET_MODE (x) != GET_MODE (new_reg))
-                   abort ();
-                 *ptr = new_reg;
-               }
-             else
-               {
-                 /* Undefined value used, rename it to a new pseudo register so
-                    that it cannot conflict with an existing register */
-                 *ptr = gen_reg_rtx (GET_MODE(x));
-               }
+             if (GET_MODE (x) != GET_MODE (new_reg))
+               abort ();
+             *ptr = new_reg;
            }
+         else
+            {
+              /* Undefined value used, rename it to a new pseudo register so
+                 that it cannot conflict with an existing register */
+              *ptr = gen_reg_rtx(GET_MODE(x));
+            }
        }
       return -1;



I'm well aware that the ssa.c file is not in active use at this time, but
at least I can try to help make it as "correct" as possible. :)

Thanks,

-Chris

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


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