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