Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / gnu / usr.bin / cc34 / cc_prep / patches / simplify-rtx.c.patch
1 $DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/simplify-rtx.c.patch,v 1.4 2005/08/27 21:03:51 joerg Exp $
2
3 ===================================================================
4 RCS file: /home/joerg/wd/repository/dragonflybsd/src/contrib/gcc-3.4/gcc/simplify-rtx.c,v
5 retrieving revision 1.2
6 diff -u -r1.2 simplify-rtx.c
7 --- simplify-rtx.c      20 Dec 2004 19:23:24 -0000      1.2
8 +++ simplify-rtx.c      20 Dec 2004 20:48:13 -0000
9 @@ -2329,6 +2329,7 @@
10    int n_ops = 2, input_ops = 2, input_consts = 0, n_consts;
11    int first, changed;
12    int i, j;
13 +  HOST_WIDE_INT fp_offset = 0;
14  
15    memset (ops, 0, sizeof ops);
16  
17 @@ -2354,6 +2355,10 @@
18           switch (this_code)
19             {
20             case PLUS:
21 +           if (flag_propolice_protection
22 +               && XEXP (this_op, 0) == virtual_stack_vars_rtx
23 +               && GET_CODE (XEXP (this_op, 1)) == CONST_INT)
24 +             fp_offset = INTVAL (XEXP (this_op, 1));
25             case MINUS:
26               if (n_ops == 7)
27                 return NULL_RTX;
28 @@ -2515,11 +2520,24 @@
29        && GET_CODE (ops[n_ops - 1].op) == CONST_INT
30        && CONSTANT_P (ops[n_ops - 2].op))
31      {
32 -      rtx value = ops[n_ops - 1].op;
33 -      if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg)
34 -       value = neg_const_int (mode, value);
35 -      ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, INTVAL (value));
36 -      n_ops--;
37 +      if (!flag_propolice_protection)
38 +       {
39 +         rtx value = ops[n_ops - 1].op;
40 +         if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg)
41 +           value = neg_const_int (mode, value);
42 +         ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, INTVAL (value));
43 +         n_ops--;
44 +       }
45 +      /* The stack protector keeps the addressing style of a local variable,
46 +        so it doesn't use neg_const_int function not to change
47 +        the offset value.  */
48 +      else {
49 +       HOST_WIDE_INT value = INTVAL (ops[n_ops - 1].op);
50 +       if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg)
51 +         value = -value;
52 +       ops[n_ops - 2].op = plus_constant (ops[n_ops - 2].op, value);
53 +       n_ops--;
54 +      }
55      }
56  
57    /* Count the number of CONSTs that we generated.  */
58 @@ -2537,6 +2555,59 @@
59           || (n_ops + n_consts == input_ops && n_consts <= input_consts)))
60      return NULL_RTX;
61  
62 +  if (flag_propolice_protection)
63 +    {
64 +      /* keep the addressing style of local variables
65 +        as (plus (virtual_stack_vars_rtx) (CONST_int x)).
66 +        For the case array[r-1],
67 +        converts from (+ (+VFP c1) (+r -1)) to (SET R (+VFP c1)) (+ R (+r -1)).
68 +
69 +        This loop finds ops[i] which is the register for the frame
70 +        addressing, Then, makes the frame addressing using the register and
71 +        the constant of ops[n_ops - 1].  */
72 +      for (i = 0; i < n_ops; i++)
73 +#ifdef FRAME_GROWS_DOWNWARD
74 +       if (ops[i].op == virtual_stack_vars_rtx)
75 +#else
76 +       if (ops[i].op == virtual_stack_vars_rtx
77 +           || ops[i].op == frame_pointer_rtx)
78 +#endif
79 +         {
80 +           if (GET_CODE (ops[n_ops - 1].op) == CONST_INT)
81 +             {
82 +               HOST_WIDE_INT value = INTVAL (ops[n_ops - 1].op);
83 +               if (value >= fp_offset)
84 +                 {
85 +                   ops[i].op = plus_constant (ops[i].op, value);
86 +                   n_ops--;
87 +                 }
88 +               else
89 +                 {
90 +                   if (!force
91 +                       && (n_ops + 1 + n_consts > input_ops
92 +                           || (n_ops + 1 + n_consts == input_ops
93 +                               && n_consts <= input_consts)))
94 +                     return NULL_RTX;
95 +                   ops[n_ops - 1].op = GEN_INT (value-fp_offset);
96 +                   ops[i].op = plus_constant (ops[i].op, fp_offset);
97 +                 }
98 +             }
99 +           /* keep the following address pattern;
100 +              (1) buf[BUFSIZE] is the first assigned variable.
101 +              (+ (+ fp -BUFSIZE) BUFSIZE)
102 +              (2) ((+ (+ fp 1) r) -1).  */
103 +           else if (fp_offset != 0)
104 +             return NULL_RTX;
105 +           /* keep the (+ fp 0) pattern for the following case;
106 +              (1) buf[i]: i: REG, buf: (+ fp 0) in !FRAME_GROWS_DOWNWARD
107 +              (2) argument: the address is (+ fp 0).  */
108 +           else if (fp_offset == 0)
109 +             return NULL_RTX;
110 +
111 +           break;
112 +         }
113 +    }
114 +
115    /* Put a non-negated operand first, if possible.  */
116  
117    for (i = 0; i < n_ops && ops[i].neg; i++)