OSDN Git Service

Sat Aug 15 20:22:33 1998 H.J. Lu (hjl@gnu.org)
[pf3gnuchains/gcc-fork.git] / gcc / expr.c
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2    Copyright (C) 1988, 92-97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 #include "config.h"
23 #include "system.h"
24 #include "machmode.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "obstack.h"
28 #include "flags.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "except.h"
32 #include "function.h"
33 #include "insn-flags.h"
34 #include "insn-codes.h"
35 #include "insn-config.h"
36 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
37 #include "expr.h"
38 #include "recog.h"
39 #include "output.h"
40 #include "typeclass.h"
41 #include "defaults.h"
42 #include "toplev.h"
43
44 #define CEIL(x,y) (((x) + (y) - 1) / (y))
45
46 /* Decide whether a function's arguments should be processed
47    from first to last or from last to first.
48
49    They should if the stack and args grow in opposite directions, but
50    only if we have push insns.  */
51
52 #ifdef PUSH_ROUNDING
53
54 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
55 #define PUSH_ARGS_REVERSED      /* If it's last to first */
56 #endif
57
58 #endif
59
60 #ifndef STACK_PUSH_CODE
61 #ifdef STACK_GROWS_DOWNWARD
62 #define STACK_PUSH_CODE PRE_DEC
63 #else
64 #define STACK_PUSH_CODE PRE_INC
65 #endif
66 #endif
67
68 /* Like STACK_BOUNDARY but in units of bytes, not bits.  */
69 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
70
71 /* Assume that case vectors are not pc-relative.  */
72 #ifndef CASE_VECTOR_PC_RELATIVE
73 #define CASE_VECTOR_PC_RELATIVE 0
74 #endif
75
76 /* If this is nonzero, we do not bother generating VOLATILE
77    around volatile memory references, and we are willing to
78    output indirect addresses.  If cse is to follow, we reject
79    indirect addresses so a useful potential cse is generated;
80    if it is used only once, instruction combination will produce
81    the same indirect address eventually.  */
82 int cse_not_expected;
83
84 /* Nonzero to generate code for all the subroutines within an
85    expression before generating the upper levels of the expression.
86    Nowadays this is never zero.  */
87 int do_preexpand_calls = 1;
88
89 /* Number of units that we should eventually pop off the stack.
90    These are the arguments to function calls that have already returned.  */
91 int pending_stack_adjust;
92
93 /* Nonzero means stack pops must not be deferred, and deferred stack
94    pops must not be output.  It is nonzero inside a function call,
95    inside a conditional expression, inside a statement expression,
96    and in other cases as well.  */
97 int inhibit_defer_pop;
98
99 /* Nonzero means __builtin_saveregs has already been done in this function.
100    The value is the pseudoreg containing the value __builtin_saveregs
101    returned.  */
102 static rtx saveregs_value;
103
104 /* Similarly for __builtin_apply_args.  */
105 static rtx apply_args_value;
106
107 /* Nonzero if the machine description has been fixed to accept
108    CONSTANT_P_RTX patterns.  We will emit a warning and continue
109    if we find we must actually use such a beast.  */
110 static int can_handle_constant_p;
111
112 /* Don't check memory usage, since code is being emitted to check a memory
113    usage.  Used when flag_check_memory_usage is true, to avoid infinite
114    recursion.  */
115 static int in_check_memory_usage;
116
117 /* This structure is used by move_by_pieces to describe the move to
118    be performed.  */
119 struct move_by_pieces
120 {
121   rtx to;
122   rtx to_addr;
123   int autinc_to;
124   int explicit_inc_to;
125   int to_struct;
126   rtx from;
127   rtx from_addr;
128   int autinc_from;
129   int explicit_inc_from;
130   int from_struct;
131   int len;
132   int offset;
133   int reverse;
134 };
135
136 /* This structure is used by clear_by_pieces to describe the clear to
137    be performed.  */
138
139 struct clear_by_pieces
140 {
141   rtx to;
142   rtx to_addr;
143   int autinc_to;
144   int explicit_inc_to;
145   int to_struct;
146   int len;
147   int offset;
148   int reverse;
149 };
150
151 extern struct obstack permanent_obstack;
152 extern rtx arg_pointer_save_area;
153
154 static rtx get_push_address     PROTO ((int));
155
156 static rtx enqueue_insn         PROTO((rtx, rtx));
157 static int queued_subexp_p      PROTO((rtx));
158 static void init_queue          PROTO((void));
159 static void move_by_pieces      PROTO((rtx, rtx, int, int));
160 static int move_by_pieces_ninsns PROTO((unsigned int, int));
161 static void move_by_pieces_1    PROTO((rtx (*) (rtx, ...), enum machine_mode,
162                                        struct move_by_pieces *));
163 static void clear_by_pieces     PROTO((rtx, int, int));
164 static void clear_by_pieces_1   PROTO((rtx (*) (rtx, ...), enum machine_mode,
165                                        struct clear_by_pieces *));
166 static int is_zeros_p           PROTO((tree));
167 static int mostly_zeros_p       PROTO((tree));
168 static void store_constructor_field PROTO((rtx, int, int, enum machine_mode,
169                                            tree, tree, int));
170 static void store_constructor   PROTO((tree, rtx, int));
171 static rtx store_field          PROTO((rtx, int, int, enum machine_mode, tree,
172                                        enum machine_mode, int, int, int));
173 static enum memory_use_mode
174   get_memory_usage_from_modifier PROTO((enum expand_modifier));
175 static tree save_noncopied_parts PROTO((tree, tree));
176 static tree init_noncopied_parts PROTO((tree, tree));
177 static int safe_from_p          PROTO((rtx, tree, int));
178 static int fixed_type_p         PROTO((tree));
179 static rtx var_rtx              PROTO((tree));
180 static int get_pointer_alignment PROTO((tree, unsigned));
181 static tree string_constant     PROTO((tree, tree *));
182 static tree c_strlen            PROTO((tree));
183 static rtx get_memory_rtx       PROTO((tree));
184 static rtx expand_builtin       PROTO((tree, rtx, rtx,
185                                        enum machine_mode, int));
186 static int apply_args_size      PROTO((void));
187 static int apply_result_size    PROTO((void));
188 static rtx result_vector        PROTO((int, rtx));
189 static rtx expand_builtin_apply_args PROTO((void));
190 static rtx expand_builtin_apply PROTO((rtx, rtx, rtx));
191 static void expand_builtin_return PROTO((rtx));
192 static rtx expand_increment     PROTO((tree, int, int));
193 static void preexpand_calls     PROTO((tree));
194 static void do_jump_by_parts_greater PROTO((tree, int, rtx, rtx));
195 static void do_jump_by_parts_equality PROTO((tree, rtx, rtx));
196 static void do_jump_for_compare PROTO((rtx, rtx, rtx));
197 static rtx compare              PROTO((tree, enum rtx_code, enum rtx_code));
198 static rtx do_store_flag        PROTO((tree, rtx, enum machine_mode, int));
199
200 /* Record for each mode whether we can move a register directly to or
201    from an object of that mode in memory.  If we can't, we won't try
202    to use that mode directly when accessing a field of that mode.  */
203
204 static char direct_load[NUM_MACHINE_MODES];
205 static char direct_store[NUM_MACHINE_MODES];
206
207 /* MOVE_RATIO is the number of move instructions that is better than
208    a block move.  */
209
210 #ifndef MOVE_RATIO
211 #if defined (HAVE_movstrqi) || defined (HAVE_movstrhi) || defined (HAVE_movstrsi) || defined (HAVE_movstrdi) || defined (HAVE_movstrti)
212 #define MOVE_RATIO 2
213 #else
214 /* If we are optimizing for space (-Os), cut down the default move ratio */
215 #define MOVE_RATIO (optimize_size ? 3 : 15)
216 #endif
217 #endif
218
219 /* This array records the insn_code of insns to perform block moves.  */
220 enum insn_code movstr_optab[NUM_MACHINE_MODES];
221
222 /* This array records the insn_code of insns to perform block clears.  */
223 enum insn_code clrstr_optab[NUM_MACHINE_MODES];
224
225 /* SLOW_UNALIGNED_ACCESS is non-zero if unaligned accesses are very slow.  */
226
227 #ifndef SLOW_UNALIGNED_ACCESS
228 #define SLOW_UNALIGNED_ACCESS STRICT_ALIGNMENT
229 #endif
230
231 /* Register mappings for target machines without register windows.  */
232 #ifndef INCOMING_REGNO
233 #define INCOMING_REGNO(OUT) (OUT)
234 #endif
235 #ifndef OUTGOING_REGNO
236 #define OUTGOING_REGNO(IN) (IN)
237 #endif
238 \f
239 /* This is run once per compilation to set up which modes can be used
240    directly in memory and to initialize the block move optab.  */
241
242 void
243 init_expr_once ()
244 {
245   rtx insn, pat;
246   enum machine_mode mode;
247   int num_clobbers;
248   rtx mem, mem1;
249   char *free_point;
250
251   start_sequence ();
252
253   /* Since we are on the permanent obstack, we must be sure we save this
254      spot AFTER we call start_sequence, since it will reuse the rtl it
255      makes.  */
256   free_point = (char *) oballoc (0);
257
258   /* Try indexing by frame ptr and try by stack ptr.
259      It is known that on the Convex the stack ptr isn't a valid index.
260      With luck, one or the other is valid on any machine.  */
261   mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
262   mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
263
264   insn = emit_insn (gen_rtx_SET (0, NULL_RTX, NULL_RTX));
265   pat = PATTERN (insn);
266
267   for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
268        mode = (enum machine_mode) ((int) mode + 1))
269     {
270       int regno;
271       rtx reg;
272
273       direct_load[(int) mode] = direct_store[(int) mode] = 0;
274       PUT_MODE (mem, mode);
275       PUT_MODE (mem1, mode);
276
277       /* See if there is some register that can be used in this mode and
278          directly loaded or stored from memory.  */
279
280       if (mode != VOIDmode && mode != BLKmode)
281         for (regno = 0; regno < FIRST_PSEUDO_REGISTER
282              && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
283              regno++)
284           {
285             if (! HARD_REGNO_MODE_OK (regno, mode))
286               continue;
287
288             reg = gen_rtx_REG (mode, regno);
289
290             SET_SRC (pat) = mem;
291             SET_DEST (pat) = reg;
292             if (recog (pat, insn, &num_clobbers) >= 0)
293               direct_load[(int) mode] = 1;
294
295             SET_SRC (pat) = mem1;
296             SET_DEST (pat) = reg;
297             if (recog (pat, insn, &num_clobbers) >= 0)
298               direct_load[(int) mode] = 1;
299
300             SET_SRC (pat) = reg;
301             SET_DEST (pat) = mem;
302             if (recog (pat, insn, &num_clobbers) >= 0)
303               direct_store[(int) mode] = 1;
304
305             SET_SRC (pat) = reg;
306             SET_DEST (pat) = mem1;
307             if (recog (pat, insn, &num_clobbers) >= 0)
308               direct_store[(int) mode] = 1;
309           }
310     }
311
312   /* Find out if CONSTANT_P_RTX is accepted.  */
313   SET_DEST (pat) = gen_rtx_REG (TYPE_MODE (integer_type_node),
314                                 FIRST_PSEUDO_REGISTER);
315   SET_SRC (pat) = gen_rtx_CONSTANT_P_RTX (TYPE_MODE (integer_type_node),
316                                           SET_DEST (pat));
317   if (recog (pat, insn, &num_clobbers) >= 0)
318     can_handle_constant_p = 1;
319
320   end_sequence ();
321   obfree (free_point);
322 }
323
324 /* This is run at the start of compiling a function.  */
325
326 void
327 init_expr ()
328 {
329   init_queue ();
330
331   pending_stack_adjust = 0;
332   inhibit_defer_pop = 0;
333   saveregs_value = 0;
334   apply_args_value = 0;
335   forced_labels = 0;
336 }
337
338 /* Save all variables describing the current status into the structure *P.
339    This is used before starting a nested function.  */
340
341 void
342 save_expr_status (p)
343      struct function *p;
344 {
345   /* Instead of saving the postincrement queue, empty it.  */
346   emit_queue ();
347
348   p->pending_stack_adjust = pending_stack_adjust;
349   p->inhibit_defer_pop = inhibit_defer_pop;
350   p->saveregs_value = saveregs_value;
351   p->apply_args_value = apply_args_value;
352   p->forced_labels = forced_labels;
353
354   pending_stack_adjust = 0;
355   inhibit_defer_pop = 0;
356   saveregs_value = 0;
357   apply_args_value = 0;
358   forced_labels = 0;
359 }
360
361 /* Restore all variables describing the current status from the structure *P.
362    This is used after a nested function.  */
363
364 void
365 restore_expr_status (p)
366      struct function *p;
367 {
368   pending_stack_adjust = p->pending_stack_adjust;
369   inhibit_defer_pop = p->inhibit_defer_pop;
370   saveregs_value = p->saveregs_value;
371   apply_args_value = p->apply_args_value;
372   forced_labels = p->forced_labels;
373 }
374 \f
375 /* Manage the queue of increment instructions to be output
376    for POSTINCREMENT_EXPR expressions, etc.  */
377
378 static rtx pending_chain;
379
380 /* Queue up to increment (or change) VAR later.  BODY says how:
381    BODY should be the same thing you would pass to emit_insn
382    to increment right away.  It will go to emit_insn later on.
383
384    The value is a QUEUED expression to be used in place of VAR
385    where you want to guarantee the pre-incrementation value of VAR.  */
386
387 static rtx
388 enqueue_insn (var, body)
389      rtx var, body;
390 {
391   pending_chain = gen_rtx_QUEUED (GET_MODE (var),
392                                   var, NULL_RTX, NULL_RTX, body,
393                                   pending_chain);
394   return pending_chain;
395 }
396
397 /* Use protect_from_queue to convert a QUEUED expression
398    into something that you can put immediately into an instruction.
399    If the queued incrementation has not happened yet,
400    protect_from_queue returns the variable itself.
401    If the incrementation has happened, protect_from_queue returns a temp
402    that contains a copy of the old value of the variable.
403
404    Any time an rtx which might possibly be a QUEUED is to be put
405    into an instruction, it must be passed through protect_from_queue first.
406    QUEUED expressions are not meaningful in instructions.
407
408    Do not pass a value through protect_from_queue and then hold
409    on to it for a while before putting it in an instruction!
410    If the queue is flushed in between, incorrect code will result.  */
411
412 rtx
413 protect_from_queue (x, modify)
414      register rtx x;
415      int modify;
416 {
417   register RTX_CODE code = GET_CODE (x);
418
419 #if 0  /* A QUEUED can hang around after the queue is forced out.  */
420   /* Shortcut for most common case.  */
421   if (pending_chain == 0)
422     return x;
423 #endif
424
425   if (code != QUEUED)
426     {
427       /* A special hack for read access to (MEM (QUEUED ...)) to facilitate
428          use of autoincrement.  Make a copy of the contents of the memory
429          location rather than a copy of the address, but not if the value is
430          of mode BLKmode.  Don't modify X in place since it might be
431          shared.  */
432       if (code == MEM && GET_MODE (x) != BLKmode
433           && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
434         {
435           register rtx y = XEXP (x, 0);
436           register rtx new = gen_rtx_MEM (GET_MODE (x), QUEUED_VAR (y));
437
438           MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
439           RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
440           MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
441           MEM_ALIAS_SET (new) = MEM_ALIAS_SET (x);
442
443           if (QUEUED_INSN (y))
444             {
445               register rtx temp = gen_reg_rtx (GET_MODE (new));
446               emit_insn_before (gen_move_insn (temp, new),
447                                 QUEUED_INSN (y));
448               return temp;
449             }
450           return new;
451         }
452       /* Otherwise, recursively protect the subexpressions of all
453          the kinds of rtx's that can contain a QUEUED.  */
454       if (code == MEM)
455         {
456           rtx tem = protect_from_queue (XEXP (x, 0), 0);
457           if (tem != XEXP (x, 0))
458             {
459               x = copy_rtx (x);
460               XEXP (x, 0) = tem;
461             }
462         }
463       else if (code == PLUS || code == MULT)
464         {
465           rtx new0 = protect_from_queue (XEXP (x, 0), 0);
466           rtx new1 = protect_from_queue (XEXP (x, 1), 0);
467           if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
468             {
469               x = copy_rtx (x);
470               XEXP (x, 0) = new0;
471               XEXP (x, 1) = new1;
472             }
473         }
474       return x;
475     }
476   /* If the increment has not happened, use the variable itself.  */
477   if (QUEUED_INSN (x) == 0)
478     return QUEUED_VAR (x);
479   /* If the increment has happened and a pre-increment copy exists,
480      use that copy.  */
481   if (QUEUED_COPY (x) != 0)
482     return QUEUED_COPY (x);
483   /* The increment has happened but we haven't set up a pre-increment copy.
484      Set one up now, and use it.  */
485   QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
486   emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
487                     QUEUED_INSN (x));
488   return QUEUED_COPY (x);
489 }
490
491 /* Return nonzero if X contains a QUEUED expression:
492    if it contains anything that will be altered by a queued increment.
493    We handle only combinations of MEM, PLUS, MINUS and MULT operators
494    since memory addresses generally contain only those.  */
495
496 static int
497 queued_subexp_p (x)
498      rtx x;
499 {
500   register enum rtx_code code = GET_CODE (x);
501   switch (code)
502     {
503     case QUEUED:
504       return 1;
505     case MEM:
506       return queued_subexp_p (XEXP (x, 0));
507     case MULT:
508     case PLUS:
509     case MINUS:
510       return (queued_subexp_p (XEXP (x, 0))
511               || queued_subexp_p (XEXP (x, 1)));
512     default:
513       return 0;
514     }
515 }
516
517 /* Perform all the pending incrementations.  */
518
519 void
520 emit_queue ()
521 {
522   register rtx p;
523   while ((p = pending_chain))
524     {
525       rtx body = QUEUED_BODY (p);
526
527       if (GET_CODE (body) == SEQUENCE)
528         {
529           QUEUED_INSN (p) = XVECEXP (QUEUED_BODY (p), 0, 0);
530           emit_insn (QUEUED_BODY (p));
531         }
532       else
533         QUEUED_INSN (p) = emit_insn (QUEUED_BODY (p));
534       pending_chain = QUEUED_NEXT (p);
535     }
536 }
537
538 static void
539 init_queue ()
540 {
541   if (pending_chain)
542     abort ();
543 }
544 \f
545 /* Copy data from FROM to TO, where the machine modes are not the same.
546    Both modes may be integer, or both may be floating.
547    UNSIGNEDP should be nonzero if FROM is an unsigned type.
548    This causes zero-extension instead of sign-extension.  */
549
550 void
551 convert_move (to, from, unsignedp)
552      register rtx to, from;
553      int unsignedp;
554 {
555   enum machine_mode to_mode = GET_MODE (to);
556   enum machine_mode from_mode = GET_MODE (from);
557   int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
558   int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
559   enum insn_code code;
560   rtx libcall;
561
562   /* rtx code for making an equivalent value.  */
563   enum rtx_code equiv_code = (unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
564
565   to = protect_from_queue (to, 1);
566   from = protect_from_queue (from, 0);
567
568   if (to_real != from_real)
569     abort ();
570
571   /* If FROM is a SUBREG that indicates that we have already done at least
572      the required extension, strip it.  We don't handle such SUBREGs as
573      TO here.  */
574
575   if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
576       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
577           >= GET_MODE_SIZE (to_mode))
578       && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
579     from = gen_lowpart (to_mode, from), from_mode = to_mode;
580
581   if (GET_CODE (to) == SUBREG && SUBREG_PROMOTED_VAR_P (to))
582     abort ();
583
584   if (to_mode == from_mode
585       || (from_mode == VOIDmode && CONSTANT_P (from)))
586     {
587       emit_move_insn (to, from);
588       return;
589     }
590
591   if (to_real)
592     {
593       rtx value;
594
595       if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode))
596         {
597           /* Try converting directly if the insn is supported.  */
598           if ((code = can_extend_p (to_mode, from_mode, 0))
599               != CODE_FOR_nothing)
600             {
601               emit_unop_insn (code, to, from, UNKNOWN);
602               return;
603             }
604         }
605  
606 #ifdef HAVE_trunchfqf2
607       if (HAVE_trunchfqf2 && from_mode == HFmode && to_mode == QFmode)
608         {
609           emit_unop_insn (CODE_FOR_trunchfqf2, to, from, UNKNOWN);
610           return;
611         }
612 #endif
613 #ifdef HAVE_trunctqfqf2
614       if (HAVE_trunctqfqf2 && from_mode == TQFmode && to_mode == QFmode)
615         {
616           emit_unop_insn (CODE_FOR_trunctqfqf2, to, from, UNKNOWN);
617           return;
618         }
619 #endif
620 #ifdef HAVE_truncsfqf2
621       if (HAVE_truncsfqf2 && from_mode == SFmode && to_mode == QFmode)
622         {
623           emit_unop_insn (CODE_FOR_truncsfqf2, to, from, UNKNOWN);
624           return;
625         }
626 #endif
627 #ifdef HAVE_truncdfqf2
628       if (HAVE_truncdfqf2 && from_mode == DFmode && to_mode == QFmode)
629         {
630           emit_unop_insn (CODE_FOR_truncdfqf2, to, from, UNKNOWN);
631           return;
632         }
633 #endif
634 #ifdef HAVE_truncxfqf2
635       if (HAVE_truncxfqf2 && from_mode == XFmode && to_mode == QFmode)
636         {
637           emit_unop_insn (CODE_FOR_truncxfqf2, to, from, UNKNOWN);
638           return;
639         }
640 #endif
641 #ifdef HAVE_trunctfqf2
642       if (HAVE_trunctfqf2 && from_mode == TFmode && to_mode == QFmode)
643         {
644           emit_unop_insn (CODE_FOR_trunctfqf2, to, from, UNKNOWN);
645           return;
646         }
647 #endif
648
649 #ifdef HAVE_trunctqfhf2
650       if (HAVE_trunctqfhf2 && from_mode == TQFmode && to_mode == HFmode)
651         {
652           emit_unop_insn (CODE_FOR_trunctqfhf2, to, from, UNKNOWN);
653           return;
654         }
655 #endif
656 #ifdef HAVE_truncsfhf2
657       if (HAVE_truncsfhf2 && from_mode == SFmode && to_mode == HFmode)
658         {
659           emit_unop_insn (CODE_FOR_truncsfhf2, to, from, UNKNOWN);
660           return;
661         }
662 #endif
663 #ifdef HAVE_truncdfhf2
664       if (HAVE_truncdfhf2 && from_mode == DFmode && to_mode == HFmode)
665         {
666           emit_unop_insn (CODE_FOR_truncdfhf2, to, from, UNKNOWN);
667           return;
668         }
669 #endif
670 #ifdef HAVE_truncxfhf2
671       if (HAVE_truncxfhf2 && from_mode == XFmode && to_mode == HFmode)
672         {
673           emit_unop_insn (CODE_FOR_truncxfhf2, to, from, UNKNOWN);
674           return;
675         }
676 #endif
677 #ifdef HAVE_trunctfhf2
678       if (HAVE_trunctfhf2 && from_mode == TFmode && to_mode == HFmode)
679         {
680           emit_unop_insn (CODE_FOR_trunctfhf2, to, from, UNKNOWN);
681           return;
682         }
683 #endif
684
685 #ifdef HAVE_truncsftqf2
686       if (HAVE_truncsftqf2 && from_mode == SFmode && to_mode == TQFmode)
687         {
688           emit_unop_insn (CODE_FOR_truncsftqf2, to, from, UNKNOWN);
689           return;
690         }
691 #endif
692 #ifdef HAVE_truncdftqf2
693       if (HAVE_truncdftqf2 && from_mode == DFmode && to_mode == TQFmode)
694         {
695           emit_unop_insn (CODE_FOR_truncdftqf2, to, from, UNKNOWN);
696           return;
697         }
698 #endif
699 #ifdef HAVE_truncxftqf2
700       if (HAVE_truncxftqf2 && from_mode == XFmode && to_mode == TQFmode)
701         {
702           emit_unop_insn (CODE_FOR_truncxftqf2, to, from, UNKNOWN);
703           return;
704         }
705 #endif
706 #ifdef HAVE_trunctftqf2
707       if (HAVE_trunctftqf2 && from_mode == TFmode && to_mode == TQFmode)
708         {
709           emit_unop_insn (CODE_FOR_trunctftqf2, to, from, UNKNOWN);
710           return;
711         }
712 #endif
713
714 #ifdef HAVE_truncdfsf2
715       if (HAVE_truncdfsf2 && from_mode == DFmode && to_mode == SFmode)
716         {
717           emit_unop_insn (CODE_FOR_truncdfsf2, to, from, UNKNOWN);
718           return;
719         }
720 #endif
721 #ifdef HAVE_truncxfsf2
722       if (HAVE_truncxfsf2 && from_mode == XFmode && to_mode == SFmode)
723         {
724           emit_unop_insn (CODE_FOR_truncxfsf2, to, from, UNKNOWN);
725           return;
726         }
727 #endif
728 #ifdef HAVE_trunctfsf2
729       if (HAVE_trunctfsf2 && from_mode == TFmode && to_mode == SFmode)
730         {
731           emit_unop_insn (CODE_FOR_trunctfsf2, to, from, UNKNOWN);
732           return;
733         }
734 #endif
735 #ifdef HAVE_truncxfdf2
736       if (HAVE_truncxfdf2 && from_mode == XFmode && to_mode == DFmode)
737         {
738           emit_unop_insn (CODE_FOR_truncxfdf2, to, from, UNKNOWN);
739           return;
740         }
741 #endif
742 #ifdef HAVE_trunctfdf2
743       if (HAVE_trunctfdf2 && from_mode == TFmode && to_mode == DFmode)
744         {
745           emit_unop_insn (CODE_FOR_trunctfdf2, to, from, UNKNOWN);
746           return;
747         }
748 #endif
749
750       libcall = (rtx) 0;
751       switch (from_mode)
752         {
753         case SFmode:
754           switch (to_mode)
755             {
756             case DFmode:
757               libcall = extendsfdf2_libfunc;
758               break;
759
760             case XFmode:
761               libcall = extendsfxf2_libfunc;
762               break;
763
764             case TFmode:
765               libcall = extendsftf2_libfunc;
766               break;
767               
768             default:
769               break;
770             }
771           break;
772
773         case DFmode:
774           switch (to_mode)
775             {
776             case SFmode:
777               libcall = truncdfsf2_libfunc;
778               break;
779
780             case XFmode:
781               libcall = extenddfxf2_libfunc;
782               break;
783
784             case TFmode:
785               libcall = extenddftf2_libfunc;
786               break;
787               
788             default:
789               break;
790             }
791           break;
792
793         case XFmode:
794           switch (to_mode)
795             {
796             case SFmode:
797               libcall = truncxfsf2_libfunc;
798               break;
799
800             case DFmode:
801               libcall = truncxfdf2_libfunc;
802               break;
803               
804             default:
805               break;
806             }
807           break;
808
809         case TFmode:
810           switch (to_mode)
811             {
812             case SFmode:
813               libcall = trunctfsf2_libfunc;
814               break;
815
816             case DFmode:
817               libcall = trunctfdf2_libfunc;
818               break;
819               
820             default:
821               break;
822             }
823           break;
824           
825         default:
826           break;
827         }
828
829       if (libcall == (rtx) 0)
830         /* This conversion is not implemented yet.  */
831         abort ();
832
833       value = emit_library_call_value (libcall, NULL_RTX, 1, to_mode,
834                                        1, from, from_mode);
835       emit_move_insn (to, value);
836       return;
837     }
838
839   /* Now both modes are integers.  */
840
841   /* Handle expanding beyond a word.  */
842   if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
843       && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
844     {
845       rtx insns;
846       rtx lowpart;
847       rtx fill_value;
848       rtx lowfrom;
849       int i;
850       enum machine_mode lowpart_mode;
851       int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
852
853       /* Try converting directly if the insn is supported.  */
854       if ((code = can_extend_p (to_mode, from_mode, unsignedp))
855           != CODE_FOR_nothing)
856         {
857           /* If FROM is a SUBREG, put it into a register.  Do this
858              so that we always generate the same set of insns for
859              better cse'ing; if an intermediate assignment occurred,
860              we won't be doing the operation directly on the SUBREG.  */
861           if (optimize > 0 && GET_CODE (from) == SUBREG)
862             from = force_reg (from_mode, from);
863           emit_unop_insn (code, to, from, equiv_code);
864           return;
865         }
866       /* Next, try converting via full word.  */
867       else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
868                && ((code = can_extend_p (to_mode, word_mode, unsignedp))
869                    != CODE_FOR_nothing))
870         {
871           if (GET_CODE (to) == REG)
872             emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
873           convert_move (gen_lowpart (word_mode, to), from, unsignedp);
874           emit_unop_insn (code, to,
875                           gen_lowpart (word_mode, to), equiv_code);
876           return;
877         }
878
879       /* No special multiword conversion insn; do it by hand.  */
880       start_sequence ();
881
882       /* Since we will turn this into a no conflict block, we must ensure
883          that the source does not overlap the target.  */
884
885       if (reg_overlap_mentioned_p (to, from))
886         from = force_reg (from_mode, from);
887
888       /* Get a copy of FROM widened to a word, if necessary.  */
889       if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
890         lowpart_mode = word_mode;
891       else
892         lowpart_mode = from_mode;
893
894       lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
895
896       lowpart = gen_lowpart (lowpart_mode, to);
897       emit_move_insn (lowpart, lowfrom);
898
899       /* Compute the value to put in each remaining word.  */
900       if (unsignedp)
901         fill_value = const0_rtx;
902       else
903         {
904 #ifdef HAVE_slt
905           if (HAVE_slt
906               && insn_operand_mode[(int) CODE_FOR_slt][0] == word_mode
907               && STORE_FLAG_VALUE == -1)
908             {
909               emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
910                              lowpart_mode, 0, 0);
911               fill_value = gen_reg_rtx (word_mode);
912               emit_insn (gen_slt (fill_value));
913             }
914           else
915 #endif
916             {
917               fill_value
918                 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
919                                 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
920                                 NULL_RTX, 0);
921               fill_value = convert_to_mode (word_mode, fill_value, 1);
922             }
923         }
924
925       /* Fill the remaining words.  */
926       for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
927         {
928           int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
929           rtx subword = operand_subword (to, index, 1, to_mode);
930
931           if (subword == 0)
932             abort ();
933
934           if (fill_value != subword)
935             emit_move_insn (subword, fill_value);
936         }
937
938       insns = get_insns ();
939       end_sequence ();
940
941       emit_no_conflict_block (insns, to, from, NULL_RTX,
942                               gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
943       return;
944     }
945
946   /* Truncating multi-word to a word or less.  */
947   if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
948       && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
949     {
950       if (!((GET_CODE (from) == MEM
951              && ! MEM_VOLATILE_P (from)
952              && direct_load[(int) to_mode]
953              && ! mode_dependent_address_p (XEXP (from, 0)))
954             || GET_CODE (from) == REG
955             || GET_CODE (from) == SUBREG))
956         from = force_reg (from_mode, from);
957       convert_move (to, gen_lowpart (word_mode, from), 0);
958       return;
959     }
960
961   /* Handle pointer conversion */                       /* SPEE 900220 */
962   if (to_mode == PQImode)
963     {
964       if (from_mode != QImode)
965         from = convert_to_mode (QImode, from, unsignedp);
966
967 #ifdef HAVE_truncqipqi2
968       if (HAVE_truncqipqi2)
969         {
970           emit_unop_insn (CODE_FOR_truncqipqi2, to, from, UNKNOWN);
971           return;
972         }
973 #endif /* HAVE_truncqipqi2 */
974       abort ();
975     }
976
977   if (from_mode == PQImode)
978     {
979       if (to_mode != QImode)
980         {
981           from = convert_to_mode (QImode, from, unsignedp);
982           from_mode = QImode;
983         }
984       else
985         {
986 #ifdef HAVE_extendpqiqi2
987           if (HAVE_extendpqiqi2)
988             {
989               emit_unop_insn (CODE_FOR_extendpqiqi2, to, from, UNKNOWN);
990               return;
991             }
992 #endif /* HAVE_extendpqiqi2 */
993           abort ();
994         }
995     }
996
997   if (to_mode == PSImode)
998     {
999       if (from_mode != SImode)
1000         from = convert_to_mode (SImode, from, unsignedp);
1001
1002 #ifdef HAVE_truncsipsi2
1003       if (HAVE_truncsipsi2)
1004         {
1005           emit_unop_insn (CODE_FOR_truncsipsi2, to, from, UNKNOWN);
1006           return;
1007         }
1008 #endif /* HAVE_truncsipsi2 */
1009       abort ();
1010     }
1011
1012   if (from_mode == PSImode)
1013     {
1014       if (to_mode != SImode)
1015         {
1016           from = convert_to_mode (SImode, from, unsignedp);
1017           from_mode = SImode;
1018         }
1019       else
1020         {
1021 #ifdef HAVE_extendpsisi2
1022           if (HAVE_extendpsisi2)
1023             {
1024               emit_unop_insn (CODE_FOR_extendpsisi2, to, from, UNKNOWN);
1025               return;
1026             }
1027 #endif /* HAVE_extendpsisi2 */
1028           abort ();
1029         }
1030     }
1031
1032   if (to_mode == PDImode)
1033     {
1034       if (from_mode != DImode)
1035         from = convert_to_mode (DImode, from, unsignedp);
1036
1037 #ifdef HAVE_truncdipdi2
1038       if (HAVE_truncdipdi2)
1039         {
1040           emit_unop_insn (CODE_FOR_truncdipdi2, to, from, UNKNOWN);
1041           return;
1042         }
1043 #endif /* HAVE_truncdipdi2 */
1044       abort ();
1045     }
1046
1047   if (from_mode == PDImode)
1048     {
1049       if (to_mode != DImode)
1050         {
1051           from = convert_to_mode (DImode, from, unsignedp);
1052           from_mode = DImode;
1053         }
1054       else
1055         {
1056 #ifdef HAVE_extendpdidi2
1057           if (HAVE_extendpdidi2)
1058             {
1059               emit_unop_insn (CODE_FOR_extendpdidi2, to, from, UNKNOWN);
1060               return;
1061             }
1062 #endif /* HAVE_extendpdidi2 */
1063           abort ();
1064         }
1065     }
1066
1067   /* Now follow all the conversions between integers
1068      no more than a word long.  */
1069
1070   /* For truncation, usually we can just refer to FROM in a narrower mode.  */
1071   if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
1072       && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
1073                                 GET_MODE_BITSIZE (from_mode)))
1074     {
1075       if (!((GET_CODE (from) == MEM
1076              && ! MEM_VOLATILE_P (from)
1077              && direct_load[(int) to_mode]
1078              && ! mode_dependent_address_p (XEXP (from, 0)))
1079             || GET_CODE (from) == REG
1080             || GET_CODE (from) == SUBREG))
1081         from = force_reg (from_mode, from);
1082       if (GET_CODE (from) == REG && REGNO (from) < FIRST_PSEUDO_REGISTER
1083           && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
1084         from = copy_to_reg (from);
1085       emit_move_insn (to, gen_lowpart (to_mode, from));
1086       return;
1087     }
1088
1089   /* Handle extension.  */
1090   if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
1091     {
1092       /* Convert directly if that works.  */
1093       if ((code = can_extend_p (to_mode, from_mode, unsignedp))
1094           != CODE_FOR_nothing)
1095         {
1096           emit_unop_insn (code, to, from, equiv_code);
1097           return;
1098         }
1099       else
1100         {
1101           enum machine_mode intermediate;
1102
1103           /* Search for a mode to convert via.  */
1104           for (intermediate = from_mode; intermediate != VOIDmode;
1105                intermediate = GET_MODE_WIDER_MODE (intermediate))
1106             if (((can_extend_p (to_mode, intermediate, unsignedp)
1107                   != CODE_FOR_nothing)
1108                  || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
1109                      && TRULY_NOOP_TRUNCATION (to_mode, intermediate)))
1110                 && (can_extend_p (intermediate, from_mode, unsignedp)
1111                     != CODE_FOR_nothing))
1112               {
1113                 convert_move (to, convert_to_mode (intermediate, from,
1114                                                    unsignedp), unsignedp);
1115                 return;
1116               }
1117
1118           /* No suitable intermediate mode.  */
1119           abort ();
1120         }
1121     }
1122
1123   /* Support special truncate insns for certain modes.  */ 
1124
1125   if (from_mode == DImode && to_mode == SImode)
1126     {
1127 #ifdef HAVE_truncdisi2
1128       if (HAVE_truncdisi2)
1129         {
1130           emit_unop_insn (CODE_FOR_truncdisi2, to, from, UNKNOWN);
1131           return;
1132         }
1133 #endif
1134       convert_move (to, force_reg (from_mode, from), unsignedp);
1135       return;
1136     }
1137
1138   if (from_mode == DImode && to_mode == HImode)
1139     {
1140 #ifdef HAVE_truncdihi2
1141       if (HAVE_truncdihi2)
1142         {
1143           emit_unop_insn (CODE_FOR_truncdihi2, to, from, UNKNOWN);
1144           return;
1145         }
1146 #endif
1147       convert_move (to, force_reg (from_mode, from), unsignedp);
1148       return;
1149     }
1150
1151   if (from_mode == DImode && to_mode == QImode)
1152     {
1153 #ifdef HAVE_truncdiqi2
1154       if (HAVE_truncdiqi2)
1155         {
1156           emit_unop_insn (CODE_FOR_truncdiqi2, to, from, UNKNOWN);
1157           return;
1158         }
1159 #endif
1160       convert_move (to, force_reg (from_mode, from), unsignedp);
1161       return;
1162     }
1163
1164   if (from_mode == SImode && to_mode == HImode)
1165     {
1166 #ifdef HAVE_truncsihi2
1167       if (HAVE_truncsihi2)
1168         {
1169           emit_unop_insn (CODE_FOR_truncsihi2, to, from, UNKNOWN);
1170           return;
1171         }
1172 #endif
1173       convert_move (to, force_reg (from_mode, from), unsignedp);
1174       return;
1175     }
1176
1177   if (from_mode == SImode && to_mode == QImode)
1178     {
1179 #ifdef HAVE_truncsiqi2
1180       if (HAVE_truncsiqi2)
1181         {
1182           emit_unop_insn (CODE_FOR_truncsiqi2, to, from, UNKNOWN);
1183           return;
1184         }
1185 #endif
1186       convert_move (to, force_reg (from_mode, from), unsignedp);
1187       return;
1188     }
1189
1190   if (from_mode == HImode && to_mode == QImode)
1191     {
1192 #ifdef HAVE_trunchiqi2
1193       if (HAVE_trunchiqi2)
1194         {
1195           emit_unop_insn (CODE_FOR_trunchiqi2, to, from, UNKNOWN);
1196           return;
1197         }
1198 #endif
1199       convert_move (to, force_reg (from_mode, from), unsignedp);
1200       return;
1201     }
1202
1203   if (from_mode == TImode && to_mode == DImode)
1204     {
1205 #ifdef HAVE_trunctidi2
1206       if (HAVE_trunctidi2)
1207         {
1208           emit_unop_insn (CODE_FOR_trunctidi2, to, from, UNKNOWN);
1209           return;
1210         }
1211 #endif
1212       convert_move (to, force_reg (from_mode, from), unsignedp);
1213       return;
1214     }
1215
1216   if (from_mode == TImode && to_mode == SImode)
1217     {
1218 #ifdef HAVE_trunctisi2
1219       if (HAVE_trunctisi2)
1220         {
1221           emit_unop_insn (CODE_FOR_trunctisi2, to, from, UNKNOWN);
1222           return;
1223         }
1224 #endif
1225       convert_move (to, force_reg (from_mode, from), unsignedp);
1226       return;
1227     }
1228
1229   if (from_mode == TImode && to_mode == HImode)
1230     {
1231 #ifdef HAVE_trunctihi2
1232       if (HAVE_trunctihi2)
1233         {
1234           emit_unop_insn (CODE_FOR_trunctihi2, to, from, UNKNOWN);
1235           return;
1236         }
1237 #endif
1238       convert_move (to, force_reg (from_mode, from), unsignedp);
1239       return;
1240     }
1241
1242   if (from_mode == TImode && to_mode == QImode)
1243     {
1244 #ifdef HAVE_trunctiqi2
1245       if (HAVE_trunctiqi2)
1246         {
1247           emit_unop_insn (CODE_FOR_trunctiqi2, to, from, UNKNOWN);
1248           return;
1249         }
1250 #endif
1251       convert_move (to, force_reg (from_mode, from), unsignedp);
1252       return;
1253     }
1254
1255   /* Handle truncation of volatile memrefs, and so on;
1256      the things that couldn't be truncated directly,
1257      and for which there was no special instruction.  */
1258   if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
1259     {
1260       rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
1261       emit_move_insn (to, temp);
1262       return;
1263     }
1264
1265   /* Mode combination is not recognized.  */
1266   abort ();
1267 }
1268
1269 /* Return an rtx for a value that would result
1270    from converting X to mode MODE.
1271    Both X and MODE may be floating, or both integer.
1272    UNSIGNEDP is nonzero if X is an unsigned value.
1273    This can be done by referring to a part of X in place
1274    or by copying to a new temporary with conversion.
1275
1276    This function *must not* call protect_from_queue
1277    except when putting X into an insn (in which case convert_move does it).  */
1278
1279 rtx
1280 convert_to_mode (mode, x, unsignedp)
1281      enum machine_mode mode;
1282      rtx x;
1283      int unsignedp;
1284 {
1285   return convert_modes (mode, VOIDmode, x, unsignedp);
1286 }
1287
1288 /* Return an rtx for a value that would result
1289    from converting X from mode OLDMODE to mode MODE.
1290    Both modes may be floating, or both integer.
1291    UNSIGNEDP is nonzero if X is an unsigned value.
1292
1293    This can be done by referring to a part of X in place
1294    or by copying to a new temporary with conversion.
1295
1296    You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode.
1297
1298    This function *must not* call protect_from_queue
1299    except when putting X into an insn (in which case convert_move does it).  */
1300
1301 rtx
1302 convert_modes (mode, oldmode, x, unsignedp)
1303      enum machine_mode mode, oldmode;
1304      rtx x;
1305      int unsignedp;
1306 {
1307   register rtx temp;
1308
1309   /* If FROM is a SUBREG that indicates that we have already done at least
1310      the required extension, strip it.  */
1311
1312   if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
1313       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
1314       && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
1315     x = gen_lowpart (mode, x);
1316
1317   if (GET_MODE (x) != VOIDmode)
1318     oldmode = GET_MODE (x);
1319  
1320   if (mode == oldmode)
1321     return x;
1322
1323   /* There is one case that we must handle specially: If we are converting
1324      a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
1325      we are to interpret the constant as unsigned, gen_lowpart will do
1326      the wrong if the constant appears negative.  What we want to do is
1327      make the high-order word of the constant zero, not all ones.  */
1328
1329   if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
1330       && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
1331       && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
1332     {
1333       HOST_WIDE_INT val = INTVAL (x);
1334
1335       if (oldmode != VOIDmode
1336           && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
1337         {
1338           int width = GET_MODE_BITSIZE (oldmode);
1339
1340           /* We need to zero extend VAL.  */
1341           val &= ((HOST_WIDE_INT) 1 << width) - 1;
1342         }
1343
1344       return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
1345     }
1346
1347   /* We can do this with a gen_lowpart if both desired and current modes
1348      are integer, and this is either a constant integer, a register, or a
1349      non-volatile MEM.  Except for the constant case where MODE is no
1350      wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand.  */
1351
1352   if ((GET_CODE (x) == CONST_INT
1353        && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1354       || (GET_MODE_CLASS (mode) == MODE_INT
1355           && GET_MODE_CLASS (oldmode) == MODE_INT
1356           && (GET_CODE (x) == CONST_DOUBLE
1357               || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
1358                   && ((GET_CODE (x) == MEM && ! MEM_VOLATILE_P (x)
1359                        && direct_load[(int) mode])
1360                       || (GET_CODE (x) == REG
1361                           && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
1362                                                     GET_MODE_BITSIZE (GET_MODE (x)))))))))
1363     {
1364       /* ?? If we don't know OLDMODE, we have to assume here that
1365          X does not need sign- or zero-extension.   This may not be
1366          the case, but it's the best we can do.  */
1367       if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
1368           && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
1369         {
1370           HOST_WIDE_INT val = INTVAL (x);
1371           int width = GET_MODE_BITSIZE (oldmode);
1372
1373           /* We must sign or zero-extend in this case.  Start by
1374              zero-extending, then sign extend if we need to.  */
1375           val &= ((HOST_WIDE_INT) 1 << width) - 1;
1376           if (! unsignedp
1377               && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
1378             val |= (HOST_WIDE_INT) (-1) << width;
1379
1380           return GEN_INT (val);
1381         }
1382
1383       return gen_lowpart (mode, x);
1384     }
1385
1386   temp = gen_reg_rtx (mode);
1387   convert_move (temp, x, unsignedp);
1388   return temp;
1389 }
1390 \f
1391 /* Generate several move instructions to copy LEN bytes
1392    from block FROM to block TO.  (These are MEM rtx's with BLKmode).
1393    The caller must pass FROM and TO
1394     through protect_from_queue before calling.
1395    ALIGN (in bytes) is maximum alignment we can assume.  */
1396
1397 static void
1398 move_by_pieces (to, from, len, align)
1399      rtx to, from;
1400      int len, align;
1401 {
1402   struct move_by_pieces data;
1403   rtx to_addr = XEXP (to, 0), from_addr = XEXP (from, 0);
1404   int max_size = MOVE_MAX + 1;
1405
1406   data.offset = 0;
1407   data.to_addr = to_addr;
1408   data.from_addr = from_addr;
1409   data.to = to;
1410   data.from = from;
1411   data.autinc_to
1412     = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
1413        || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
1414   data.autinc_from
1415     = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
1416        || GET_CODE (from_addr) == POST_INC
1417        || GET_CODE (from_addr) == POST_DEC);
1418
1419   data.explicit_inc_from = 0;
1420   data.explicit_inc_to = 0;
1421   data.reverse
1422     = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1423   if (data.reverse) data.offset = len;
1424   data.len = len;
1425
1426   data.to_struct = MEM_IN_STRUCT_P (to);
1427   data.from_struct = MEM_IN_STRUCT_P (from);
1428
1429   /* If copying requires more than two move insns,
1430      copy addresses to registers (to make displacements shorter)
1431      and use post-increment if available.  */
1432   if (!(data.autinc_from && data.autinc_to)
1433       && move_by_pieces_ninsns (len, align) > 2)
1434     {
1435 #ifdef HAVE_PRE_DECREMENT
1436       if (data.reverse && ! data.autinc_from)
1437         {
1438           data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
1439           data.autinc_from = 1;
1440           data.explicit_inc_from = -1;
1441         }
1442 #endif
1443 #ifdef HAVE_POST_INCREMENT
1444       if (! data.autinc_from)
1445         {
1446           data.from_addr = copy_addr_to_reg (from_addr);
1447           data.autinc_from = 1;
1448           data.explicit_inc_from = 1;
1449         }
1450 #endif
1451       if (!data.autinc_from && CONSTANT_P (from_addr))
1452         data.from_addr = copy_addr_to_reg (from_addr);
1453 #ifdef HAVE_PRE_DECREMENT
1454       if (data.reverse && ! data.autinc_to)
1455         {
1456           data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1457           data.autinc_to = 1;
1458           data.explicit_inc_to = -1;
1459         }
1460 #endif
1461 #ifdef HAVE_POST_INCREMENT
1462       if (! data.reverse && ! data.autinc_to)
1463         {
1464           data.to_addr = copy_addr_to_reg (to_addr);
1465           data.autinc_to = 1;
1466           data.explicit_inc_to = 1;
1467         }
1468 #endif
1469       if (!data.autinc_to && CONSTANT_P (to_addr))
1470         data.to_addr = copy_addr_to_reg (to_addr);
1471     }
1472
1473   if (! SLOW_UNALIGNED_ACCESS
1474       || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1475     align = MOVE_MAX;
1476
1477   /* First move what we can in the largest integer mode, then go to
1478      successively smaller modes.  */
1479
1480   while (max_size > 1)
1481     {
1482       enum machine_mode mode = VOIDmode, tmode;
1483       enum insn_code icode;
1484
1485       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1486            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1487         if (GET_MODE_SIZE (tmode) < max_size)
1488           mode = tmode;
1489
1490       if (mode == VOIDmode)
1491         break;
1492
1493       icode = mov_optab->handlers[(int) mode].insn_code;
1494       if (icode != CODE_FOR_nothing
1495           && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
1496                            GET_MODE_SIZE (mode)))
1497         move_by_pieces_1 (GEN_FCN (icode), mode, &data);
1498
1499       max_size = GET_MODE_SIZE (mode);
1500     }
1501
1502   /* The code above should have handled everything.  */
1503   if (data.len > 0)
1504     abort ();
1505 }
1506
1507 /* Return number of insns required to move L bytes by pieces.
1508    ALIGN (in bytes) is maximum alignment we can assume.  */
1509
1510 static int
1511 move_by_pieces_ninsns (l, align)
1512      unsigned int l;
1513      int align;
1514 {
1515   register int n_insns = 0;
1516   int max_size = MOVE_MAX + 1;
1517
1518   if (! SLOW_UNALIGNED_ACCESS
1519       || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1520     align = MOVE_MAX;
1521
1522   while (max_size > 1)
1523     {
1524       enum machine_mode mode = VOIDmode, tmode;
1525       enum insn_code icode;
1526
1527       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1528            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1529         if (GET_MODE_SIZE (tmode) < max_size)
1530           mode = tmode;
1531
1532       if (mode == VOIDmode)
1533         break;
1534
1535       icode = mov_optab->handlers[(int) mode].insn_code;
1536       if (icode != CODE_FOR_nothing
1537           && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
1538                            GET_MODE_SIZE (mode)))
1539         n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1540
1541       max_size = GET_MODE_SIZE (mode);
1542     }
1543
1544   return n_insns;
1545 }
1546
1547 /* Subroutine of move_by_pieces.  Move as many bytes as appropriate
1548    with move instructions for mode MODE.  GENFUN is the gen_... function
1549    to make a move insn for that mode.  DATA has all the other info.  */
1550
1551 static void
1552 move_by_pieces_1 (genfun, mode, data)
1553      rtx (*genfun) PROTO ((rtx, ...));
1554      enum machine_mode mode;
1555      struct move_by_pieces *data;
1556 {
1557   register int size = GET_MODE_SIZE (mode);
1558   register rtx to1, from1;
1559
1560   while (data->len >= size)
1561     {
1562       if (data->reverse) data->offset -= size;
1563
1564       to1 = (data->autinc_to
1565              ? gen_rtx_MEM (mode, data->to_addr)
1566              : copy_rtx (change_address (data->to, mode,
1567                                          plus_constant (data->to_addr,
1568                                                         data->offset))));
1569       MEM_IN_STRUCT_P (to1) = data->to_struct;
1570
1571       from1
1572         = (data->autinc_from
1573            ? gen_rtx_MEM (mode, data->from_addr)
1574            : copy_rtx (change_address (data->from, mode,
1575                                        plus_constant (data->from_addr,
1576                                                       data->offset))));
1577       MEM_IN_STRUCT_P (from1) = data->from_struct;
1578
1579 #ifdef HAVE_PRE_DECREMENT
1580       if (data->explicit_inc_to < 0)
1581         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (-size)));
1582       if (data->explicit_inc_from < 0)
1583         emit_insn (gen_add2_insn (data->from_addr, GEN_INT (-size)));
1584 #endif
1585
1586       emit_insn ((*genfun) (to1, from1));
1587 #ifdef HAVE_POST_INCREMENT
1588       if (data->explicit_inc_to > 0)
1589         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1590       if (data->explicit_inc_from > 0)
1591         emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1592 #endif
1593
1594       if (! data->reverse) data->offset += size;
1595
1596       data->len -= size;
1597     }
1598 }
1599 \f
1600 /* Emit code to move a block Y to a block X.
1601    This may be done with string-move instructions,
1602    with multiple scalar move instructions, or with a library call.
1603
1604    Both X and Y must be MEM rtx's (perhaps inside VOLATILE)
1605    with mode BLKmode.
1606    SIZE is an rtx that says how long they are.
1607    ALIGN is the maximum alignment we can assume they have,
1608    measured in bytes. 
1609
1610    Return the address of the new block, if memcpy is called and returns it,
1611    0 otherwise.  */
1612
1613 rtx
1614 emit_block_move (x, y, size, align)
1615      rtx x, y;
1616      rtx size;
1617      int align;
1618 {
1619   rtx retval = 0;
1620
1621   if (GET_MODE (x) != BLKmode)
1622     abort ();
1623
1624   if (GET_MODE (y) != BLKmode)
1625     abort ();
1626
1627   x = protect_from_queue (x, 1);
1628   y = protect_from_queue (y, 0);
1629   size = protect_from_queue (size, 0);
1630
1631   if (GET_CODE (x) != MEM)
1632     abort ();
1633   if (GET_CODE (y) != MEM)
1634     abort ();
1635   if (size == 0)
1636     abort ();
1637
1638   if (GET_CODE (size) == CONST_INT
1639       && (move_by_pieces_ninsns (INTVAL (size), align) < MOVE_RATIO))
1640     move_by_pieces (x, y, INTVAL (size), align);
1641   else
1642     {
1643       /* Try the most limited insn first, because there's no point
1644          including more than one in the machine description unless
1645          the more limited one has some advantage.  */
1646
1647       rtx opalign = GEN_INT (align);
1648       enum machine_mode mode;
1649
1650       for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1651            mode = GET_MODE_WIDER_MODE (mode))
1652         {
1653           enum insn_code code = movstr_optab[(int) mode];
1654
1655           if (code != CODE_FOR_nothing
1656               /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1657                  here because if SIZE is less than the mode mask, as it is
1658                  returned by the macro, it will definitely be less than the
1659                  actual mode mask.  */
1660               && ((GET_CODE (size) == CONST_INT
1661                    && ((unsigned HOST_WIDE_INT) INTVAL (size)
1662                        <= (GET_MODE_MASK (mode) >> 1)))
1663                   || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1664               && (insn_operand_predicate[(int) code][0] == 0
1665                   || (*insn_operand_predicate[(int) code][0]) (x, BLKmode))
1666               && (insn_operand_predicate[(int) code][1] == 0
1667                   || (*insn_operand_predicate[(int) code][1]) (y, BLKmode))
1668               && (insn_operand_predicate[(int) code][3] == 0
1669                   || (*insn_operand_predicate[(int) code][3]) (opalign,
1670                                                                VOIDmode)))
1671             {
1672               rtx op2;
1673               rtx last = get_last_insn ();
1674               rtx pat;
1675
1676               op2 = convert_to_mode (mode, size, 1);
1677               if (insn_operand_predicate[(int) code][2] != 0
1678                   && ! (*insn_operand_predicate[(int) code][2]) (op2, mode))
1679                 op2 = copy_to_mode_reg (mode, op2);
1680
1681               pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1682               if (pat)
1683                 {
1684                   emit_insn (pat);
1685                   return 0;
1686                 }
1687               else
1688                 delete_insns_since (last);
1689             }
1690         }
1691
1692 #ifdef TARGET_MEM_FUNCTIONS
1693       retval
1694         = emit_library_call_value (memcpy_libfunc, NULL_RTX, 0,
1695                                    ptr_mode, 3, XEXP (x, 0), Pmode,
1696                                    XEXP (y, 0), Pmode,
1697                                    convert_to_mode (TYPE_MODE (sizetype), size,
1698                                                     TREE_UNSIGNED (sizetype)),
1699                                    TYPE_MODE (sizetype));
1700 #else
1701       emit_library_call (bcopy_libfunc, 0,
1702                          VOIDmode, 3, XEXP (y, 0), Pmode,
1703                          XEXP (x, 0), Pmode,
1704                          convert_to_mode (TYPE_MODE (integer_type_node), size,
1705                                           TREE_UNSIGNED (integer_type_node)),
1706                          TYPE_MODE (integer_type_node));
1707 #endif
1708     }
1709
1710   return retval;
1711 }
1712 \f
1713 /* Copy all or part of a value X into registers starting at REGNO.
1714    The number of registers to be filled is NREGS.  */
1715
1716 void
1717 move_block_to_reg (regno, x, nregs, mode)
1718      int regno;
1719      rtx x;
1720      int nregs;
1721      enum machine_mode mode;
1722 {
1723   int i;
1724 #ifdef HAVE_load_multiple
1725   rtx pat; 
1726   rtx last;
1727 #endif
1728
1729   if (nregs == 0)
1730     return;
1731
1732   if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1733     x = validize_mem (force_const_mem (mode, x));
1734
1735   /* See if the machine can do this with a load multiple insn.  */
1736 #ifdef HAVE_load_multiple
1737   if (HAVE_load_multiple)
1738     {
1739       last = get_last_insn ();
1740       pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1741                                GEN_INT (nregs));
1742       if (pat)
1743         {
1744           emit_insn (pat);
1745           return;
1746         }
1747       else
1748         delete_insns_since (last);
1749     }
1750 #endif
1751
1752   for (i = 0; i < nregs; i++)
1753     emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1754                     operand_subword_force (x, i, mode));
1755 }
1756
1757 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1758    The number of registers to be filled is NREGS.  SIZE indicates the number
1759    of bytes in the object X.  */
1760
1761
1762 void
1763 move_block_from_reg (regno, x, nregs, size)
1764      int regno;
1765      rtx x;
1766      int nregs;
1767      int size;
1768 {
1769   int i;
1770 #ifdef HAVE_store_multiple
1771   rtx pat; 
1772   rtx last;
1773 #endif
1774   enum machine_mode mode;
1775
1776   /* If SIZE is that of a mode no bigger than a word, just use that
1777      mode's store operation.  */
1778   if (size <= UNITS_PER_WORD
1779       && (mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0)) != BLKmode)
1780     {
1781       emit_move_insn (change_address (x, mode, NULL),
1782                       gen_rtx_REG (mode, regno));
1783       return;
1784     }
1785     
1786   /* Blocks smaller than a word on a BYTES_BIG_ENDIAN machine must be aligned
1787      to the left before storing to memory.  Note that the previous test
1788      doesn't handle all cases (e.g. SIZE == 3).  */
1789   if (size < UNITS_PER_WORD && BYTES_BIG_ENDIAN)
1790     {
1791       rtx tem = operand_subword (x, 0, 1, BLKmode);
1792       rtx shift;
1793
1794       if (tem == 0)
1795         abort ();
1796
1797       shift = expand_shift (LSHIFT_EXPR, word_mode,
1798                             gen_rtx_REG (word_mode, regno),
1799                             build_int_2 ((UNITS_PER_WORD - size)
1800                                          * BITS_PER_UNIT, 0), NULL_RTX, 0);
1801       emit_move_insn (tem, shift);
1802       return;
1803     }
1804
1805   /* See if the machine can do this with a store multiple insn.  */
1806 #ifdef HAVE_store_multiple
1807   if (HAVE_store_multiple)
1808     {
1809       last = get_last_insn ();
1810       pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1811                                 GEN_INT (nregs));
1812       if (pat)
1813         {
1814           emit_insn (pat);
1815           return;
1816         }
1817       else
1818         delete_insns_since (last);
1819     }
1820 #endif
1821
1822   for (i = 0; i < nregs; i++)
1823     {
1824       rtx tem = operand_subword (x, i, 1, BLKmode);
1825
1826       if (tem == 0)
1827         abort ();
1828
1829       emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1830     }
1831 }
1832
1833 /* Emit code to move a block SRC to a block DST, where DST is non-consecutive
1834    registers represented by a PARALLEL.  SSIZE represents the total size of
1835    block SRC in bytes, or -1 if not known.  ALIGN is the known alignment of
1836    SRC in bits.  */
1837 /* ??? If SSIZE % UNITS_PER_WORD != 0, we make the blatent assumption that
1838    the balance will be in what would be the low-order memory addresses, i.e.
1839    left justified for big endian, right justified for little endian.  This
1840    happens to be true for the targets currently using this support.  If this
1841    ever changes, a new target macro along the lines of FUNCTION_ARG_PADDING
1842    would be needed.  */
1843
1844 void
1845 emit_group_load (dst, orig_src, ssize, align)
1846      rtx dst, orig_src;
1847      int align, ssize;
1848 {
1849   rtx *tmps, src;
1850   int start, i;
1851
1852   if (GET_CODE (dst) != PARALLEL)
1853     abort ();
1854
1855   /* Check for a NULL entry, used to indicate that the parameter goes
1856      both on the stack and in registers.  */
1857   if (XEXP (XVECEXP (dst, 0, 0), 0))
1858     start = 0;
1859   else
1860     start = 1;
1861
1862   tmps = (rtx *) alloca (sizeof(rtx) * XVECLEN (dst, 0));
1863
1864   /* If we won't be loading directly from memory, protect the real source
1865      from strange tricks we might play.  */
1866   src = orig_src;
1867   if (GET_CODE (src) != MEM)
1868     {
1869       src = gen_reg_rtx (GET_MODE (orig_src));
1870       emit_move_insn (src, orig_src);
1871     }
1872
1873   /* Process the pieces.  */
1874   for (i = start; i < XVECLEN (dst, 0); i++)
1875     {
1876       enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1877       int bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1878       int bytelen = GET_MODE_SIZE (mode);
1879       int shift = 0;
1880
1881       /* Handle trailing fragments that run over the size of the struct.  */
1882       if (ssize >= 0 && bytepos + bytelen > ssize)
1883         {
1884           shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1885           bytelen = ssize - bytepos;
1886           if (bytelen <= 0)
1887             abort();
1888         }
1889
1890       /* Optimize the access just a bit.  */
1891       if (GET_CODE (src) == MEM
1892           && align*BITS_PER_UNIT >= GET_MODE_ALIGNMENT (mode)
1893           && bytepos*BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1894           && bytelen == GET_MODE_SIZE (mode))
1895         {
1896           tmps[i] = gen_reg_rtx (mode);
1897           emit_move_insn (tmps[i],
1898                           change_address (src, mode,
1899                                           plus_constant (XEXP (src, 0),
1900                                                          bytepos)));
1901         }
1902       else
1903         {
1904           tmps[i] = extract_bit_field (src, bytelen*BITS_PER_UNIT,
1905                                        bytepos*BITS_PER_UNIT, 1, NULL_RTX,
1906                                        mode, mode, align, ssize);
1907         }
1908
1909       if (BYTES_BIG_ENDIAN && shift)
1910         {
1911           expand_binop (mode, ashl_optab, tmps[i], GEN_INT (shift),
1912                         tmps[i], 0, OPTAB_WIDEN);
1913         }
1914     }
1915   emit_queue();
1916
1917   /* Copy the extracted pieces into the proper (probable) hard regs.  */
1918   for (i = start; i < XVECLEN (dst, 0); i++)
1919     emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0), tmps[i]);
1920 }
1921
1922 /* Emit code to move a block SRC to a block DST, where SRC is non-consecutive
1923    registers represented by a PARALLEL.  SSIZE represents the total size of
1924    block DST, or -1 if not known.  ALIGN is the known alignment of DST.  */
1925
1926 void
1927 emit_group_store (orig_dst, src, ssize, align)
1928      rtx orig_dst, src;
1929      int ssize, align;
1930 {
1931   rtx *tmps, dst;
1932   int start, i;
1933
1934   if (GET_CODE (src) != PARALLEL)
1935     abort ();
1936
1937   /* Check for a NULL entry, used to indicate that the parameter goes
1938      both on the stack and in registers.  */
1939   if (XEXP (XVECEXP (src, 0, 0), 0))
1940     start = 0;
1941   else
1942     start = 1;
1943
1944   tmps = (rtx *) alloca (sizeof(rtx) * XVECLEN (src, 0));
1945
1946   /* Copy the (probable) hard regs into pseudos.  */
1947   for (i = start; i < XVECLEN (src, 0); i++)
1948     {
1949       rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1950       tmps[i] = gen_reg_rtx (GET_MODE (reg));
1951       emit_move_insn (tmps[i], reg);
1952     }
1953   emit_queue();
1954
1955   /* If we won't be storing directly into memory, protect the real destination
1956      from strange tricks we might play.  */
1957   dst = orig_dst;
1958   if (GET_CODE (dst) != MEM)
1959     {
1960       dst = gen_reg_rtx (GET_MODE (orig_dst));
1961       /* Make life a bit easier for combine.  */
1962       emit_move_insn (dst, const0_rtx);
1963     }
1964   else if (! MEM_IN_STRUCT_P (dst))
1965     {
1966       /* store_bit_field requires that memory operations have
1967          mem_in_struct_p set; we might not.  */
1968
1969       dst = copy_rtx (orig_dst);
1970       MEM_IN_STRUCT_P (dst) = 1;
1971     }
1972
1973   /* Process the pieces.  */
1974   for (i = start; i < XVECLEN (src, 0); i++)
1975     {
1976       int bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1977       enum machine_mode mode = GET_MODE (tmps[i]);
1978       int bytelen = GET_MODE_SIZE (mode);
1979
1980       /* Handle trailing fragments that run over the size of the struct.  */
1981       if (ssize >= 0 && bytepos + bytelen > ssize)
1982         {
1983           if (BYTES_BIG_ENDIAN)
1984             {
1985               int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1986               expand_binop (mode, ashr_optab, tmps[i], GEN_INT (shift),
1987                             tmps[i], 0, OPTAB_WIDEN);
1988             }
1989           bytelen = ssize - bytepos;
1990         }
1991
1992       /* Optimize the access just a bit.  */
1993       if (GET_CODE (dst) == MEM
1994           && align*BITS_PER_UNIT >= GET_MODE_ALIGNMENT (mode)
1995           && bytepos*BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1996           && bytelen == GET_MODE_SIZE (mode))
1997         {
1998           emit_move_insn (change_address (dst, mode,
1999                                           plus_constant (XEXP (dst, 0),
2000                                                          bytepos)),
2001                           tmps[i]);
2002         }
2003       else
2004         {
2005           store_bit_field (dst, bytelen*BITS_PER_UNIT, bytepos*BITS_PER_UNIT,
2006                            mode, tmps[i], align, ssize);
2007         }
2008     }
2009   emit_queue();
2010
2011   /* Copy from the pseudo into the (probable) hard reg.  */
2012   if (GET_CODE (dst) == REG)
2013     emit_move_insn (orig_dst, dst);
2014 }
2015
2016 /* Add a USE expression for REG to the (possibly empty) list pointed
2017    to by CALL_FUSAGE.  REG must denote a hard register.  */
2018
2019 void
2020 use_reg (call_fusage, reg)
2021      rtx *call_fusage, reg;
2022 {
2023   if (GET_CODE (reg) != REG
2024       || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
2025     abort();
2026
2027   *call_fusage
2028     = gen_rtx_EXPR_LIST (VOIDmode,
2029                          gen_rtx_USE (VOIDmode, reg), *call_fusage);
2030 }
2031
2032 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2033    starting at REGNO.  All of these registers must be hard registers.  */
2034
2035 void
2036 use_regs (call_fusage, regno, nregs)
2037      rtx *call_fusage;
2038      int regno;
2039      int nregs;
2040 {
2041   int i;
2042
2043   if (regno + nregs > FIRST_PSEUDO_REGISTER)
2044     abort ();
2045
2046   for (i = 0; i < nregs; i++)
2047     use_reg (call_fusage, gen_rtx_REG (reg_raw_mode[regno + i], regno + i));
2048 }
2049
2050 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2051    PARALLEL REGS.  This is for calls that pass values in multiple
2052    non-contiguous locations.  The Irix 6 ABI has examples of this.  */
2053
2054 void
2055 use_group_regs (call_fusage, regs)
2056      rtx *call_fusage;
2057      rtx regs;
2058 {
2059   int i;
2060
2061   for (i = 0; i < XVECLEN (regs, 0); i++)
2062     {
2063       rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2064
2065       /* A NULL entry means the parameter goes both on the stack and in
2066          registers.  This can also be a MEM for targets that pass values
2067          partially on the stack and partially in registers.  */
2068       if (reg != 0 && GET_CODE (reg) == REG)
2069         use_reg (call_fusage, reg);
2070     }
2071 }
2072 \f
2073 /* Generate several move instructions to clear LEN bytes of block TO.
2074    (A MEM rtx with BLKmode).   The caller must pass TO through
2075    protect_from_queue before calling. ALIGN (in bytes) is maximum alignment
2076    we can assume.  */
2077
2078 static void
2079 clear_by_pieces (to, len, align)
2080      rtx to;
2081      int len, align;
2082 {
2083   struct clear_by_pieces data;
2084   rtx to_addr = XEXP (to, 0);
2085   int max_size = MOVE_MAX + 1;
2086
2087   data.offset = 0;
2088   data.to_addr = to_addr;
2089   data.to = to;
2090   data.autinc_to
2091     = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2092        || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2093
2094   data.explicit_inc_to = 0;
2095   data.reverse
2096     = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2097   if (data.reverse) data.offset = len;
2098   data.len = len;
2099
2100   data.to_struct = MEM_IN_STRUCT_P (to);
2101
2102   /* If copying requires more than two move insns,
2103      copy addresses to registers (to make displacements shorter)
2104      and use post-increment if available.  */
2105   if (!data.autinc_to
2106       && move_by_pieces_ninsns (len, align) > 2)
2107     {
2108 #ifdef HAVE_PRE_DECREMENT
2109       if (data.reverse && ! data.autinc_to)
2110         {
2111           data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
2112           data.autinc_to = 1;
2113           data.explicit_inc_to = -1;
2114         }
2115 #endif
2116 #ifdef HAVE_POST_INCREMENT
2117       if (! data.reverse && ! data.autinc_to)
2118         {
2119           data.to_addr = copy_addr_to_reg (to_addr);
2120           data.autinc_to = 1;
2121           data.explicit_inc_to = 1;
2122         }
2123 #endif
2124       if (!data.autinc_to && CONSTANT_P (to_addr))
2125         data.to_addr = copy_addr_to_reg (to_addr);
2126     }
2127
2128   if (! SLOW_UNALIGNED_ACCESS
2129       || align > MOVE_MAX || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2130     align = MOVE_MAX;
2131
2132   /* First move what we can in the largest integer mode, then go to
2133      successively smaller modes.  */
2134
2135   while (max_size > 1)
2136     {
2137       enum machine_mode mode = VOIDmode, tmode;
2138       enum insn_code icode;
2139
2140       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2141            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2142         if (GET_MODE_SIZE (tmode) < max_size)
2143           mode = tmode;
2144
2145       if (mode == VOIDmode)
2146         break;
2147
2148       icode = mov_optab->handlers[(int) mode].insn_code;
2149       if (icode != CODE_FOR_nothing
2150           && align >= MIN (BIGGEST_ALIGNMENT / BITS_PER_UNIT,
2151                            GET_MODE_SIZE (mode)))
2152         clear_by_pieces_1 (GEN_FCN (icode), mode, &data);
2153
2154       max_size = GET_MODE_SIZE (mode);
2155     }
2156
2157   /* The code above should have handled everything.  */
2158   if (data.len != 0)
2159     abort ();
2160 }
2161
2162 /* Subroutine of clear_by_pieces.  Clear as many bytes as appropriate
2163    with move instructions for mode MODE.  GENFUN is the gen_... function
2164    to make a move insn for that mode.  DATA has all the other info.  */
2165
2166 static void
2167 clear_by_pieces_1 (genfun, mode, data)
2168      rtx (*genfun) PROTO ((rtx, ...));
2169      enum machine_mode mode;
2170      struct clear_by_pieces *data;
2171 {
2172   register int size = GET_MODE_SIZE (mode);
2173   register rtx to1;
2174
2175   while (data->len >= size)
2176     {
2177       if (data->reverse) data->offset -= size;
2178
2179       to1 = (data->autinc_to
2180              ? gen_rtx_MEM (mode, data->to_addr)
2181              : copy_rtx (change_address (data->to, mode,
2182                                          plus_constant (data->to_addr,
2183                                                         data->offset))));
2184       MEM_IN_STRUCT_P (to1) = data->to_struct;
2185
2186 #ifdef HAVE_PRE_DECREMENT
2187       if (data->explicit_inc_to < 0)
2188         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (-size)));
2189 #endif
2190
2191       emit_insn ((*genfun) (to1, const0_rtx));
2192 #ifdef HAVE_POST_INCREMENT
2193       if (data->explicit_inc_to > 0)
2194         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2195 #endif
2196
2197       if (! data->reverse) data->offset += size;
2198
2199       data->len -= size;
2200     }
2201 }
2202 \f
2203 /* Write zeros through the storage of OBJECT.
2204    If OBJECT has BLKmode, SIZE is its length in bytes and ALIGN is
2205    the maximum alignment we can is has, measured in bytes.
2206
2207    If we call a function that returns the length of the block, return it.  */
2208
2209 rtx
2210 clear_storage (object, size, align)
2211      rtx object;
2212      rtx size;
2213      int align;
2214 {
2215   rtx retval = 0;
2216
2217   if (GET_MODE (object) == BLKmode)
2218     {
2219       object = protect_from_queue (object, 1);
2220       size = protect_from_queue (size, 0);
2221
2222       if (GET_CODE (size) == CONST_INT
2223           && (move_by_pieces_ninsns (INTVAL (size), align) < MOVE_RATIO))
2224         clear_by_pieces (object, INTVAL (size), align);
2225
2226       else
2227         {
2228           /* Try the most limited insn first, because there's no point
2229              including more than one in the machine description unless
2230              the more limited one has some advantage.  */
2231
2232           rtx opalign = GEN_INT (align);
2233           enum machine_mode mode;
2234
2235           for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2236                mode = GET_MODE_WIDER_MODE (mode))
2237             {
2238               enum insn_code code = clrstr_optab[(int) mode];
2239
2240               if (code != CODE_FOR_nothing
2241                   /* We don't need MODE to be narrower than
2242                      BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2243                      the mode mask, as it is returned by the macro, it will
2244                      definitely be less than the actual mode mask.  */
2245                   && ((GET_CODE (size) == CONST_INT
2246                        && ((unsigned HOST_WIDE_INT) INTVAL (size)
2247                            <= (GET_MODE_MASK (mode) >> 1)))
2248                       || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2249                   && (insn_operand_predicate[(int) code][0] == 0
2250                       || (*insn_operand_predicate[(int) code][0]) (object,
2251                                                                    BLKmode))
2252                   && (insn_operand_predicate[(int) code][2] == 0
2253                       || (*insn_operand_predicate[(int) code][2]) (opalign,
2254                                                                    VOIDmode)))
2255                 {
2256                   rtx op1;
2257                   rtx last = get_last_insn ();
2258                   rtx pat;
2259
2260                   op1 = convert_to_mode (mode, size, 1);
2261                   if (insn_operand_predicate[(int) code][1] != 0
2262                       && ! (*insn_operand_predicate[(int) code][1]) (op1,
2263                                                                      mode))
2264                     op1 = copy_to_mode_reg (mode, op1);
2265
2266                   pat = GEN_FCN ((int) code) (object, op1, opalign);
2267                   if (pat)
2268                     {
2269                       emit_insn (pat);
2270                       return 0;
2271                     }
2272                   else
2273                     delete_insns_since (last);
2274                 }
2275             }
2276
2277
2278 #ifdef TARGET_MEM_FUNCTIONS
2279           retval
2280             = emit_library_call_value (memset_libfunc, NULL_RTX, 0,
2281                                        ptr_mode, 3,
2282                                        XEXP (object, 0), Pmode,
2283                                        const0_rtx,
2284                                        TYPE_MODE (integer_type_node),
2285                                        convert_to_mode
2286                                        (TYPE_MODE (sizetype), size,
2287                                         TREE_UNSIGNED (sizetype)),
2288                                        TYPE_MODE (sizetype));
2289 #else
2290           emit_library_call (bzero_libfunc, 0,
2291                              VOIDmode, 2,
2292                              XEXP (object, 0), Pmode,   
2293                              convert_to_mode
2294                              (TYPE_MODE (integer_type_node), size,
2295                               TREE_UNSIGNED (integer_type_node)),
2296                              TYPE_MODE (integer_type_node));
2297 #endif
2298         }
2299     }
2300   else
2301     emit_move_insn (object, CONST0_RTX (GET_MODE (object)));
2302
2303   return retval;
2304 }
2305
2306 /* Generate code to copy Y into X.
2307    Both Y and X must have the same mode, except that
2308    Y can be a constant with VOIDmode.
2309    This mode cannot be BLKmode; use emit_block_move for that.
2310
2311    Return the last instruction emitted.  */
2312
2313 rtx
2314 emit_move_insn (x, y)
2315      rtx x, y;
2316 {
2317   enum machine_mode mode = GET_MODE (x);
2318
2319   x = protect_from_queue (x, 1);
2320   y = protect_from_queue (y, 0);
2321
2322   if (mode == BLKmode || (GET_MODE (y) != mode && GET_MODE (y) != VOIDmode))
2323     abort ();
2324
2325   if (CONSTANT_P (y) && ! LEGITIMATE_CONSTANT_P (y))
2326     y = force_const_mem (mode, y);
2327
2328   /* If X or Y are memory references, verify that their addresses are valid
2329      for the machine.  */
2330   if (GET_CODE (x) == MEM
2331       && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
2332            && ! push_operand (x, GET_MODE (x)))
2333           || (flag_force_addr
2334               && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
2335     x = change_address (x, VOIDmode, XEXP (x, 0));
2336
2337   if (GET_CODE (y) == MEM
2338       && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
2339           || (flag_force_addr
2340               && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
2341     y = change_address (y, VOIDmode, XEXP (y, 0));
2342
2343   if (mode == BLKmode)
2344     abort ();
2345
2346   return emit_move_insn_1 (x, y);
2347 }
2348
2349 /* Low level part of emit_move_insn.
2350    Called just like emit_move_insn, but assumes X and Y
2351    are basically valid.  */
2352
2353 rtx
2354 emit_move_insn_1 (x, y)
2355      rtx x, y;
2356 {
2357   enum machine_mode mode = GET_MODE (x);
2358   enum machine_mode submode;
2359   enum mode_class class = GET_MODE_CLASS (mode);
2360   int i;
2361
2362   if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2363     return
2364       emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
2365
2366   /* Expand complex moves by moving real part and imag part, if possible.  */
2367   else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
2368            && BLKmode != (submode = mode_for_size ((GET_MODE_UNIT_SIZE (mode)
2369                                                     * BITS_PER_UNIT),
2370                                                    (class == MODE_COMPLEX_INT
2371                                                     ? MODE_INT : MODE_FLOAT),
2372                                                    0))
2373            && (mov_optab->handlers[(int) submode].insn_code
2374                != CODE_FOR_nothing))
2375     {
2376       /* Don't split destination if it is a stack push.  */
2377       int stack = push_operand (x, GET_MODE (x));
2378
2379       /* If this is a stack, push the highpart first, so it
2380          will be in the argument order.
2381
2382          In that case, change_address is used only to convert
2383          the mode, not to change the address.  */
2384       if (stack)
2385         {
2386           /* Note that the real part always precedes the imag part in memory
2387              regardless of machine's endianness.  */
2388 #ifdef STACK_GROWS_DOWNWARD
2389           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2390                      (gen_rtx_MEM (submode, (XEXP (x, 0))),
2391                       gen_imagpart (submode, y)));
2392           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2393                      (gen_rtx_MEM (submode, (XEXP (x, 0))),
2394                       gen_realpart (submode, y)));
2395 #else
2396           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2397                      (gen_rtx_MEM (submode, (XEXP (x, 0))),
2398                       gen_realpart (submode, y)));
2399           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2400                      (gen_rtx_MEM (submode, (XEXP (x, 0))),
2401                       gen_imagpart (submode, y)));
2402 #endif
2403         }
2404       else
2405         {
2406           /* Show the output dies here.  */
2407           if (x != y)
2408             emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2409
2410           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2411                      (gen_realpart (submode, x), gen_realpart (submode, y)));
2412           emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
2413                      (gen_imagpart (submode, x), gen_imagpart (submode, y)));
2414         }
2415
2416       return get_last_insn ();
2417     }
2418
2419   /* This will handle any multi-word mode that lacks a move_insn pattern.
2420      However, you will get better code if you define such patterns,
2421      even if they must turn into multiple assembler instructions.  */
2422   else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
2423     {
2424       rtx last_insn = 0;
2425       
2426 #ifdef PUSH_ROUNDING
2427
2428       /* If X is a push on the stack, do the push now and replace
2429          X with a reference to the stack pointer.  */
2430       if (push_operand (x, GET_MODE (x)))
2431         {
2432           anti_adjust_stack (GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
2433           x = change_address (x, VOIDmode, stack_pointer_rtx);
2434         }
2435 #endif
2436                              
2437       /* Show the output dies here.  */
2438       if (x != y)
2439         emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2440
2441       for (i = 0;
2442            i < (GET_MODE_SIZE (mode)  + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2443            i++)
2444         {
2445           rtx xpart = operand_subword (x, i, 1, mode);
2446           rtx ypart = operand_subword (y, i, 1, mode);
2447
2448           /* If we can't get a part of Y, put Y into memory if it is a
2449              constant.  Otherwise, force it into a register.  If we still
2450              can't get a part of Y, abort.  */
2451           if (ypart == 0 && CONSTANT_P (y))
2452             {
2453               y = force_const_mem (mode, y);
2454               ypart = operand_subword (y, i, 1, mode);
2455             }
2456           else if (ypart == 0)
2457             ypart = operand_subword_force (y, i, mode);
2458
2459           if (xpart == 0 || ypart == 0)
2460             abort ();
2461
2462           last_insn = emit_move_insn (xpart, ypart);
2463         }
2464
2465       return last_insn;
2466     }
2467   else
2468     abort ();
2469 }
2470 \f
2471 /* Pushing data onto the stack.  */
2472
2473 /* Push a block of length SIZE (perhaps variable)
2474    and return an rtx to address the beginning of the block.
2475    Note that it is not possible for the value returned to be a QUEUED.
2476    The value may be virtual_outgoing_args_rtx.
2477
2478    EXTRA is the number of bytes of padding to push in addition to SIZE.
2479    BELOW nonzero means this padding comes at low addresses;
2480    otherwise, the padding comes at high addresses.  */
2481
2482 rtx
2483 push_block (size, extra, below)
2484      rtx size;
2485      int extra, below;
2486 {
2487   register rtx temp;
2488
2489   size = convert_modes (Pmode, ptr_mode, size, 1);
2490   if (CONSTANT_P (size))
2491     anti_adjust_stack (plus_constant (size, extra));
2492   else if (GET_CODE (size) == REG && extra == 0)
2493     anti_adjust_stack (size);
2494   else
2495     {
2496       rtx temp = copy_to_mode_reg (Pmode, size);
2497       if (extra != 0)
2498         temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
2499                              temp, 0, OPTAB_LIB_WIDEN);
2500       anti_adjust_stack (temp);
2501     }
2502
2503 #ifdef STACK_GROWS_DOWNWARD
2504   temp = virtual_outgoing_args_rtx;
2505   if (extra != 0 && below)
2506     temp = plus_constant (temp, extra);
2507 #else
2508   if (GET_CODE (size) == CONST_INT)
2509     temp = plus_constant (virtual_outgoing_args_rtx,
2510                           - INTVAL (size) - (below ? 0 : extra));
2511   else if (extra != 0 && !below)
2512     temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2513                     negate_rtx (Pmode, plus_constant (size, extra)));
2514   else
2515     temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2516                     negate_rtx (Pmode, size));
2517 #endif
2518
2519   return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
2520 }
2521
2522 rtx
2523 gen_push_operand ()
2524 {
2525   return gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
2526 }
2527
2528 /* Return an rtx for the address of the beginning of a as-if-it-was-pushed
2529    block of SIZE bytes.  */
2530
2531 static rtx
2532 get_push_address (size)
2533         int size;
2534 {
2535   register rtx temp;
2536
2537   if (STACK_PUSH_CODE == POST_DEC)
2538     temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (size));
2539   else if (STACK_PUSH_CODE == POST_INC)
2540     temp = gen_rtx_MINUS (Pmode, stack_pointer_rtx, GEN_INT (size));
2541   else
2542     temp = stack_pointer_rtx;
2543
2544   return copy_to_reg (temp);
2545 }
2546
2547 /* Generate code to push X onto the stack, assuming it has mode MODE and
2548    type TYPE.
2549    MODE is redundant except when X is a CONST_INT (since they don't
2550    carry mode info).
2551    SIZE is an rtx for the size of data to be copied (in bytes),
2552    needed only if X is BLKmode.
2553
2554    ALIGN (in bytes) is maximum alignment we can assume.
2555
2556    If PARTIAL and REG are both nonzero, then copy that many of the first
2557    words of X into registers starting with REG, and push the rest of X.
2558    The amount of space pushed is decreased by PARTIAL words,
2559    rounded *down* to a multiple of PARM_BOUNDARY.
2560    REG must be a hard register in this case.
2561    If REG is zero but PARTIAL is not, take any all others actions for an
2562    argument partially in registers, but do not actually load any
2563    registers.
2564
2565    EXTRA is the amount in bytes of extra space to leave next to this arg.
2566    This is ignored if an argument block has already been allocated.
2567
2568    On a machine that lacks real push insns, ARGS_ADDR is the address of
2569    the bottom of the argument block for this call.  We use indexing off there
2570    to store the arg.  On machines with push insns, ARGS_ADDR is 0 when a
2571    argument block has not been preallocated.
2572
2573    ARGS_SO_FAR is the size of args previously pushed for this call.
2574
2575    REG_PARM_STACK_SPACE is nonzero if functions require stack space
2576    for arguments passed in registers.  If nonzero, it will be the number
2577    of bytes required.  */
2578
2579 void
2580 emit_push_insn (x, mode, type, size, align, partial, reg, extra,
2581                 args_addr, args_so_far, reg_parm_stack_space)
2582      register rtx x;
2583      enum machine_mode mode;
2584      tree type;
2585      rtx size;
2586      int align;
2587      int partial;
2588      rtx reg;
2589      int extra;
2590      rtx args_addr;
2591      rtx args_so_far;
2592      int reg_parm_stack_space;
2593 {
2594   rtx xinner;
2595   enum direction stack_direction
2596 #ifdef STACK_GROWS_DOWNWARD
2597     = downward;
2598 #else
2599     = upward;
2600 #endif
2601
2602   /* Decide where to pad the argument: `downward' for below,
2603      `upward' for above, or `none' for don't pad it.
2604      Default is below for small data on big-endian machines; else above.  */
2605   enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
2606
2607   /* Invert direction if stack is post-update.  */
2608   if (STACK_PUSH_CODE == POST_INC || STACK_PUSH_CODE == POST_DEC)
2609     if (where_pad != none)
2610       where_pad = (where_pad == downward ? upward : downward);
2611
2612   xinner = x = protect_from_queue (x, 0);
2613
2614   if (mode == BLKmode)
2615     {
2616       /* Copy a block into the stack, entirely or partially.  */
2617
2618       register rtx temp;
2619       int used = partial * UNITS_PER_WORD;
2620       int offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
2621       int skip;
2622       
2623       if (size == 0)
2624         abort ();
2625
2626       used -= offset;
2627
2628       /* USED is now the # of bytes we need not copy to the stack
2629          because registers will take care of them.  */
2630
2631       if (partial != 0)
2632         xinner = change_address (xinner, BLKmode,
2633                                  plus_constant (XEXP (xinner, 0), used));
2634
2635       /* If the partial register-part of the arg counts in its stack size,
2636          skip the part of stack space corresponding to the registers.
2637          Otherwise, start copying to the beginning of the stack space,
2638          by setting SKIP to 0.  */
2639       skip = (reg_parm_stack_space == 0) ? 0 : used;
2640
2641 #ifdef PUSH_ROUNDING
2642       /* Do it with several push insns if that doesn't take lots of insns
2643          and if there is no difficulty with push insns that skip bytes
2644          on the stack for alignment purposes.  */
2645       if (args_addr == 0
2646           && GET_CODE (size) == CONST_INT
2647           && skip == 0
2648           && (move_by_pieces_ninsns ((unsigned) INTVAL (size) - used, align)
2649               < MOVE_RATIO)
2650           /* Here we avoid the case of a structure whose weak alignment
2651              forces many pushes of a small amount of data,
2652              and such small pushes do rounding that causes trouble.  */
2653           && ((! SLOW_UNALIGNED_ACCESS)
2654               || align >= BIGGEST_ALIGNMENT / BITS_PER_UNIT
2655               || PUSH_ROUNDING (align) == align)
2656           && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
2657         {
2658           /* Push padding now if padding above and stack grows down,
2659              or if padding below and stack grows up.
2660              But if space already allocated, this has already been done.  */
2661           if (extra && args_addr == 0
2662               && where_pad != none && where_pad != stack_direction)
2663             anti_adjust_stack (GEN_INT (extra));
2664
2665           move_by_pieces (gen_rtx_MEM (BLKmode, gen_push_operand ()), xinner,
2666                           INTVAL (size) - used, align);
2667
2668           if (flag_check_memory_usage && ! in_check_memory_usage)
2669             {
2670               rtx temp;
2671               
2672               in_check_memory_usage = 1;
2673               temp = get_push_address (INTVAL(size) - used);
2674               if (GET_CODE (x) == MEM && type && AGGREGATE_TYPE_P (type))
2675                 emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
2676                                    temp, ptr_mode,
2677                                    XEXP (xinner, 0), ptr_mode,
2678                                    GEN_INT (INTVAL(size) - used),
2679                                    TYPE_MODE (sizetype));
2680               else
2681                 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
2682                                    temp, ptr_mode,
2683                                    GEN_INT (INTVAL(size) - used),
2684                                    TYPE_MODE (sizetype),
2685                                    GEN_INT (MEMORY_USE_RW),
2686                                    TYPE_MODE (integer_type_node));
2687               in_check_memory_usage = 0;
2688             }
2689         }
2690       else
2691 #endif /* PUSH_ROUNDING */
2692         {
2693           /* Otherwise make space on the stack and copy the data
2694              to the address of that space.  */
2695
2696           /* Deduct words put into registers from the size we must copy.  */
2697           if (partial != 0)
2698             {
2699               if (GET_CODE (size) == CONST_INT)
2700                 size = GEN_INT (INTVAL (size) - used);
2701               else
2702                 size = expand_binop (GET_MODE (size), sub_optab, size,
2703                                      GEN_INT (used), NULL_RTX, 0,
2704                                      OPTAB_LIB_WIDEN);
2705             }
2706
2707           /* Get the address of the stack space.
2708              In this case, we do not deal with EXTRA separately.
2709              A single stack adjust will do.  */
2710           if (! args_addr)
2711             {
2712               temp = push_block (size, extra, where_pad == downward);
2713               extra = 0;
2714             }
2715           else if (GET_CODE (args_so_far) == CONST_INT)
2716             temp = memory_address (BLKmode,
2717                                    plus_constant (args_addr,
2718                                                   skip + INTVAL (args_so_far)));
2719           else
2720             temp = memory_address (BLKmode,
2721                                    plus_constant (gen_rtx_PLUS (Pmode,
2722                                                                 args_addr,
2723                                                                 args_so_far),
2724                                                   skip));
2725           if (flag_check_memory_usage && ! in_check_memory_usage)
2726             {
2727               rtx target;
2728               
2729               in_check_memory_usage = 1;
2730               target = copy_to_reg (temp);
2731               if (GET_CODE (x) == MEM && type && AGGREGATE_TYPE_P (type))
2732                 emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
2733                                    target, ptr_mode,
2734                                    XEXP (xinner, 0), ptr_mode,
2735                                    size, TYPE_MODE (sizetype));
2736               else
2737                 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
2738                                    target, ptr_mode,
2739                                    size, TYPE_MODE (sizetype),
2740                                    GEN_INT (MEMORY_USE_RW),
2741                                    TYPE_MODE (integer_type_node));
2742               in_check_memory_usage = 0;
2743             }
2744
2745           /* TEMP is the address of the block.  Copy the data there.  */
2746           if (GET_CODE (size) == CONST_INT
2747               && (move_by_pieces_ninsns ((unsigned) INTVAL (size), align)
2748                   < MOVE_RATIO))
2749             {
2750               move_by_pieces (gen_rtx_MEM (BLKmode, temp), xinner,
2751                               INTVAL (size), align);
2752               goto ret;
2753             }
2754           else
2755             {
2756               rtx opalign = GEN_INT (align);
2757               enum machine_mode mode;
2758               rtx target = gen_rtx_MEM (BLKmode, temp);
2759
2760               for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2761                    mode != VOIDmode;
2762                    mode = GET_MODE_WIDER_MODE (mode))
2763                 {
2764                   enum insn_code code = movstr_optab[(int) mode];
2765
2766                   if (code != CODE_FOR_nothing
2767                       && ((GET_CODE (size) == CONST_INT
2768                            && ((unsigned HOST_WIDE_INT) INTVAL (size)
2769                                <= (GET_MODE_MASK (mode) >> 1)))
2770                           || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2771                       && (insn_operand_predicate[(int) code][0] == 0
2772                           || ((*insn_operand_predicate[(int) code][0])
2773                               (target, BLKmode)))
2774                       && (insn_operand_predicate[(int) code][1] == 0
2775                           || ((*insn_operand_predicate[(int) code][1])
2776                               (xinner, BLKmode)))
2777                       && (insn_operand_predicate[(int) code][3] == 0
2778                           || ((*insn_operand_predicate[(int) code][3])
2779                               (opalign, VOIDmode))))
2780                     {
2781                       rtx op2 = convert_to_mode (mode, size, 1);
2782                       rtx last = get_last_insn ();
2783                       rtx pat;
2784
2785                       if (insn_operand_predicate[(int) code][2] != 0
2786                           && ! ((*insn_operand_predicate[(int) code][2])
2787                                 (op2, mode)))
2788                         op2 = copy_to_mode_reg (mode, op2);
2789
2790                       pat = GEN_FCN ((int) code) (target, xinner,
2791                                                   op2, opalign);
2792                       if (pat)
2793                         {
2794                           emit_insn (pat);
2795                           goto ret;
2796                         }
2797                       else
2798                         delete_insns_since (last);
2799                     }
2800                 }
2801             }
2802
2803 #ifndef ACCUMULATE_OUTGOING_ARGS
2804           /* If the source is referenced relative to the stack pointer,
2805              copy it to another register to stabilize it.  We do not need
2806              to do this if we know that we won't be changing sp.  */
2807
2808           if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
2809               || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
2810             temp = copy_to_reg (temp);
2811 #endif
2812
2813           /* Make inhibit_defer_pop nonzero around the library call
2814              to force it to pop the bcopy-arguments right away.  */
2815           NO_DEFER_POP;
2816 #ifdef TARGET_MEM_FUNCTIONS
2817           emit_library_call (memcpy_libfunc, 0,
2818                              VOIDmode, 3, temp, Pmode, XEXP (xinner, 0), Pmode,
2819                              convert_to_mode (TYPE_MODE (sizetype),
2820                                               size, TREE_UNSIGNED (sizetype)),
2821                              TYPE_MODE (sizetype));
2822 #else
2823           emit_library_call (bcopy_libfunc, 0,
2824                              VOIDmode, 3, XEXP (xinner, 0), Pmode, temp, Pmode,
2825                              convert_to_mode (TYPE_MODE (integer_type_node),
2826                                               size,
2827                                               TREE_UNSIGNED (integer_type_node)),
2828                              TYPE_MODE (integer_type_node));
2829 #endif
2830           OK_DEFER_POP;
2831         }
2832     }
2833   else if (partial > 0)
2834     {
2835       /* Scalar partly in registers.  */
2836
2837       int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
2838       int i;
2839       int not_stack;
2840       /* # words of start of argument
2841          that we must make space for but need not store.  */
2842       int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
2843       int args_offset = INTVAL (args_so_far);
2844       int skip;
2845
2846       /* Push padding now if padding above and stack grows down,
2847          or if padding below and stack grows up.
2848          But if space already allocated, this has already been done.  */
2849       if (extra && args_addr == 0
2850           && where_pad != none && where_pad != stack_direction)
2851         anti_adjust_stack (GEN_INT (extra));
2852
2853       /* If we make space by pushing it, we might as well push
2854          the real data.  Otherwise, we can leave OFFSET nonzero
2855          and leave the space uninitialized.  */
2856       if (args_addr == 0)
2857         offset = 0;
2858
2859       /* Now NOT_STACK gets the number of words that we don't need to
2860          allocate on the stack.  */
2861       not_stack = partial - offset;
2862
2863       /* If the partial register-part of the arg counts in its stack size,
2864          skip the part of stack space corresponding to the registers.
2865          Otherwise, start copying to the beginning of the stack space,
2866          by setting SKIP to 0.  */
2867       skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
2868
2869       if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
2870         x = validize_mem (force_const_mem (mode, x));
2871
2872       /* If X is a hard register in a non-integer mode, copy it into a pseudo;
2873          SUBREGs of such registers are not allowed.  */
2874       if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER
2875            && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
2876         x = copy_to_reg (x);
2877
2878       /* Loop over all the words allocated on the stack for this arg.  */
2879       /* We can do it by words, because any scalar bigger than a word
2880          has a size a multiple of a word.  */
2881 #ifndef PUSH_ARGS_REVERSED
2882       for (i = not_stack; i < size; i++)
2883 #else
2884       for (i = size - 1; i >= not_stack; i--)
2885 #endif
2886         if (i >= not_stack + offset)
2887           emit_push_insn (operand_subword_force (x, i, mode),
2888                           word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
2889                           0, args_addr,
2890                           GEN_INT (args_offset + ((i - not_stack + skip)
2891                                                   * UNITS_PER_WORD)),
2892                           reg_parm_stack_space);
2893     }
2894   else
2895     {
2896       rtx addr;
2897       rtx target = NULL_RTX;
2898
2899       /* Push padding now if padding above and stack grows down,
2900          or if padding below and stack grows up.
2901          But if space already allocated, this has already been done.  */
2902       if (extra && args_addr == 0
2903           && where_pad != none && where_pad != stack_direction)
2904         anti_adjust_stack (GEN_INT (extra));
2905
2906 #ifdef PUSH_ROUNDING
2907       if (args_addr == 0)
2908         addr = gen_push_operand ();
2909       else
2910 #endif
2911         {
2912           if (GET_CODE (args_so_far) == CONST_INT)
2913             addr
2914               = memory_address (mode,
2915                                 plus_constant (args_addr, 
2916                                                INTVAL (args_so_far)));
2917           else
2918             addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
2919                                                        args_so_far));
2920           target = addr;
2921         }
2922
2923       emit_move_insn (gen_rtx_MEM (mode, addr), x);
2924
2925       if (flag_check_memory_usage && ! in_check_memory_usage)
2926         {
2927           in_check_memory_usage = 1;
2928           if (target == 0)
2929             target = get_push_address (GET_MODE_SIZE (mode));
2930
2931           if (GET_CODE (x) == MEM && type && AGGREGATE_TYPE_P (type))
2932             emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
2933                                target, ptr_mode,
2934                                XEXP (x, 0), ptr_mode,
2935                                GEN_INT (GET_MODE_SIZE (mode)),
2936                                TYPE_MODE (sizetype));
2937           else
2938             emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
2939                                target, ptr_mode,
2940                                GEN_INT (GET_MODE_SIZE (mode)),
2941                                TYPE_MODE (sizetype),
2942                                GEN_INT (MEMORY_USE_RW),
2943                                TYPE_MODE (integer_type_node));
2944           in_check_memory_usage = 0;
2945         }
2946     }
2947
2948  ret:
2949   /* If part should go in registers, copy that part
2950      into the appropriate registers.  Do this now, at the end,
2951      since mem-to-mem copies above may do function calls.  */
2952   if (partial > 0 && reg != 0)
2953     {
2954       /* Handle calls that pass values in multiple non-contiguous locations.
2955          The Irix 6 ABI has examples of this.  */
2956       if (GET_CODE (reg) == PARALLEL)
2957         emit_group_load (reg, x, -1, align);  /* ??? size? */
2958       else
2959         move_block_to_reg (REGNO (reg), x, partial, mode);
2960     }
2961
2962   if (extra && args_addr == 0 && where_pad == stack_direction)
2963     anti_adjust_stack (GEN_INT (extra));
2964 }
2965 \f
2966 /* Expand an assignment that stores the value of FROM into TO.
2967    If WANT_VALUE is nonzero, return an rtx for the value of TO.
2968    (This may contain a QUEUED rtx;
2969    if the value is constant, this rtx is a constant.)
2970    Otherwise, the returned value is NULL_RTX.
2971
2972    SUGGEST_REG is no longer actually used.
2973    It used to mean, copy the value through a register
2974    and return that register, if that is possible.
2975    We now use WANT_VALUE to decide whether to do this.  */
2976
2977 rtx
2978 expand_assignment (to, from, want_value, suggest_reg)
2979      tree to, from;
2980      int want_value;
2981      int suggest_reg;
2982 {
2983   register rtx to_rtx = 0;
2984   rtx result;
2985
2986   /* Don't crash if the lhs of the assignment was erroneous.  */
2987
2988   if (TREE_CODE (to) == ERROR_MARK)
2989     {
2990       result = expand_expr (from, NULL_RTX, VOIDmode, 0);
2991       return want_value ? result : NULL_RTX;
2992     }
2993
2994   /* Assignment of a structure component needs special treatment
2995      if the structure component's rtx is not simply a MEM.
2996      Assignment of an array element at a constant index, and assignment of
2997      an array element in an unaligned packed structure field, has the same
2998      problem.  */
2999
3000   if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
3001       || TREE_CODE (to) == ARRAY_REF)
3002     {
3003       enum machine_mode mode1;
3004       int bitsize;
3005       int bitpos;
3006       tree offset;
3007       int unsignedp;
3008       int volatilep = 0;
3009       tree tem;
3010       int alignment;
3011
3012       push_temp_slots ();
3013       tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
3014                                  &unsignedp, &volatilep, &alignment);
3015
3016       /* If we are going to use store_bit_field and extract_bit_field,
3017          make sure to_rtx will be safe for multiple use.  */
3018
3019       if (mode1 == VOIDmode && want_value)
3020         tem = stabilize_reference (tem);
3021
3022       to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_DONT);
3023       if (offset != 0)
3024         {
3025           rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
3026
3027           if (GET_CODE (to_rtx) != MEM)
3028             abort ();
3029
3030           if (GET_MODE (offset_rtx) != ptr_mode)
3031             {
3032 #ifdef POINTERS_EXTEND_UNSIGNED
3033               offset_rtx = convert_memory_address (ptr_mode, offset_rtx);
3034 #else
3035               offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
3036 #endif
3037             }
3038
3039           if (GET_CODE (to_rtx) == MEM
3040               && GET_MODE (to_rtx) == BLKmode
3041               && bitsize
3042               && (bitpos % bitsize) == 0 
3043               && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
3044               && (alignment * BITS_PER_UNIT) == GET_MODE_ALIGNMENT (mode1))
3045             {
3046               rtx temp = change_address (to_rtx, mode1,
3047                                          plus_constant (XEXP (to_rtx, 0),
3048                                                         (bitpos /
3049                                                          BITS_PER_UNIT)));
3050               if (GET_CODE (XEXP (temp, 0)) == REG)
3051                 to_rtx = temp;
3052               else
3053                 to_rtx = change_address (to_rtx, mode1,
3054                                          force_reg (GET_MODE (XEXP (temp, 0)),
3055                                                     XEXP (temp, 0)));
3056               bitpos = 0;
3057             }
3058
3059           to_rtx = change_address (to_rtx, VOIDmode,
3060                                    gen_rtx_PLUS (ptr_mode, XEXP (to_rtx, 0),
3061                                                  force_reg (ptr_mode, offset_rtx)));
3062         }
3063       if (volatilep)
3064         {
3065           if (GET_CODE (to_rtx) == MEM)
3066             {
3067               /* When the offset is zero, to_rtx is the address of the
3068                  structure we are storing into, and hence may be shared.
3069                  We must make a new MEM before setting the volatile bit.  */
3070               if (offset == 0)
3071                 to_rtx = copy_rtx (to_rtx);
3072
3073               MEM_VOLATILE_P (to_rtx) = 1;
3074             }
3075 #if 0  /* This was turned off because, when a field is volatile
3076           in an object which is not volatile, the object may be in a register,
3077           and then we would abort over here.  */
3078           else
3079             abort ();
3080 #endif
3081         }
3082
3083       if (TREE_CODE (to) == COMPONENT_REF
3084           && TREE_READONLY (TREE_OPERAND (to, 1)))
3085         {
3086           if (offset == 0)
3087             to_rtx = copy_rtx (to_rtx);
3088
3089           RTX_UNCHANGING_P (to_rtx) = 1;
3090         }
3091
3092       /* Check the access.  */
3093       if (flag_check_memory_usage && GET_CODE (to_rtx) == MEM)
3094         {
3095           rtx to_addr;
3096           int size;
3097           int best_mode_size;
3098           enum machine_mode best_mode;
3099
3100           best_mode = get_best_mode (bitsize, bitpos,
3101                                      TYPE_ALIGN (TREE_TYPE (tem)),
3102                                      mode1, volatilep);
3103           if (best_mode == VOIDmode)
3104             best_mode = QImode;
3105
3106           best_mode_size = GET_MODE_BITSIZE (best_mode);
3107           to_addr = plus_constant (XEXP (to_rtx, 0), (bitpos / BITS_PER_UNIT));
3108           size = CEIL ((bitpos % best_mode_size) + bitsize, best_mode_size);
3109           size *= GET_MODE_SIZE (best_mode);
3110
3111           /* Check the access right of the pointer.  */
3112           if (size)
3113             emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
3114                                to_addr, ptr_mode,
3115                                GEN_INT (size), TYPE_MODE (sizetype),
3116                                GEN_INT (MEMORY_USE_WO),
3117                                TYPE_MODE (integer_type_node));
3118         }
3119
3120       result = store_field (to_rtx, bitsize, bitpos, mode1, from,
3121                             (want_value
3122                              /* Spurious cast makes HPUX compiler happy.  */
3123                              ? (enum machine_mode) TYPE_MODE (TREE_TYPE (to))
3124                              : VOIDmode),
3125                             unsignedp,
3126                             /* Required alignment of containing datum.  */
3127                             alignment,
3128                             int_size_in_bytes (TREE_TYPE (tem)));
3129       preserve_temp_slots (result);
3130       free_temp_slots ();
3131       pop_temp_slots ();
3132
3133       /* If the value is meaningful, convert RESULT to the proper mode.
3134          Otherwise, return nothing.  */
3135       return (want_value ? convert_modes (TYPE_MODE (TREE_TYPE (to)),
3136                                           TYPE_MODE (TREE_TYPE (from)),
3137                                           result,
3138                                           TREE_UNSIGNED (TREE_TYPE (to)))
3139               : NULL_RTX);
3140     }
3141
3142   /* If the rhs is a function call and its value is not an aggregate,
3143      call the function before we start to compute the lhs.
3144      This is needed for correct code for cases such as
3145      val = setjmp (buf) on machines where reference to val
3146      requires loading up part of an address in a separate insn.
3147
3148      Don't do this if TO is a VAR_DECL whose DECL_RTL is REG since it might be
3149      a promoted variable where the zero- or sign- extension needs to be done.
3150      Handling this in the normal way is safe because no computation is done
3151      before the call.  */
3152   if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from)
3153       && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
3154       && ! (TREE_CODE (to) == VAR_DECL && GET_CODE (DECL_RTL (to)) == REG))
3155     {
3156       rtx value;
3157
3158       push_temp_slots ();
3159       value = expand_expr (from, NULL_RTX, VOIDmode, 0);
3160       if (to_rtx == 0)
3161         to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_WO);
3162
3163       /* Handle calls that return values in multiple non-contiguous locations.
3164          The Irix 6 ABI has examples of this.  */
3165       if (GET_CODE (to_rtx) == PARALLEL)
3166         emit_group_load (to_rtx, value, int_size_in_bytes (TREE_TYPE (from)),
3167                          TYPE_ALIGN (TREE_TYPE (from)) / BITS_PER_UNIT);
3168       else if (GET_MODE (to_rtx) == BLKmode)
3169         emit_block_move (to_rtx, value, expr_size (from),
3170                          TYPE_ALIGN (TREE_TYPE (from)) / BITS_PER_UNIT);
3171       else
3172         emit_move_insn (to_rtx, value);
3173       preserve_temp_slots (to_rtx);
3174       free_temp_slots ();
3175       pop_temp_slots ();
3176       return want_value ? to_rtx : NULL_RTX;
3177     }
3178
3179   /* Ordinary treatment.  Expand TO to get a REG or MEM rtx.
3180      Don't re-expand if it was expanded already (in COMPONENT_REF case).  */
3181
3182   if (to_rtx == 0)
3183     {
3184       to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_WO);
3185       if (GET_CODE (to_rtx) == MEM)
3186         MEM_ALIAS_SET (to_rtx) = get_alias_set (to);
3187     }
3188
3189   /* Don't move directly into a return register.  */
3190   if (TREE_CODE (to) == RESULT_DECL && GET_CODE (to_rtx) == REG)
3191     {
3192       rtx temp;
3193
3194       push_temp_slots ();
3195       temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
3196       emit_move_insn (to_rtx, temp);
3197       preserve_temp_slots (to_rtx);
3198       free_temp_slots ();
3199       pop_temp_slots ();
3200       return want_value ? to_rtx : NULL_RTX;
3201     }
3202
3203   /* In case we are returning the contents of an object which overlaps
3204      the place the value is being stored, use a safe function when copying
3205      a value through a pointer into a structure value return block.  */
3206   if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
3207       && current_function_returns_struct
3208       && !current_function_returns_pcc_struct)
3209     {
3210       rtx from_rtx, size;
3211
3212       push_temp_slots ();
3213       size = expr_size (from);
3214       from_rtx = expand_expr (from, NULL_RTX, VOIDmode,
3215                               EXPAND_MEMORY_USE_DONT);
3216
3217       /* Copy the rights of the bitmap.  */
3218       if (flag_check_memory_usage)
3219         emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
3220                            XEXP (to_rtx, 0), ptr_mode,
3221                            XEXP (from_rtx, 0), ptr_mode,
3222                            convert_to_mode (TYPE_MODE (sizetype),
3223                                             size, TREE_UNSIGNED (sizetype)),
3224                            TYPE_MODE (sizetype));
3225
3226 #ifdef TARGET_MEM_FUNCTIONS
3227       emit_library_call (memcpy_libfunc, 0,
3228                          VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
3229                          XEXP (from_rtx, 0), Pmode,
3230                          convert_to_mode (TYPE_MODE (sizetype),
3231                                           size, TREE_UNSIGNED (sizetype)),
3232                          TYPE_MODE (sizetype));
3233 #else
3234       emit_library_call (bcopy_libfunc, 0,
3235                          VOIDmode, 3, XEXP (from_rtx, 0), Pmode,
3236                          XEXP (to_rtx, 0), Pmode,
3237                          convert_to_mode (TYPE_MODE (integer_type_node),
3238                                           size, TREE_UNSIGNED (integer_type_node)),
3239                          TYPE_MODE (integer_type_node));
3240 #endif
3241
3242       preserve_temp_slots (to_rtx);
3243       free_temp_slots ();
3244       pop_temp_slots ();
3245       return want_value ? to_rtx : NULL_RTX;
3246     }
3247
3248   /* Compute FROM and store the value in the rtx we got.  */
3249
3250   push_temp_slots ();
3251   result = store_expr (from, to_rtx, want_value);
3252   preserve_temp_slots (result);
3253   free_temp_slots ();
3254   pop_temp_slots ();
3255   return want_value ? result : NULL_RTX;
3256 }
3257
3258 /* Generate code for computing expression EXP,
3259    and storing the value into TARGET.
3260    TARGET may contain a QUEUED rtx.
3261
3262    If WANT_VALUE is nonzero, return a copy of the value
3263    not in TARGET, so that we can be sure to use the proper
3264    value in a containing expression even if TARGET has something
3265    else stored in it.  If possible, we copy the value through a pseudo
3266    and return that pseudo.  Or, if the value is constant, we try to
3267    return the constant.  In some cases, we return a pseudo
3268    copied *from* TARGET.
3269
3270    If the mode is BLKmode then we may return TARGET itself.
3271    It turns out that in BLKmode it doesn't cause a problem.
3272    because C has no operators that could combine two different
3273    assignments into the same BLKmode object with different values
3274    with no sequence point.  Will other languages need this to
3275    be more thorough?
3276
3277    If WANT_VALUE is 0, we return NULL, to make sure
3278    to catch quickly any cases where the caller uses the value
3279    and fails to set WANT_VALUE.  */
3280
3281 rtx
3282 store_expr (exp, target, want_value)
3283      register tree exp;
3284      register rtx target;
3285      int want_value;
3286 {
3287   register rtx temp;
3288   int dont_return_target = 0;
3289
3290   if (TREE_CODE (exp) == COMPOUND_EXPR)
3291     {
3292       /* Perform first part of compound expression, then assign from second
3293          part.  */
3294       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
3295       emit_queue ();
3296       return store_expr (TREE_OPERAND (exp, 1), target, want_value);
3297     }
3298   else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
3299     {
3300       /* For conditional expression, get safe form of the target.  Then
3301          test the condition, doing the appropriate assignment on either
3302          side.  This avoids the creation of unnecessary temporaries.
3303          For non-BLKmode, it is more efficient not to do this.  */
3304
3305       rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
3306
3307       emit_queue ();
3308       target = protect_from_queue (target, 1);
3309
3310       do_pending_stack_adjust ();
3311       NO_DEFER_POP;
3312       jumpifnot (TREE_OPERAND (exp, 0), lab1);
3313       start_cleanup_deferral ();
3314       store_expr (TREE_OPERAND (exp, 1), target, 0);
3315       end_cleanup_deferral ();
3316       emit_queue ();
3317       emit_jump_insn (gen_jump (lab2));
3318       emit_barrier ();
3319       emit_label (lab1);
3320       start_cleanup_deferral ();
3321       store_expr (TREE_OPERAND (exp, 2), target, 0);
3322       end_cleanup_deferral ();
3323       emit_queue ();
3324       emit_label (lab2);
3325       OK_DEFER_POP;
3326
3327       return want_value ? target : NULL_RTX;
3328     }
3329   else if (want_value && GET_CODE (target) == MEM && ! MEM_VOLATILE_P (target)
3330            && GET_MODE (target) != BLKmode)
3331     /* If target is in memory and caller wants value in a register instead,
3332        arrange that.  Pass TARGET as target for expand_expr so that,
3333        if EXP is another assignment, WANT_VALUE will be nonzero for it.
3334        We know expand_expr will not use the target in that case.
3335        Don't do this if TARGET is volatile because we are supposed
3336        to write it and then read it.  */
3337     {
3338       temp = expand_expr (exp, cse_not_expected ? NULL_RTX : target,
3339                           GET_MODE (target), 0);
3340       if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
3341         temp = copy_to_reg (temp);
3342       dont_return_target = 1;
3343     }
3344   else if (queued_subexp_p (target))
3345     /* If target contains a postincrement, let's not risk
3346        using it as the place to generate the rhs.  */
3347     {
3348       if (GET_MODE (target) != BLKmode && GET_MODE (target) != VOIDmode)
3349         {
3350           /* Expand EXP into a new pseudo.  */
3351           temp = gen_reg_rtx (GET_MODE (target));
3352           temp = expand_expr (exp, temp, GET_MODE (target), 0);
3353         }
3354       else
3355         temp = expand_expr (exp, NULL_RTX, GET_MODE (target), 0);
3356
3357       /* If target is volatile, ANSI requires accessing the value
3358          *from* the target, if it is accessed.  So make that happen.
3359          In no case return the target itself.  */
3360       if (! MEM_VOLATILE_P (target) && want_value)
3361         dont_return_target = 1;
3362     }
3363   else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
3364     /* If this is an scalar in a register that is stored in a wider mode
3365        than the declared mode, compute the result into its declared mode
3366        and then convert to the wider mode.  Our value is the computed
3367        expression.  */
3368     {
3369       /* If we don't want a value, we can do the conversion inside EXP,
3370          which will often result in some optimizations.  Do the conversion
3371          in two steps: first change the signedness, if needed, then
3372          the extend.  But don't do this if the type of EXP is a subtype
3373          of something else since then the conversion might involve
3374          more than just converting modes.  */
3375       if (! want_value && INTEGRAL_TYPE_P (TREE_TYPE (exp))
3376           && TREE_TYPE (TREE_TYPE (exp)) == 0)
3377         {
3378           if (TREE_UNSIGNED (TREE_TYPE (exp))
3379               != SUBREG_PROMOTED_UNSIGNED_P (target))
3380             exp
3381               = convert
3382                 (signed_or_unsigned_type (SUBREG_PROMOTED_UNSIGNED_P (target),
3383                                           TREE_TYPE (exp)),
3384                  exp);
3385
3386           exp = convert (type_for_mode (GET_MODE (SUBREG_REG (target)),
3387                                         SUBREG_PROMOTED_UNSIGNED_P (target)),
3388                          exp);
3389         }
3390          
3391       temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
3392
3393       /* If TEMP is a volatile MEM and we want a result value, make
3394          the access now so it gets done only once.  Likewise if
3395          it contains TARGET.  */
3396       if (GET_CODE (temp) == MEM && want_value
3397           && (MEM_VOLATILE_P (temp)
3398               || reg_mentioned_p (SUBREG_REG (target), XEXP (temp, 0))))
3399         temp = copy_to_reg (temp);
3400
3401       /* If TEMP is a VOIDmode constant, use convert_modes to make
3402          sure that we properly convert it.  */
3403       if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
3404         temp = convert_modes (GET_MODE (SUBREG_REG (target)),
3405                               TYPE_MODE (TREE_TYPE (exp)), temp,
3406                               SUBREG_PROMOTED_UNSIGNED_P (target));
3407
3408       convert_move (SUBREG_REG (target), temp,
3409                     SUBREG_PROMOTED_UNSIGNED_P (target));
3410       return want_value ? temp : NULL_RTX;
3411     }
3412   else
3413     {
3414       temp = expand_expr (exp, target, GET_MODE (target), 0);
3415       /* Return TARGET if it's a specified hardware register.
3416          If TARGET is a volatile mem ref, either return TARGET
3417          or return a reg copied *from* TARGET; ANSI requires this.
3418
3419          Otherwise, if TEMP is not TARGET, return TEMP
3420          if it is constant (for efficiency),
3421          or if we really want the correct value.  */
3422       if (!(target && GET_CODE (target) == REG
3423             && REGNO (target) < FIRST_PSEUDO_REGISTER)
3424           && !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
3425           && ! rtx_equal_p (temp, target)
3426           && (CONSTANT_P (temp) || want_value))
3427         dont_return_target = 1;
3428     }
3429
3430   /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
3431      the same as that of TARGET, adjust the constant.  This is needed, for
3432      example, in case it is a CONST_DOUBLE and we want only a word-sized
3433      value.  */
3434   if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
3435       && TREE_CODE (exp) != ERROR_MARK
3436       && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
3437     temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
3438                           temp, TREE_UNSIGNED (TREE_TYPE (exp)));
3439
3440   if (flag_check_memory_usage
3441       && GET_CODE (target) == MEM
3442       && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3443     {
3444       if (GET_CODE (temp) == MEM)
3445         emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
3446                            XEXP (target, 0), ptr_mode,
3447                            XEXP (temp, 0), ptr_mode,
3448                            expr_size (exp), TYPE_MODE (sizetype));
3449       else
3450         emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
3451                            XEXP (target, 0), ptr_mode, 
3452                            expr_size (exp), TYPE_MODE (sizetype),
3453                            GEN_INT (MEMORY_USE_WO), 
3454                            TYPE_MODE (integer_type_node));
3455     }
3456
3457   /* If value was not generated in the target, store it there.
3458      Convert the value to TARGET's type first if nec.  */
3459
3460   if ((! rtx_equal_p (temp, target)
3461        || side_effects_p (temp)
3462        || side_effects_p (target))
3463       && TREE_CODE (exp) != ERROR_MARK)
3464     {
3465       target = protect_from_queue (target, 1);
3466       if (GET_MODE (temp) != GET_MODE (target)
3467           && GET_MODE (temp) != VOIDmode)
3468         {
3469           int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
3470           if (dont_return_target)
3471             {
3472               /* In this case, we will return TEMP,
3473                  so make sure it has the proper mode.
3474                  But don't forget to store the value into TARGET.  */
3475               temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
3476               emit_move_insn (target, temp);
3477             }
3478           else
3479             convert_move (target, temp, unsignedp);
3480         }
3481
3482       else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
3483         {
3484           /* Handle copying a string constant into an array.
3485              The string constant may be shorter than the array.
3486              So copy just the string's actual length, and clear the rest.  */
3487           rtx size;
3488           rtx addr;
3489
3490           /* Get the size of the data type of the string,
3491              which is actually the size of the target.  */
3492           size = expr_size (exp);
3493           if (GET_CODE (size) == CONST_INT
3494               && INTVAL (size) < TREE_STRING_LENGTH (exp))
3495             emit_block_move (target, temp, size,
3496                              TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3497           else
3498             {
3499               /* Compute the size of the data to copy from the string.  */
3500               tree copy_size
3501                 = size_binop (MIN_EXPR,
3502                               make_tree (sizetype, size),
3503                               convert (sizetype,
3504                                        build_int_2 (TREE_STRING_LENGTH (exp), 0)));
3505               rtx copy_size_rtx = expand_expr (copy_size, NULL_RTX,
3506                                                VOIDmode, 0);
3507               rtx label = 0;
3508
3509               /* Copy that much.  */
3510               emit_block_move (target, temp, copy_size_rtx,
3511                                TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3512
3513               /* Figure out how much is left in TARGET that we have to clear.
3514                  Do all calculations in ptr_mode.  */
3515
3516               addr = XEXP (target, 0);
3517               addr = convert_modes (ptr_mode, Pmode, addr, 1);
3518
3519               if (GET_CODE (copy_size_rtx) == CONST_INT)
3520                 {
3521                   addr = plus_constant (addr, TREE_STRING_LENGTH (exp));
3522                   size = plus_constant (size, - TREE_STRING_LENGTH (exp));
3523                 }
3524               else
3525                 {
3526                   addr = force_reg (ptr_mode, addr);
3527                   addr = expand_binop (ptr_mode, add_optab, addr,
3528                                        copy_size_rtx, NULL_RTX, 0,
3529                                        OPTAB_LIB_WIDEN);
3530
3531                   size = expand_binop (ptr_mode, sub_optab, size,
3532                                        copy_size_rtx, NULL_RTX, 0,
3533                                        OPTAB_LIB_WIDEN);
3534
3535                   emit_cmp_insn (size, const0_rtx, LT, NULL_RTX,
3536                                  GET_MODE (size), 0, 0);
3537                   label = gen_label_rtx ();
3538                   emit_jump_insn (gen_blt (label));
3539                 }
3540
3541               if (size != const0_rtx)
3542                 {
3543                   /* Be sure we can write on ADDR.  */
3544                   if (flag_check_memory_usage)
3545                     emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
3546                                        addr, ptr_mode,
3547                                        size, TYPE_MODE (sizetype),
3548                                        GEN_INT (MEMORY_USE_WO), 
3549                                        TYPE_MODE (integer_type_node));
3550 #ifdef TARGET_MEM_FUNCTIONS
3551                   emit_library_call (memset_libfunc, 0, VOIDmode, 3,
3552                                      addr, ptr_mode,
3553                                      const0_rtx, TYPE_MODE (integer_type_node),
3554                                      convert_to_mode (TYPE_MODE (sizetype),
3555                                                       size,
3556                                                       TREE_UNSIGNED (sizetype)),
3557                                      TYPE_MODE (sizetype));
3558 #else
3559                   emit_library_call (bzero_libfunc, 0, VOIDmode, 2,
3560                                      addr, ptr_mode,
3561                                      convert_to_mode (TYPE_MODE (integer_type_node),
3562                                                       size,
3563                                                       TREE_UNSIGNED (integer_type_node)),
3564                                      TYPE_MODE (integer_type_node));
3565 #endif
3566                 }
3567
3568               if (label)
3569                 emit_label (label);
3570             }
3571         }
3572       /* Handle calls that return values in multiple non-contiguous locations.
3573          The Irix 6 ABI has examples of this.  */
3574       else if (GET_CODE (target) == PARALLEL)
3575         emit_group_load (target, temp, int_size_in_bytes (TREE_TYPE (exp)),
3576                          TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3577       else if (GET_MODE (temp) == BLKmode)
3578         emit_block_move (target, temp, expr_size (exp),
3579                          TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
3580       else
3581         emit_move_insn (target, temp);
3582     }
3583
3584   /* If we don't want a value, return NULL_RTX.  */
3585   if (! want_value)
3586     return NULL_RTX;
3587
3588   /* If we are supposed to return TEMP, do so as long as it isn't a MEM.
3589      ??? The latter test doesn't seem to make sense.  */
3590   else if (dont_return_target && GET_CODE (temp) != MEM)
3591     return temp;
3592
3593   /* Return TARGET itself if it is a hard register.  */
3594   else if (want_value && GET_MODE (target) != BLKmode
3595            && ! (GET_CODE (target) == REG
3596                  && REGNO (target) < FIRST_PSEUDO_REGISTER))
3597     return copy_to_reg (target);
3598   
3599   else
3600     return target;
3601 }
3602 \f
3603 /* Return 1 if EXP just contains zeros.  */
3604
3605 static int
3606 is_zeros_p (exp)
3607      tree exp;
3608 {
3609   tree elt;
3610
3611   switch (TREE_CODE (exp))
3612     {
3613     case CONVERT_EXPR:
3614     case NOP_EXPR:
3615     case NON_LVALUE_EXPR:
3616       return is_zeros_p (TREE_OPERAND (exp, 0));
3617
3618     case INTEGER_CST:
3619       return TREE_INT_CST_LOW (exp) == 0 && TREE_INT_CST_HIGH (exp) == 0;
3620
3621     case COMPLEX_CST:
3622       return
3623         is_zeros_p (TREE_REALPART (exp)) && is_zeros_p (TREE_IMAGPART (exp));
3624
3625     case REAL_CST:
3626       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (exp), dconst0);
3627
3628     case CONSTRUCTOR:
3629       if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3630         return CONSTRUCTOR_ELTS (exp) == NULL_TREE;
3631       for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
3632         if (! is_zeros_p (TREE_VALUE (elt)))
3633           return 0;
3634
3635       return 1;
3636       
3637     default:
3638       return 0;
3639     }
3640 }
3641
3642 /* Return 1 if EXP contains mostly (3/4)  zeros.  */
3643
3644 static int
3645 mostly_zeros_p (exp)
3646      tree exp;
3647 {
3648   if (TREE_CODE (exp) == CONSTRUCTOR)
3649     {
3650       int elts = 0, zeros = 0;
3651       tree elt = CONSTRUCTOR_ELTS (exp);
3652       if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3653         {
3654           /* If there are no ranges of true bits, it is all zero.  */
3655           return elt == NULL_TREE;
3656         }
3657       for (; elt; elt = TREE_CHAIN (elt))
3658         {
3659           /* We do not handle the case where the index is a RANGE_EXPR,
3660              so the statistic will be somewhat inaccurate.
3661              We do make a more accurate count in store_constructor itself,
3662              so since this function is only used for nested array elements,
3663              this should be close enough.  */
3664           if (mostly_zeros_p (TREE_VALUE (elt)))
3665             zeros++;
3666           elts++;
3667         }
3668
3669       return 4 * zeros >= 3 * elts;
3670     }
3671
3672   return is_zeros_p (exp);
3673 }
3674 \f
3675 /* Helper function for store_constructor.
3676    TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
3677    TYPE is the type of the CONSTRUCTOR, not the element type.
3678    CLEARED is as for store_constructor.
3679
3680    This provides a recursive shortcut back to store_constructor when it isn't
3681    necessary to go through store_field.  This is so that we can pass through
3682    the cleared field to let store_constructor know that we may not have to
3683    clear a substructure if the outer structure has already been cleared.  */
3684
3685 static void
3686 store_constructor_field (target, bitsize, bitpos,
3687                          mode, exp, type, cleared)
3688      rtx target;
3689      int bitsize, bitpos;
3690      enum machine_mode mode;
3691      tree exp, type;
3692      int cleared;
3693 {
3694   if (TREE_CODE (exp) == CONSTRUCTOR
3695       && bitpos % BITS_PER_UNIT == 0
3696       /* If we have a non-zero bitpos for a register target, then we just
3697          let store_field do the bitfield handling.  This is unlikely to
3698          generate unnecessary clear instructions anyways.  */
3699       && (bitpos == 0 || GET_CODE (target) == MEM))
3700     {
3701       if (bitpos != 0)
3702         target = change_address (target, VOIDmode,
3703                                  plus_constant (XEXP (target, 0),
3704                                                 bitpos / BITS_PER_UNIT));
3705       store_constructor (exp, target, cleared);
3706     }
3707   else
3708     store_field (target, bitsize, bitpos, mode, exp,
3709                  VOIDmode, 0, TYPE_ALIGN (type) / BITS_PER_UNIT,
3710                  int_size_in_bytes (type));
3711 }
3712
3713 /* Store the value of constructor EXP into the rtx TARGET.
3714    TARGET is either a REG or a MEM.
3715    CLEARED is true if TARGET is known to have been zero'd.  */
3716
3717 static void
3718 store_constructor (exp, target, cleared)
3719      tree exp;
3720      rtx target;
3721      int cleared;
3722 {
3723   tree type = TREE_TYPE (exp);
3724
3725   /* We know our target cannot conflict, since safe_from_p has been called.  */
3726 #if 0
3727   /* Don't try copying piece by piece into a hard register
3728      since that is vulnerable to being clobbered by EXP.
3729      Instead, construct in a pseudo register and then copy it all.  */
3730   if (GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER)
3731     {
3732       rtx temp = gen_reg_rtx (GET_MODE (target));
3733       store_constructor (exp, temp, 0);
3734       emit_move_insn (target, temp);
3735       return;
3736     }
3737 #endif
3738
3739   if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3740       || TREE_CODE (type) == QUAL_UNION_TYPE)
3741     {
3742       register tree elt;
3743
3744       /* Inform later passes that the whole union value is dead.  */
3745       if (TREE_CODE (type) == UNION_TYPE
3746           || TREE_CODE (type) == QUAL_UNION_TYPE)
3747         emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3748
3749       /* If we are building a static constructor into a register,
3750          set the initial value as zero so we can fold the value into
3751          a constant.  But if more than one register is involved,
3752          this probably loses.  */
3753       else if (GET_CODE (target) == REG && TREE_STATIC (exp)
3754                && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
3755         {
3756           if (! cleared)
3757             emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
3758
3759           cleared = 1;
3760         }
3761
3762       /* If the constructor has fewer fields than the structure
3763          or if we are initializing the structure to mostly zeros,
3764          clear the whole structure first.  */
3765       else if ((list_length (CONSTRUCTOR_ELTS (exp))
3766                 != list_length (TYPE_FIELDS (type)))
3767                || mostly_zeros_p (exp))
3768         {
3769           if (! cleared)
3770             clear_storage (target, expr_size (exp),
3771                            TYPE_ALIGN (type) / BITS_PER_UNIT);
3772
3773           cleared = 1;
3774         }
3775       else
3776         /* Inform later passes that the old value is dead.  */
3777         emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3778
3779       /* Store each element of the constructor into
3780          the corresponding field of TARGET.  */
3781
3782       for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
3783         {
3784           register tree field = TREE_PURPOSE (elt);
3785           register enum machine_mode mode;
3786           int bitsize;
3787           int bitpos = 0;
3788           int unsignedp;
3789           tree pos, constant = 0, offset = 0;
3790           rtx to_rtx = target;
3791
3792           /* Just ignore missing fields.
3793              We cleared the whole structure, above,
3794              if any fields are missing.  */
3795           if (field == 0)
3796             continue;
3797
3798           if (cleared && is_zeros_p (TREE_VALUE (elt)))
3799             continue;
3800
3801           bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3802           unsignedp = TREE_UNSIGNED (field);
3803           mode = DECL_MODE (field);
3804           if (DECL_BIT_FIELD (field))
3805             mode = VOIDmode;
3806
3807           pos = DECL_FIELD_BITPOS (field);
3808           if (TREE_CODE (pos) == INTEGER_CST)
3809             constant = pos;
3810           else if (TREE_CODE (pos) == PLUS_EXPR
3811                    && TREE_CODE (TREE_OPERAND (pos, 1)) == INTEGER_CST)
3812             constant = TREE_OPERAND (pos, 1), offset = TREE_OPERAND (pos, 0);
3813           else
3814             offset = pos;
3815
3816           if (constant)
3817             bitpos = TREE_INT_CST_LOW (constant);
3818
3819           if (offset)
3820             {
3821               rtx offset_rtx;
3822
3823               if (contains_placeholder_p (offset))
3824                 offset = build (WITH_RECORD_EXPR, sizetype,
3825                                 offset, make_tree (TREE_TYPE (exp), target));
3826
3827               offset = size_binop (FLOOR_DIV_EXPR, offset,
3828                                    size_int (BITS_PER_UNIT));
3829
3830               offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
3831               if (GET_CODE (to_rtx) != MEM)
3832                 abort ();
3833
3834               if (GET_MODE (offset_rtx) != ptr_mode)
3835                 {
3836 #ifdef POINTERS_EXTEND_UNSIGNED
3837                   offset_rtx = convert_memory_address (ptr_mode, offset_rtx);
3838 #else
3839                   offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
3840 #endif
3841                 }
3842
3843               to_rtx
3844                 = change_address (to_rtx, VOIDmode,
3845                                   gen_rtx_PLUS (ptr_mode, XEXP (to_rtx, 0),
3846                                            force_reg (ptr_mode, offset_rtx)));
3847             }
3848           if (TREE_READONLY (field))
3849             {
3850               if (GET_CODE (to_rtx) == MEM)
3851                 to_rtx = copy_rtx (to_rtx);
3852
3853               RTX_UNCHANGING_P (to_rtx) = 1;
3854             }
3855
3856           store_constructor_field (to_rtx, bitsize, bitpos,
3857                                    mode, TREE_VALUE (elt), type, cleared);
3858         }
3859     }
3860   else if (TREE_CODE (type) == ARRAY_TYPE)
3861     {
3862       register tree elt;
3863       register int i;
3864       int need_to_clear;
3865       tree domain = TYPE_DOMAIN (type);
3866       HOST_WIDE_INT minelt = TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain));
3867       HOST_WIDE_INT maxelt = TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain));
3868       tree elttype = TREE_TYPE (type);
3869
3870       /* If the constructor has fewer elements than the array,
3871          clear the whole array first.  Similarly if this is
3872          static constructor of a non-BLKmode object.  */
3873       if (cleared || (GET_CODE (target) == REG && TREE_STATIC (exp)))
3874         need_to_clear = 1;
3875       else
3876         {
3877           HOST_WIDE_INT count = 0, zero_count = 0;
3878           need_to_clear = 0;
3879           /* This loop is a more accurate version of the loop in
3880              mostly_zeros_p (it handles RANGE_EXPR in an index).
3881              It is also needed to check for missing elements.  */
3882           for (elt = CONSTRUCTOR_ELTS (exp);
3883                elt != NULL_TREE;
3884                elt = TREE_CHAIN (elt))
3885             {
3886               tree index = TREE_PURPOSE (elt);
3887               HOST_WIDE_INT this_node_count;
3888               if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
3889                 {
3890                   tree lo_index = TREE_OPERAND (index, 0);
3891                   tree hi_index = TREE_OPERAND (index, 1);
3892                   if (TREE_CODE (lo_index) != INTEGER_CST
3893                       || TREE_CODE (hi_index) != INTEGER_CST)
3894                     {
3895                       need_to_clear = 1;
3896                       break;
3897                     }
3898                   this_node_count = TREE_INT_CST_LOW (hi_index)
3899                     - TREE_INT_CST_LOW (lo_index) + 1;
3900                 }
3901               else
3902                 this_node_count = 1;
3903               count += this_node_count;
3904               if (mostly_zeros_p (TREE_VALUE (elt)))
3905                 zero_count += this_node_count;
3906             }
3907           /* Clear the entire array first if there are any missing elements,
3908              or if the incidence of zero elements is >= 75%.  */
3909           if (count < maxelt - minelt + 1
3910               || 4 * zero_count >= 3 * count)
3911             need_to_clear = 1;
3912         }
3913       if (need_to_clear)
3914         {
3915           if (! cleared)
3916             clear_storage (target, expr_size (exp),
3917                            TYPE_ALIGN (type) / BITS_PER_UNIT);
3918           cleared = 1;
3919         }
3920       else
3921         /* Inform later passes that the old value is dead.  */
3922         emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
3923
3924       /* Store each element of the constructor into
3925          the corresponding element of TARGET, determined
3926          by counting the elements.  */
3927       for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
3928            elt;
3929            elt = TREE_CHAIN (elt), i++)
3930         {
3931           register enum machine_mode mode;
3932           int bitsize;
3933           int bitpos;
3934           int unsignedp;
3935           tree value = TREE_VALUE (elt);
3936           tree index = TREE_PURPOSE (elt);
3937           rtx xtarget = target;
3938
3939           if (cleared && is_zeros_p (value))
3940             continue;
3941
3942           mode = TYPE_MODE (elttype);
3943           bitsize = GET_MODE_BITSIZE (mode);
3944           unsignedp = TREE_UNSIGNED (elttype);
3945
3946           if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
3947             {
3948               tree lo_index = TREE_OPERAND (index, 0);
3949               tree hi_index = TREE_OPERAND (index, 1);
3950               rtx index_r, pos_rtx, addr, hi_r, loop_top, loop_end;
3951               struct nesting *loop;
3952               HOST_WIDE_INT lo, hi, count;
3953               tree position;
3954
3955               /* If the range is constant and "small", unroll the loop.  */
3956               if (TREE_CODE (lo_index) == INTEGER_CST
3957                   && TREE_CODE (hi_index) == INTEGER_CST
3958                   && (lo = TREE_INT_CST_LOW (lo_index),
3959                       hi = TREE_INT_CST_LOW (hi_index),
3960                       count = hi - lo + 1,
3961                       (GET_CODE (target) != MEM
3962                        || count <= 2
3963                        || (TREE_CODE (TYPE_SIZE (elttype)) == INTEGER_CST
3964                            && TREE_INT_CST_LOW (TYPE_SIZE (elttype)) * count
3965                            <= 40 * 8))))
3966                 {
3967                   lo -= minelt;  hi -= minelt;
3968                   for (; lo <= hi; lo++)
3969                     {
3970                       bitpos = lo * TREE_INT_CST_LOW (TYPE_SIZE (elttype));
3971                       store_constructor_field (target, bitsize, bitpos,
3972                                                mode, value, type, cleared);
3973                     }
3974                 }
3975               else
3976                 {
3977                   hi_r = expand_expr (hi_index, NULL_RTX, VOIDmode, 0);
3978                   loop_top = gen_label_rtx ();
3979                   loop_end = gen_label_rtx ();
3980
3981                   unsignedp = TREE_UNSIGNED (domain);
3982
3983                   index = build_decl (VAR_DECL, NULL_TREE, domain);
3984
3985                   DECL_RTL (index) = index_r
3986                     = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
3987                                                  &unsignedp, 0));
3988
3989                   if (TREE_CODE (value) == SAVE_EXPR
3990                       && SAVE_EXPR_RTL (value) == 0)
3991                     {
3992                       /* Make sure value gets expanded once before the
3993                          loop.  */
3994                       expand_expr (value, const0_rtx, VOIDmode, 0);
3995                       emit_queue ();
3996                     }
3997                   store_expr (lo_index, index_r, 0);
3998                   loop = expand_start_loop (0);
3999
4000                   /* Assign value to element index.  */
4001                   position = size_binop (EXACT_DIV_EXPR, TYPE_SIZE (elttype),
4002                                          size_int (BITS_PER_UNIT));
4003                   position = size_binop (MULT_EXPR,
4004                                          size_binop (MINUS_EXPR, index,
4005                                                      TYPE_MIN_VALUE (domain)),
4006                                          position);
4007                   pos_rtx = expand_expr (position, 0, VOIDmode, 0);
4008                   addr = gen_rtx_PLUS (Pmode, XEXP (target, 0), pos_rtx);
4009                   xtarget = change_address (target, mode, addr);
4010                   if (TREE_CODE (value) == CONSTRUCTOR)
4011                     store_constructor (value, xtarget, cleared);
4012                   else
4013                     store_expr (value, xtarget, 0);
4014
4015                   expand_exit_loop_if_false (loop,
4016                                              build (LT_EXPR, integer_type_node,
4017                                                     index, hi_index));
4018
4019                   expand_increment (build (PREINCREMENT_EXPR,
4020                                            TREE_TYPE (index),
4021                                            index, integer_one_node), 0, 0);
4022                   expand_end_loop ();
4023                   emit_label (loop_end);
4024
4025                   /* Needed by stupid register allocation. to extend the
4026                      lifetime of pseudo-regs used by target past the end
4027                      of the loop.  */
4028                   emit_insn (gen_rtx_USE (GET_MODE (target), target));
4029                 }
4030             }
4031           else if ((index != 0 && TREE_CODE (index) != INTEGER_CST)
4032               || TREE_CODE (TYPE_SIZE (elttype)) != INTEGER_CST)
4033             {
4034               rtx pos_rtx, addr;
4035               tree position;
4036
4037               if (index == 0)
4038                 index = size_int (i);
4039
4040               if (minelt)
4041                 index = size_binop (MINUS_EXPR, index,
4042                                     TYPE_MIN_VALUE (domain));
4043               position = size_binop (EXACT_DIV_EXPR, TYPE_SIZE (elttype),
4044                                      size_int (BITS_PER_UNIT));
4045               position = size_binop (MULT_EXPR, index, position);
4046               pos_rtx = expand_expr (position, 0, VOIDmode, 0);
4047               addr = gen_rtx_PLUS (Pmode, XEXP (target, 0), pos_rtx);
4048               xtarget = change_address (target, mode, addr);
4049               store_expr (value, xtarget, 0);
4050             }
4051           else
4052             {
4053               if (index != 0)
4054                 bitpos = ((TREE_INT_CST_LOW (index) - minelt)
4055                           * TREE_INT_CST_LOW (TYPE_SIZE (elttype)));
4056               else
4057                 bitpos = (i * TREE_INT_CST_LOW (TYPE_SIZE (elttype)));
4058               store_constructor_field (target, bitsize, bitpos,
4059                                        mode, value, type, cleared);
4060             }
4061         }
4062     }
4063   /* set constructor assignments */
4064   else if (TREE_CODE (type) == SET_TYPE)
4065     {
4066       tree elt = CONSTRUCTOR_ELTS (exp);
4067       int nbytes = int_size_in_bytes (type), nbits;
4068       tree domain = TYPE_DOMAIN (type);
4069       tree domain_min, domain_max, bitlength;
4070
4071       /* The default implementation strategy is to extract the constant
4072          parts of the constructor, use that to initialize the target,
4073          and then "or" in whatever non-constant ranges we need in addition.
4074
4075          If a large set is all zero or all ones, it is
4076          probably better to set it using memset (if available) or bzero.
4077          Also, if a large set has just a single range, it may also be
4078          better to first clear all the first clear the set (using
4079          bzero/memset), and set the bits we want.  */
4080        
4081       /* Check for all zeros.  */
4082       if (elt == NULL_TREE)
4083         {
4084           if (!cleared)
4085             clear_storage (target, expr_size (exp),
4086                            TYPE_ALIGN (type) / BITS_PER_UNIT);
4087           return;
4088         }
4089
4090       domain_min = convert (sizetype, TYPE_MIN_VALUE (domain));
4091       domain_max = convert (sizetype, TYPE_MAX_VALUE (domain));
4092       bitlength = size_binop (PLUS_EXPR,
4093                               size_binop (MINUS_EXPR, domain_max, domain_min),
4094                               size_one_node);
4095
4096       if (nbytes < 0 || TREE_CODE (bitlength) != INTEGER_CST)
4097         abort ();
4098       nbits = TREE_INT_CST_LOW (bitlength);
4099
4100       /* For "small" sets, or "medium-sized" (up to 32 bytes) sets that
4101          are "complicated" (more than one range), initialize (the
4102          constant parts) by copying from a constant.  */         
4103       if (GET_MODE (target) != BLKmode || nbits <= 2 * BITS_PER_WORD
4104           || (nbytes <= 32 && TREE_CHAIN (elt) != NULL_TREE))
4105         {
4106           int set_word_size = TYPE_ALIGN (TREE_TYPE (exp));
4107           enum machine_mode mode = mode_for_size (set_word_size, MODE_INT, 1);
4108           char *bit_buffer = (char *) alloca (nbits);
4109           HOST_WIDE_INT word = 0;
4110           int bit_pos = 0;
4111           int ibit = 0;
4112           int offset = 0;  /* In bytes from beginning of set.  */
4113           elt = get_set_constructor_bits (exp, bit_buffer, nbits);
4114           for (;;)
4115             {
4116               if (bit_buffer[ibit])
4117                 {
4118                   if (BYTES_BIG_ENDIAN)
4119                     word |= (1 << (set_word_size - 1 - bit_pos));
4120                   else
4121                     word |= 1 << bit_pos;
4122                 }
4123               bit_pos++;  ibit++;
4124               if (bit_pos >= set_word_size || ibit == nbits)
4125                 {
4126                   if (word != 0 || ! cleared)
4127                     {
4128                       rtx datum = GEN_INT (word);
4129                       rtx to_rtx;
4130                       /* The assumption here is that it is safe to use
4131                          XEXP if the set is multi-word, but not if
4132                          it's single-word.  */
4133                       if (GET_CODE (target) == MEM)
4134                         {
4135                           to_rtx = plus_constant (XEXP (target, 0), offset);
4136                           to_rtx = change_address (target, mode, to_rtx);
4137                         }
4138                       else if (offset == 0) 
4139                         to_rtx = target;
4140                       else
4141                         abort ();
4142                       emit_move_insn (to_rtx, datum);
4143                     }
4144                   if (ibit == nbits)
4145                     break;
4146                   word = 0;
4147                   bit_pos = 0;
4148                   offset += set_word_size / BITS_PER_UNIT;
4149                 }
4150             }
4151         }
4152       else if (!cleared)
4153         {
4154           /* Don't bother clearing storage if the set is all ones.  */
4155           if (TREE_CHAIN (elt) != NULL_TREE
4156               || (TREE_PURPOSE (elt) == NULL_TREE
4157                   ? nbits != 1
4158                   : (TREE_CODE (TREE_VALUE (elt)) != INTEGER_CST
4159                      || TREE_CODE (TREE_PURPOSE (elt)) != INTEGER_CST
4160                      || (TREE_INT_CST_LOW (TREE_VALUE (elt))
4161                          - TREE_INT_CST_LOW (TREE_PURPOSE (elt)) + 1
4162                          != nbits))))
4163             clear_storage (target, expr_size (exp),
4164                            TYPE_ALIGN (type) / BITS_PER_UNIT);
4165         }
4166           
4167       for (; elt != NULL_TREE; elt = TREE_CHAIN (elt))
4168         {
4169           /* start of range of element or NULL */
4170           tree startbit = TREE_PURPOSE (elt);
4171           /* end of range of element, or element value */
4172           tree endbit   = TREE_VALUE (elt);
4173 #ifdef TARGET_MEM_FUNCTIONS
4174           HOST_WIDE_INT startb, endb;
4175 #endif
4176           rtx  bitlength_rtx, startbit_rtx, endbit_rtx, targetx;
4177
4178           bitlength_rtx = expand_expr (bitlength,
4179                             NULL_RTX, MEM, EXPAND_CONST_ADDRESS);
4180
4181           /* handle non-range tuple element like [ expr ]  */
4182           if (startbit == NULL_TREE)
4183             {
4184               startbit = save_expr (endbit);
4185               endbit = startbit;
4186             }
4187           startbit = convert (sizetype, startbit);
4188           endbit = convert (sizetype, endbit);
4189           if (! integer_zerop (domain_min))
4190             {
4191               startbit = size_binop (MINUS_EXPR, startbit, domain_min);
4192               endbit = size_binop (MINUS_EXPR, endbit, domain_min);
4193             }
4194           startbit_rtx = expand_expr (startbit, NULL_RTX, MEM, 
4195                                       EXPAND_CONST_ADDRESS);
4196           endbit_rtx = expand_expr (endbit, NULL_RTX, MEM, 
4197                                     EXPAND_CONST_ADDRESS);
4198
4199           if (REG_P (target))
4200             {
4201               targetx = assign_stack_temp (GET_MODE (target),
4202                                            GET_MODE_SIZE (GET_MODE (target)),
4203                                            0);
4204               emit_move_insn (targetx, target);
4205             }
4206           else if (GET_CODE (target) == MEM)
4207             targetx = target;
4208           else
4209             abort ();
4210
4211 #ifdef TARGET_MEM_FUNCTIONS
4212           /* Optimization:  If startbit and endbit are
4213              constants divisible by BITS_PER_UNIT,
4214              call memset instead.  */
4215           if (TREE_CODE (startbit) == INTEGER_CST
4216               && TREE_CODE (endbit) == INTEGER_CST
4217               && (startb = TREE_INT_CST_LOW (startbit)) % BITS_PER_UNIT == 0
4218               && (endb = TREE_INT_CST_LOW (endbit) + 1) % BITS_PER_UNIT == 0)
4219             {
4220               emit_library_call (memset_libfunc, 0,
4221                                  VOIDmode, 3,
4222                                  plus_constant (XEXP (targetx, 0),
4223                                                 startb / BITS_PER_UNIT),
4224                                  Pmode,
4225                                  constm1_rtx, TYPE_MODE (integer_type_node),
4226                                  GEN_INT ((endb - startb) / BITS_PER_UNIT),
4227                                  TYPE_MODE (sizetype));
4228             }
4229           else
4230 #endif
4231             {
4232               emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__setbits"),
4233                                  0, VOIDmode, 4, XEXP (targetx, 0), Pmode,
4234                                  bitlength_rtx, TYPE_MODE (sizetype),
4235                                  startbit_rtx, TYPE_MODE (sizetype),
4236                                  endbit_rtx, TYPE_MODE (sizetype));
4237             }
4238           if (REG_P (target))
4239             emit_move_insn (target, targetx);
4240         }
4241     }
4242
4243   else
4244     abort ();
4245 }
4246
4247 /* Store the value of EXP (an expression tree)
4248    into a subfield of TARGET which has mode MODE and occupies
4249    BITSIZE bits, starting BITPOS bits from the start of TARGET.
4250    If MODE is VOIDmode, it means that we are storing into a bit-field.
4251
4252    If VALUE_MODE is VOIDmode, return nothing in particular.
4253    UNSIGNEDP is not used in this case.
4254
4255    Otherwise, return an rtx for the value stored.  This rtx
4256    has mode VALUE_MODE if that is convenient to do.
4257    In this case, UNSIGNEDP must be nonzero if the value is an unsigned type.
4258
4259    ALIGN is the alignment that TARGET is known to have, measured in bytes.
4260    TOTAL_SIZE is the size in bytes of the structure, or -1 if varying.  */
4261
4262 static rtx
4263 store_field (target, bitsize, bitpos, mode, exp, value_mode,
4264              unsignedp, align, total_size)
4265      rtx target;
4266      int bitsize, bitpos;
4267      enum machine_mode mode;
4268      tree exp;
4269      enum machine_mode value_mode;
4270      int unsignedp;
4271      int align;
4272      int total_size;
4273 {
4274   HOST_WIDE_INT width_mask = 0;
4275
4276   if (TREE_CODE (exp) == ERROR_MARK)
4277     return const0_rtx;
4278
4279   if (bitsize < HOST_BITS_PER_WIDE_INT)
4280     width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
4281
4282   /* If we are storing into an unaligned field of an aligned union that is
4283      in a register, we may have the mode of TARGET being an integer mode but
4284      MODE == BLKmode.  In that case, get an aligned object whose size and
4285      alignment are the same as TARGET and store TARGET into it (we can avoid
4286      the store if the field being stored is the entire width of TARGET).  Then
4287      call ourselves recursively to store the field into a BLKmode version of
4288      that object.  Finally, load from the object into TARGET.  This is not
4289      very efficient in general, but should only be slightly more expensive
4290      than the otherwise-required unaligned accesses.  Perhaps this can be
4291      cleaned up later.  */
4292
4293   if (mode == BLKmode
4294       && (GET_CODE (target) == REG || GET_CODE (target) == SUBREG))
4295     {
4296       rtx object = assign_stack_temp (GET_MODE (target),
4297                                       GET_MODE_SIZE (GET_MODE (target)), 0);
4298       rtx blk_object = copy_rtx (object);
4299
4300       MEM_IN_STRUCT_P (object) = 1;
4301       MEM_IN_STRUCT_P (blk_object) = 1;
4302       PUT_MODE (blk_object, BLKmode);
4303
4304       if (bitsize != GET_MODE_BITSIZE (GET_MODE (target)))
4305         emit_move_insn (object, target);
4306
4307       store_field (blk_object, bitsize, bitpos, mode, exp, VOIDmode, 0,
4308                    align, total_size);
4309
4310       /* Even though we aren't returning target, we need to
4311          give it the updated value.  */
4312       emit_move_insn (target, object);
4313
4314       return blk_object;
4315     }
4316
4317   /* If the structure is in a register or if the component
4318      is a bit field, we cannot use addressing to access it.
4319      Use bit-field techniques or SUBREG to store in it.  */
4320
4321   if (mode == VOIDmode
4322       || (mode != BLKmode && ! direct_store[(int) mode])
4323       || GET_CODE (target) == REG
4324       || GET_CODE (target) == SUBREG
4325       /* If the field isn't aligned enough to store as an ordinary memref,
4326          store it as a bit field.  */
4327       || (SLOW_UNALIGNED_ACCESS
4328           && align * BITS_PER_UNIT < GET_MODE_ALIGNMENT (mode))
4329       || (SLOW_UNALIGNED_ACCESS && bitpos % GET_MODE_ALIGNMENT (mode) != 0))
4330     {
4331       rtx temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
4332
4333       /* If BITSIZE is narrower than the size of the type of EXP
4334          we will be narrowing TEMP.  Normally, what's wanted are the
4335          low-order bits.  However, if EXP's type is a record and this is
4336          big-endian machine, we want the upper BITSIZE bits.  */
4337       if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
4338           && bitsize < GET_MODE_BITSIZE (GET_MODE (temp))
4339           && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4340         temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
4341                              size_int (GET_MODE_BITSIZE (GET_MODE (temp))
4342                                        - bitsize),
4343                              temp, 1);
4344
4345       /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
4346          MODE.  */
4347       if (mode != VOIDmode && mode != BLKmode
4348           && mode != TYPE_MODE (TREE_TYPE (exp)))
4349         temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
4350
4351       /* If the modes of TARGET and TEMP are both BLKmode, both
4352          must be in memory and BITPOS must be aligned on a byte
4353          boundary.  If so, we simply do a block copy.  */
4354       if (GET_MODE (target) == BLKmode && GET_MODE (temp) == BLKmode)
4355         {
4356           if (GET_CODE (target) != MEM || GET_CODE (temp) != MEM
4357               || bitpos % BITS_PER_UNIT != 0)
4358             abort ();
4359
4360           target = change_address (target, VOIDmode,
4361                                    plus_constant (XEXP (target, 0),
4362                                                 bitpos / BITS_PER_UNIT));
4363
4364           emit_block_move (target, temp,
4365                            GEN_INT ((bitsize + BITS_PER_UNIT - 1)
4366                                     / BITS_PER_UNIT),
4367                            1);
4368
4369           return value_mode == VOIDmode ? const0_rtx : target;
4370         }
4371
4372       /* Store the value in the bitfield.  */
4373       store_bit_field (target, bitsize, bitpos, mode, temp, align, total_size);
4374       if (value_mode != VOIDmode)
4375         {
4376           /* The caller wants an rtx for the value.  */
4377           /* If possible, avoid refetching from the bitfield itself.  */
4378           if (width_mask != 0
4379               && ! (GET_CODE (target) == MEM && MEM_VOLATILE_P (target)))
4380             {
4381               tree count;
4382               enum machine_mode tmode;
4383
4384               if (unsignedp)
4385                 return expand_and (temp, GEN_INT (width_mask), NULL_RTX);
4386               tmode = GET_MODE (temp);
4387               if (tmode == VOIDmode)
4388                 tmode = value_mode;
4389               count = build_int_2 (GET_MODE_BITSIZE (tmode) - bitsize, 0);
4390               temp = expand_shift (LSHIFT_EXPR, tmode, temp, count, 0, 0);
4391               return expand_shift (RSHIFT_EXPR, tmode, temp, count, 0, 0);
4392             }
4393           return extract_bit_field (target, bitsize, bitpos, unsignedp,
4394                                     NULL_RTX, value_mode, 0, align,
4395                                     total_size);
4396         }
4397       return const0_rtx;
4398     }
4399   else
4400     {
4401       rtx addr = XEXP (target, 0);
4402       rtx to_rtx;
4403
4404       /* If a value is wanted, it must be the lhs;
4405          so make the address stable for multiple use.  */
4406
4407       if (value_mode != VOIDmode && GET_CODE (addr) != REG
4408           && ! CONSTANT_ADDRESS_P (addr)
4409           /* A frame-pointer reference is already stable.  */
4410           && ! (GET_CODE (addr) == PLUS
4411                 && GET_CODE (XEXP (addr, 1)) == CONST_INT
4412                 && (XEXP (addr, 0) == virtual_incoming_args_rtx
4413                     || XEXP (addr, 0) == virtual_stack_vars_rtx)))
4414         addr = copy_to_reg (addr);
4415
4416       /* Now build a reference to just the desired component.  */
4417
4418       to_rtx = copy_rtx (change_address (target, mode,
4419                                          plus_constant (addr,
4420                                                         (bitpos
4421                                                          / BITS_PER_UNIT))));
4422       MEM_IN_STRUCT_P (to_rtx) = 1;
4423
4424       return store_expr (exp, to_rtx, value_mode != VOIDmode);
4425     }
4426 }
4427 \f
4428 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
4429    or an ARRAY_REF, look for nested COMPONENT_REFs, BIT_FIELD_REFs, or
4430    ARRAY_REFs and find the ultimate containing object, which we return.
4431
4432    We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
4433    bit position, and *PUNSIGNEDP to the signedness of the field.
4434    If the position of the field is variable, we store a tree
4435    giving the variable offset (in units) in *POFFSET.
4436    This offset is in addition to the bit position.
4437    If the position is not variable, we store 0 in *POFFSET.
4438    We set *PALIGNMENT to the alignment in bytes of the address that will be
4439    computed.  This is the alignment of the thing we return if *POFFSET
4440    is zero, but can be more less strictly aligned if *POFFSET is nonzero.
4441
4442    If any of the extraction expressions is volatile,
4443    we store 1 in *PVOLATILEP.  Otherwise we don't change that.
4444
4445    If the field is a bit-field, *PMODE is set to VOIDmode.  Otherwise, it
4446    is a mode that can be used to access the field.  In that case, *PBITSIZE
4447    is redundant.
4448
4449    If the field describes a variable-sized object, *PMODE is set to
4450    VOIDmode and *PBITSIZE is set to -1.  An access cannot be made in
4451    this case, but the address of the object can be found.   */
4452
4453 tree
4454 get_inner_reference (exp, pbitsize, pbitpos, poffset, pmode,
4455                      punsignedp, pvolatilep, palignment)
4456      tree exp;
4457      int *pbitsize;
4458      int *pbitpos;
4459      tree *poffset;
4460      enum machine_mode *pmode;
4461      int *punsignedp;
4462      int *pvolatilep;
4463      int *palignment;
4464 {
4465   tree orig_exp = exp;
4466   tree size_tree = 0;
4467   enum machine_mode mode = VOIDmode;
4468   tree offset = integer_zero_node;
4469   int alignment = BIGGEST_ALIGNMENT;
4470
4471   if (TREE_CODE (exp) == COMPONENT_REF)
4472     {
4473       size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
4474       if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
4475         mode = DECL_MODE (TREE_OPERAND (exp, 1));
4476       *punsignedp = TREE_UNSIGNED (TREE_OPERAND (exp, 1));
4477     }
4478   else if (TREE_CODE (exp) == BIT_FIELD_REF)
4479     {
4480       size_tree = TREE_OPERAND (exp, 1);
4481       *punsignedp = TREE_UNSIGNED (exp);
4482     }
4483   else
4484     {
4485       mode = TYPE_MODE (TREE_TYPE (exp));
4486       *pbitsize = GET_MODE_BITSIZE (mode);
4487       *punsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
4488     }
4489       
4490   if (size_tree)
4491     {
4492       if (TREE_CODE (size_tree) != INTEGER_CST)
4493         mode = BLKmode, *pbitsize = -1;
4494       else
4495         *pbitsize = TREE_INT_CST_LOW (size_tree);
4496     }
4497
4498   /* Compute cumulative bit-offset for nested component-refs and array-refs,
4499      and find the ultimate containing object.  */
4500
4501   *pbitpos = 0;
4502
4503   while (1)
4504     {
4505       if (TREE_CODE (exp) == COMPONENT_REF || TREE_CODE (exp) == BIT_FIELD_REF)
4506         {
4507           tree pos = (TREE_CODE (exp) == COMPONENT_REF
4508                       ? DECL_FIELD_BITPOS (TREE_OPERAND (exp, 1))
4509                       : TREE_OPERAND (exp, 2));
4510           tree constant = integer_zero_node, var = pos;
4511
4512           /* If this field hasn't been filled in yet, don't go
4513              past it.  This should only happen when folding expressions
4514              made during type construction.  */
4515           if (pos == 0)
4516             break;
4517
4518           /* Assume here that the offset is a multiple of a unit.
4519              If not, there should be an explicitly added constant.  */
4520           if (TREE_CODE (pos) == PLUS_EXPR
4521               && TREE_CODE (TREE_OPERAND (pos, 1)) == INTEGER_CST)
4522             constant = TREE_OPERAND (pos, 1), var = TREE_OPERAND (pos, 0);
4523           else if (TREE_CODE (pos) == INTEGER_CST)
4524             constant = pos, var = integer_zero_node;
4525
4526           *pbitpos += TREE_INT_CST_LOW (constant);
4527           offset = size_binop (PLUS_EXPR, offset,
4528                                size_binop (EXACT_DIV_EXPR, var,
4529                                            size_int (BITS_PER_UNIT)));
4530         }
4531
4532       else if (TREE_CODE (exp) == ARRAY_REF)
4533         {
4534           /* This code is based on the code in case ARRAY_REF in expand_expr
4535              below.  We assume here that the size of an array element is
4536              always an integral multiple of BITS_PER_UNIT.  */
4537
4538           tree index = TREE_OPERAND (exp, 1);
4539           tree domain = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
4540           tree low_bound
4541             = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
4542           tree index_type = TREE_TYPE (index);
4543           tree xindex;
4544
4545           if (TYPE_PRECISION (index_type) != TYPE_PRECISION (sizetype))
4546             {
4547               index = convert (type_for_size (TYPE_PRECISION (sizetype), 0),
4548                                index);
4549               index_type = TREE_TYPE (index);
4550             }
4551
4552           /* Optimize the special-case of a zero lower bound.
4553              
4554              We convert the low_bound to sizetype to avoid some problems
4555              with constant folding.  (E.g. suppose the lower bound is 1,
4556              and its mode is QI.  Without the conversion,  (ARRAY
4557              +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
4558              +INDEX), which becomes (ARRAY+255+INDEX).  Oops!)
4559              
4560              But sizetype isn't quite right either (especially if
4561              the lowbound is negative).  FIXME */
4562
4563           if (! integer_zerop (low_bound))
4564             index = fold (build (MINUS_EXPR, index_type, index,
4565                                  convert (sizetype, low_bound)));
4566
4567           if (TREE_CODE (index) == INTEGER_CST)
4568             {
4569               index = convert (sbitsizetype, index);
4570               index_type = TREE_TYPE (index);
4571             }
4572
4573           xindex = fold (build (MULT_EXPR, sbitsizetype, index,
4574                                 convert (sbitsizetype,
4575                                          TYPE_SIZE (TREE_TYPE (exp)))));
4576
4577           if (TREE_CODE (xindex) == INTEGER_CST
4578               && TREE_INT_CST_HIGH (xindex) == 0)
4579             *pbitpos += TREE_INT_CST_LOW (xindex);
4580           else
4581             {
4582               /* Either the bit offset calculated above is not constant, or
4583                  it overflowed.  In either case, redo the multiplication
4584                  against the size in units.  This is especially important
4585                  in the non-constant case to avoid a division at runtime.  */
4586               xindex = fold (build (MULT_EXPR, ssizetype, index,
4587                                     convert (ssizetype,
4588                                          TYPE_SIZE_UNIT (TREE_TYPE (exp)))));
4589
4590               if (contains_placeholder_p (xindex))
4591                 xindex = build (WITH_RECORD_EXPR, sizetype, xindex, exp);
4592
4593               offset = size_binop (PLUS_EXPR, offset, xindex);
4594             }
4595         }
4596       else if (TREE_CODE (exp) != NON_LVALUE_EXPR
4597                && ! ((TREE_CODE (exp) == NOP_EXPR
4598                       || TREE_CODE (exp) == CONVERT_EXPR)
4599                      && ! (TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
4600                            && (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0)))
4601                                != UNION_TYPE))
4602                      && (TYPE_MODE (TREE_TYPE (exp))
4603                          == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
4604         break;
4605
4606       /* If any reference in the chain is volatile, the effect is volatile.  */
4607       if (TREE_THIS_VOLATILE (exp))
4608         *pvolatilep = 1;
4609
4610       /* If the offset is non-constant already, then we can't assume any
4611          alignment more than the alignment here.  */
4612       if (! integer_zerop (offset))
4613         alignment = MIN (alignment, TYPE_ALIGN (TREE_TYPE (exp)));
4614
4615       exp = TREE_OPERAND (exp, 0);
4616     }
4617
4618   if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
4619     alignment = MIN (alignment, DECL_ALIGN (exp));
4620   else if (TREE_TYPE (exp) != 0)
4621     alignment = MIN (alignment, TYPE_ALIGN (TREE_TYPE (exp)));
4622
4623   if (integer_zerop (offset))
4624     offset = 0;
4625
4626   if (offset != 0 && contains_placeholder_p (offset))
4627     offset = build (WITH_RECORD_EXPR, sizetype, offset, orig_exp);
4628
4629   *pmode = mode;
4630   *poffset = offset;
4631   *palignment = alignment / BITS_PER_UNIT;
4632   return exp;
4633 }
4634
4635 /* Subroutine of expand_exp: compute memory_usage from modifier.  */
4636 static enum memory_use_mode
4637 get_memory_usage_from_modifier (modifier)
4638      enum expand_modifier modifier;
4639 {
4640   switch (modifier)
4641     {
4642     case EXPAND_NORMAL:
4643     case EXPAND_SUM:
4644       return MEMORY_USE_RO;
4645       break;
4646     case EXPAND_MEMORY_USE_WO:
4647       return MEMORY_USE_WO;
4648       break;
4649     case EXPAND_MEMORY_USE_RW:
4650       return MEMORY_USE_RW;
4651       break;
4652     case EXPAND_MEMORY_USE_DONT:
4653       /* EXPAND_CONST_ADDRESS and EXPAND_INITIALIZER are converted into
4654          MEMORY_USE_DONT, because they are modifiers to a call of
4655          expand_expr in the ADDR_EXPR case of expand_expr.  */
4656     case EXPAND_CONST_ADDRESS:
4657     case EXPAND_INITIALIZER:
4658       return MEMORY_USE_DONT;
4659     case EXPAND_MEMORY_USE_BAD:
4660     default:
4661       abort ();
4662     }
4663 }
4664 \f
4665 /* Given an rtx VALUE that may contain additions and multiplications,
4666    return an equivalent value that just refers to a register or memory.
4667    This is done by generating instructions to perform the arithmetic
4668    and returning a pseudo-register containing the value.
4669
4670    The returned value may be a REG, SUBREG, MEM or constant.  */
4671
4672 rtx
4673 force_operand (value, target)
4674      rtx value, target;
4675 {
4676   register optab binoptab = 0;
4677   /* Use a temporary to force order of execution of calls to
4678      `force_operand'.  */
4679   rtx tmp;
4680   register rtx op2;
4681   /* Use subtarget as the target for operand 0 of a binary operation.  */
4682   register rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
4683
4684   /* Check for a PIC address load.  */
4685   if (flag_pic
4686       && (GET_CODE (value) == PLUS || GET_CODE (value) == MINUS)
4687       && XEXP (value, 0) == pic_offset_table_rtx
4688       && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
4689           || GET_CODE (XEXP (value, 1)) == LABEL_REF
4690           || GET_CODE (XEXP (value, 1)) == CONST))
4691     {
4692       if (!subtarget)
4693         subtarget = gen_reg_rtx (GET_MODE (value));
4694       emit_move_insn (subtarget, value);
4695       return subtarget;
4696     }
4697
4698   if (GET_CODE (value) == PLUS)
4699     binoptab = add_optab;
4700   else if (GET_CODE (value) == MINUS)
4701     binoptab = sub_optab;
4702   else if (GET_CODE (value) == MULT)
4703     {
4704       op2 = XEXP (value, 1);
4705       if (!CONSTANT_P (op2)
4706           && !(GET_CODE (op2) == REG && op2 != subtarget))
4707         subtarget = 0;
4708       tmp = force_operand (XEXP (value, 0), subtarget);
4709       return expand_mult (GET_MODE (value), tmp,
4710                           force_operand (op2, NULL_RTX),
4711                           target, 0);
4712     }
4713
4714   if (binoptab)
4715     {
4716       op2 = XEXP (value, 1);
4717       if (!CONSTANT_P (op2)
4718           && !(GET_CODE (op2) == REG && op2 != subtarget))
4719         subtarget = 0;
4720       if (binoptab == sub_optab && GET_CODE (op2) == CONST_INT)
4721         {
4722           binoptab = add_optab;
4723           op2 = negate_rtx (GET_MODE (value), op2);
4724         }
4725
4726       /* Check for an addition with OP2 a constant integer and our first
4727          operand a PLUS of a virtual register and something else.  In that
4728          case, we want to emit the sum of the virtual register and the
4729          constant first and then add the other value.  This allows virtual
4730          register instantiation to simply modify the constant rather than
4731          creating another one around this addition.  */
4732       if (binoptab == add_optab && GET_CODE (op2) == CONST_INT
4733           && GET_CODE (XEXP (value, 0)) == PLUS
4734           && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
4735           && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
4736           && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
4737         {
4738           rtx temp = expand_binop (GET_MODE (value), binoptab,
4739                                    XEXP (XEXP (value, 0), 0), op2,
4740                                    subtarget, 0, OPTAB_LIB_WIDEN);
4741           return expand_binop (GET_MODE (value), binoptab, temp,
4742                                force_operand (XEXP (XEXP (value, 0), 1), 0),
4743                                target, 0, OPTAB_LIB_WIDEN);
4744         }
4745                                    
4746       tmp = force_operand (XEXP (value, 0), subtarget);
4747       return expand_binop (GET_MODE (value), binoptab, tmp,
4748                            force_operand (op2, NULL_RTX),
4749                            target, 0, OPTAB_LIB_WIDEN);
4750       /* We give UNSIGNEDP = 0 to expand_binop
4751          because the only operations we are expanding here are signed ones.  */
4752     }
4753   return value;
4754 }
4755 \f
4756 /* Subroutine of expand_expr:
4757    save the non-copied parts (LIST) of an expr (LHS), and return a list
4758    which can restore these values to their previous values,
4759    should something modify their storage.  */
4760
4761 static tree
4762 save_noncopied_parts (lhs, list)
4763      tree lhs;
4764      tree list;
4765 {
4766   tree tail;
4767   tree parts = 0;
4768
4769   for (tail = list; tail; tail = TREE_CHAIN (tail))
4770     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4771       parts = chainon (parts, save_noncopied_parts (lhs, TREE_VALUE (tail)));
4772     else
4773       {
4774         tree part = TREE_VALUE (tail);
4775         tree part_type = TREE_TYPE (part);
4776         tree to_be_saved = build (COMPONENT_REF, part_type, lhs, part);
4777         rtx target = assign_temp (part_type, 0, 1, 1);
4778         if (! memory_address_p (TYPE_MODE (part_type), XEXP (target, 0)))
4779           target = change_address (target, TYPE_MODE (part_type), NULL_RTX);
4780         parts = tree_cons (to_be_saved,
4781                            build (RTL_EXPR, part_type, NULL_TREE,
4782                                   (tree) target),
4783                            parts);
4784         store_expr (TREE_PURPOSE (parts), RTL_EXPR_RTL (TREE_VALUE (parts)), 0);
4785       }
4786   return parts;
4787 }
4788
4789 /* Subroutine of expand_expr:
4790    record the non-copied parts (LIST) of an expr (LHS), and return a list
4791    which specifies the initial values of these parts.  */
4792
4793 static tree
4794 init_noncopied_parts (lhs, list)
4795      tree lhs;
4796      tree list;
4797 {
4798   tree tail;
4799   tree parts = 0;
4800
4801   for (tail = list; tail; tail = TREE_CHAIN (tail))
4802     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4803       parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail)));
4804     else
4805       {
4806         tree part = TREE_VALUE (tail);
4807         tree part_type = TREE_TYPE (part);
4808         tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part);
4809         parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts);
4810       }
4811   return parts;
4812 }
4813
4814 /* Subroutine of expand_expr: return nonzero iff there is no way that
4815    EXP can reference X, which is being modified.  TOP_P is nonzero if this
4816    call is going to be used to determine whether we need a temporary
4817    for EXP, as opposed to a recursive call to this function.
4818
4819    It is always safe for this routine to return zero since it merely
4820    searches for optimization opportunities.  */
4821
4822 static int
4823 safe_from_p (x, exp, top_p)
4824      rtx x;
4825      tree exp;
4826      int top_p;
4827 {
4828   rtx exp_rtl = 0;
4829   int i, nops;
4830   static int save_expr_count;
4831   static int save_expr_size = 0;
4832   static tree *save_expr_rewritten;
4833   static tree save_expr_trees[256];
4834
4835   if (x == 0
4836       /* If EXP has varying size, we MUST use a target since we currently
4837          have no way of allocating temporaries of variable size
4838          (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
4839          So we assume here that something at a higher level has prevented a
4840          clash.  This is somewhat bogus, but the best we can do.  Only
4841          do this when X is BLKmode and when we are at the top level.  */
4842       || (top_p && TREE_TYPE (exp) != 0 && TYPE_SIZE (TREE_TYPE (exp)) != 0
4843           && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
4844           && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
4845               || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
4846               || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
4847               != INTEGER_CST)
4848           && GET_MODE (x) == BLKmode))
4849     return 1;
4850
4851   if (top_p && save_expr_size == 0)
4852     {
4853       int rtn;
4854
4855       save_expr_count = 0;
4856       save_expr_size = sizeof (save_expr_trees) / sizeof (save_expr_trees[0]);
4857       save_expr_rewritten = &save_expr_trees[0];
4858
4859       rtn = safe_from_p (x, exp, 1);
4860
4861       for (i = 0; i < save_expr_count; ++i)
4862         {
4863           if (TREE_CODE (save_expr_trees[i]) != ERROR_MARK)
4864             abort ();
4865           TREE_SET_CODE (save_expr_trees[i], SAVE_EXPR);
4866         }
4867
4868       save_expr_size = 0;
4869
4870       return rtn;
4871     }
4872
4873   /* If this is a subreg of a hard register, declare it unsafe, otherwise,
4874      find the underlying pseudo.  */
4875   if (GET_CODE (x) == SUBREG)
4876     {
4877       x = SUBREG_REG (x);
4878       if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
4879         return 0;
4880     }
4881
4882   /* If X is a location in the outgoing argument area, it is always safe.  */
4883   if (GET_CODE (x) == MEM
4884       && (XEXP (x, 0) == virtual_outgoing_args_rtx
4885           || (GET_CODE (XEXP (x, 0)) == PLUS
4886               && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx)))
4887     return 1;
4888
4889   switch (TREE_CODE_CLASS (TREE_CODE (exp)))
4890     {
4891     case 'd':
4892       exp_rtl = DECL_RTL (exp);
4893       break;
4894
4895     case 'c':
4896       return 1;
4897
4898     case 'x':
4899       if (TREE_CODE (exp) == TREE_LIST)
4900         return ((TREE_VALUE (exp) == 0
4901                  || safe_from_p (x, TREE_VALUE (exp), 0))
4902                 && (TREE_CHAIN (exp) == 0
4903                     || safe_from_p (x, TREE_CHAIN (exp), 0)));
4904       else if (TREE_CODE (exp) == ERROR_MARK)
4905         return 1;       /* An already-visited SAVE_EXPR? */
4906       else
4907         return 0;
4908
4909     case '1':
4910       return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
4911
4912     case '2':
4913     case '<':
4914       return (safe_from_p (x, TREE_OPERAND (exp, 0), 0)
4915               && safe_from_p (x, TREE_OPERAND (exp, 1), 0));
4916
4917     case 'e':
4918     case 'r':
4919       /* Now do code-specific tests.  EXP_RTL is set to any rtx we find in
4920          the expression.  If it is set, we conflict iff we are that rtx or
4921          both are in memory.  Otherwise, we check all operands of the
4922          expression recursively.  */
4923
4924       switch (TREE_CODE (exp))
4925         {
4926         case ADDR_EXPR:
4927           return (staticp (TREE_OPERAND (exp, 0))
4928                   || safe_from_p (x, TREE_OPERAND (exp, 0), 0)
4929                   || TREE_STATIC (exp));
4930
4931         case INDIRECT_REF:
4932           if (GET_CODE (x) == MEM)
4933             return 0;
4934           break;
4935
4936         case CALL_EXPR:
4937           exp_rtl = CALL_EXPR_RTL (exp);
4938           if (exp_rtl == 0)
4939             {
4940               /* Assume that the call will clobber all hard registers and
4941                  all of memory.  */
4942               if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
4943                   || GET_CODE (x) == MEM)
4944                 return 0;
4945             }
4946
4947           break;
4948
4949         case RTL_EXPR:
4950           /* If a sequence exists, we would have to scan every instruction
4951              in the sequence to see if it was safe.  This is probably not
4952              worthwhile.  */
4953           if (RTL_EXPR_SEQUENCE (exp))
4954             return 0;
4955
4956           exp_rtl = RTL_EXPR_RTL (exp);
4957           break;
4958
4959         case WITH_CLEANUP_EXPR:
4960           exp_rtl = RTL_EXPR_RTL (exp);
4961           break;
4962
4963         case CLEANUP_POINT_EXPR:
4964           return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
4965
4966         case SAVE_EXPR:
4967           exp_rtl = SAVE_EXPR_RTL (exp);
4968           if (exp_rtl)
4969             break;
4970
4971           /* This SAVE_EXPR might appear many times in the top-level
4972              safe_from_p() expression, and if it has a complex
4973              subexpression, examining it multiple times could result
4974              in a combinatorial explosion.  E.g. on an Alpha
4975              running at least 200MHz, a Fortran test case compiled with
4976              optimization took about 28 minutes to compile -- even though
4977              it was only a few lines long, and the complicated line causing
4978              so much time to be spent in the earlier version of safe_from_p()
4979              had only 293 or so unique nodes.
4980
4981              So, turn this SAVE_EXPR into an ERROR_MARK for now, but remember
4982              where it is so we can turn it back in the top-level safe_from_p()
4983              when we're done.  */
4984
4985           /* For now, don't bother re-sizing the array. */
4986           if (save_expr_count >= save_expr_size)
4987             return 0;
4988           save_expr_rewritten[save_expr_count++] = exp;
4989
4990           nops = tree_code_length[(int) SAVE_EXPR];
4991           for (i = 0; i < nops; i++)
4992             {
4993               tree operand = TREE_OPERAND (exp, i);
4994               if (operand == NULL_TREE)
4995                 continue;
4996               TREE_SET_CODE (exp, ERROR_MARK);
4997               if (!safe_from_p (x, operand, 0))
4998                 return 0;
4999               TREE_SET_CODE (exp, SAVE_EXPR);
5000             }
5001           TREE_SET_CODE (exp, ERROR_MARK);
5002           return 1;
5003
5004         case BIND_EXPR:
5005           /* The only operand we look at is operand 1.  The rest aren't
5006              part of the expression.  */
5007           return safe_from_p (x, TREE_OPERAND (exp, 1), 0);
5008
5009         case METHOD_CALL_EXPR:
5010           /* This takes a rtx argument, but shouldn't appear here.  */
5011           abort ();
5012           
5013         default:
5014           break;
5015         }
5016
5017       /* If we have an rtx, we do not need to scan our operands.  */
5018       if (exp_rtl)
5019         break;
5020
5021       nops = tree_code_length[(int) TREE_CODE (exp)];
5022       for (i = 0; i < nops; i++)
5023         if (TREE_OPERAND (exp, i) != 0
5024             && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
5025           return 0;
5026     }
5027
5028   /* If we have an rtl, find any enclosed object.  Then see if we conflict
5029      with it.  */
5030   if (exp_rtl)
5031     {
5032       if (GET_CODE (exp_rtl) == SUBREG)
5033         {
5034           exp_rtl = SUBREG_REG (exp_rtl);
5035           if (GET_CODE (exp_rtl) == REG
5036               && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
5037             return 0;
5038         }
5039
5040       /* If the rtl is X, then it is not safe.  Otherwise, it is unless both
5041          are memory and EXP is not readonly.  */
5042       return ! (rtx_equal_p (x, exp_rtl)
5043                 || (GET_CODE (x) == MEM && GET_CODE (exp_rtl) == MEM
5044                     && ! TREE_READONLY (exp)));
5045     }
5046
5047   /* If we reach here, it is safe.  */
5048   return 1;
5049 }
5050
5051 /* Subroutine of expand_expr: return nonzero iff EXP is an
5052    expression whose type is statically determinable.  */
5053
5054 static int
5055 fixed_type_p (exp)
5056      tree exp;
5057 {
5058   if (TREE_CODE (exp) == PARM_DECL
5059       || TREE_CODE (exp) == VAR_DECL
5060       || TREE_CODE (exp) == CALL_EXPR || TREE_CODE (exp) == TARGET_EXPR
5061       || TREE_CODE (exp) == COMPONENT_REF
5062       || TREE_CODE (exp) == ARRAY_REF)
5063     return 1;
5064   return 0;
5065 }
5066
5067 /* Subroutine of expand_expr: return rtx if EXP is a
5068    variable or parameter; else return 0.  */
5069
5070 static rtx
5071 var_rtx (exp)
5072      tree exp;
5073 {
5074   STRIP_NOPS (exp);
5075   switch (TREE_CODE (exp))
5076     {
5077     case PARM_DECL:
5078     case VAR_DECL:
5079       return DECL_RTL (exp);
5080     default:
5081       return 0;
5082     }
5083 }
5084
5085 #ifdef MAX_INTEGER_COMPUTATION_MODE
5086 void
5087 check_max_integer_computation_mode (exp)
5088     tree exp;
5089 {
5090   enum tree_code code = TREE_CODE (exp);
5091   enum machine_mode mode;
5092
5093   /* We must allow conversions of constants to MAX_INTEGER_COMPUTATION_MODE.  */
5094   if (code == NOP_EXPR
5095       && TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
5096     return;
5097
5098   /* First check the type of the overall operation.   We need only look at
5099      unary, binary and relational operations.  */
5100   if (TREE_CODE_CLASS (code) == '1'
5101       || TREE_CODE_CLASS (code) == '2'
5102       || TREE_CODE_CLASS (code) == '<')
5103     {
5104       mode = TYPE_MODE (TREE_TYPE (exp));
5105       if (GET_MODE_CLASS (mode) == MODE_INT
5106           && mode > MAX_INTEGER_COMPUTATION_MODE)
5107         fatal ("unsupported wide integer operation");
5108     }
5109
5110   /* Check operand of a unary op.  */
5111   if (TREE_CODE_CLASS (code) == '1')
5112     {
5113       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5114       if (GET_MODE_CLASS (mode) == MODE_INT
5115           && mode > MAX_INTEGER_COMPUTATION_MODE)
5116         fatal ("unsupported wide integer operation");
5117     }
5118         
5119   /* Check operands of a binary/comparison op.  */
5120   if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<')
5121     {
5122       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5123       if (GET_MODE_CLASS (mode) == MODE_INT
5124           && mode > MAX_INTEGER_COMPUTATION_MODE)
5125         fatal ("unsupported wide integer operation");
5126
5127       mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
5128       if (GET_MODE_CLASS (mode) == MODE_INT
5129           && mode > MAX_INTEGER_COMPUTATION_MODE)
5130         fatal ("unsupported wide integer operation");
5131     }
5132 }
5133 #endif
5134
5135 \f
5136 /* expand_expr: generate code for computing expression EXP.
5137    An rtx for the computed value is returned.  The value is never null.
5138    In the case of a void EXP, const0_rtx is returned.
5139
5140    The value may be stored in TARGET if TARGET is nonzero.
5141    TARGET is just a suggestion; callers must assume that
5142    the rtx returned may not be the same as TARGET.
5143
5144    If TARGET is CONST0_RTX, it means that the value will be ignored.
5145
5146    If TMODE is not VOIDmode, it suggests generating the
5147    result in mode TMODE.  But this is done only when convenient.
5148    Otherwise, TMODE is ignored and the value generated in its natural mode.
5149    TMODE is just a suggestion; callers must assume that
5150    the rtx returned may not have mode TMODE.
5151
5152    Note that TARGET may have neither TMODE nor MODE.  In that case, it
5153    probably will not be used.
5154
5155    If MODIFIER is EXPAND_SUM then when EXP is an addition
5156    we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
5157    or a nest of (PLUS ...) and (MINUS ...) where the terms are
5158    products as above, or REG or MEM, or constant.
5159    Ordinarily in such cases we would output mul or add instructions
5160    and then return a pseudo reg containing the sum.
5161
5162    EXPAND_INITIALIZER is much like EXPAND_SUM except that
5163    it also marks a label as absolutely required (it can't be dead).
5164    It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
5165    This is used for outputting expressions used in initializers.
5166
5167    EXPAND_CONST_ADDRESS says that it is okay to return a MEM
5168    with a constant address even if that address is not normally legitimate.
5169    EXPAND_INITIALIZER and EXPAND_SUM also have this effect.  */
5170
5171 rtx
5172 expand_expr (exp, target, tmode, modifier)
5173      register tree exp;
5174      rtx target;
5175      enum machine_mode tmode;
5176      enum expand_modifier modifier;
5177 {
5178   /* Chain of pending expressions for PLACEHOLDER_EXPR to replace.
5179      This is static so it will be accessible to our recursive callees.  */
5180   static tree placeholder_list = 0;
5181   register rtx op0, op1, temp;
5182   tree type = TREE_TYPE (exp);
5183   int unsignedp = TREE_UNSIGNED (type);
5184   register enum machine_mode mode = TYPE_MODE (type);
5185   register enum tree_code code = TREE_CODE (exp);
5186   optab this_optab;
5187   /* Use subtarget as the target for operand 0 of a binary operation.  */
5188   rtx subtarget = (target != 0 && GET_CODE (target) == REG ? target : 0);
5189   rtx original_target = target;
5190   int ignore = (target == const0_rtx
5191                 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
5192                      || code == CONVERT_EXPR || code == REFERENCE_EXPR
5193                      || code == COND_EXPR)
5194                     && TREE_CODE (type) == VOID_TYPE));
5195   tree context;
5196   /* Used by check-memory-usage to make modifier read only.  */
5197   enum expand_modifier ro_modifier;
5198
5199   /* Make a read-only version of the modifier.  */
5200   if (modifier == EXPAND_NORMAL || modifier == EXPAND_SUM
5201       || modifier == EXPAND_CONST_ADDRESS || modifier == EXPAND_INITIALIZER)
5202     ro_modifier = modifier;
5203   else
5204     ro_modifier = EXPAND_NORMAL;
5205
5206   /* Don't use hard regs as subtargets, because the combiner
5207      can only handle pseudo regs.  */
5208   if (subtarget && REGNO (subtarget) < FIRST_PSEUDO_REGISTER)
5209     subtarget = 0;
5210   /* Avoid subtargets inside loops,
5211      since they hide some invariant expressions.  */
5212   if (preserve_subexpressions_p ())
5213     subtarget = 0;
5214
5215   /* If we are going to ignore this result, we need only do something
5216      if there is a side-effect somewhere in the expression.  If there
5217      is, short-circuit the most common cases here.  Note that we must
5218      not call expand_expr with anything but const0_rtx in case this
5219      is an initial expansion of a size that contains a PLACEHOLDER_EXPR.  */
5220
5221   if (ignore)
5222     {
5223       if (! TREE_SIDE_EFFECTS (exp))
5224         return const0_rtx;
5225
5226       /* Ensure we reference a volatile object even if value is ignored.  */
5227       if (TREE_THIS_VOLATILE (exp)
5228           && TREE_CODE (exp) != FUNCTION_DECL
5229           && mode != VOIDmode && mode != BLKmode)
5230         {
5231           temp = expand_expr (exp, NULL_RTX, VOIDmode, ro_modifier);
5232           if (GET_CODE (temp) == MEM)
5233             temp = copy_to_reg (temp);
5234           return const0_rtx;
5235         }
5236
5237       if (TREE_CODE_CLASS (code) == '1')
5238         return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
5239                             VOIDmode, ro_modifier);
5240       else if (TREE_CODE_CLASS (code) == '2'
5241                || TREE_CODE_CLASS (code) == '<')
5242         {
5243           expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, ro_modifier);
5244           expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, ro_modifier);
5245           return const0_rtx;
5246         }
5247       else if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
5248                && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
5249         /* If the second operand has no side effects, just evaluate
5250            the first.  */
5251         return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
5252                             VOIDmode, ro_modifier);
5253
5254       target = 0;
5255     }
5256
5257 #ifdef MAX_INTEGER_COMPUTATION_MODE
5258   if (target && TREE_CODE (exp) != INTEGER_CST)
5259     {
5260       enum machine_mode mode = GET_MODE (target);
5261
5262       if (GET_MODE_CLASS (mode) == MODE_INT
5263           && mode > MAX_INTEGER_COMPUTATION_MODE)
5264         fatal ("unsupported wide integer operation");
5265     }
5266
5267   if (TREE_CODE (exp) != INTEGER_CST
5268       && GET_MODE_CLASS (tmode) == MODE_INT
5269       && tmode > MAX_INTEGER_COMPUTATION_MODE)
5270     fatal ("unsupported wide integer operation");
5271
5272   check_max_integer_computation_mode (exp);
5273 #endif
5274
5275   /* If will do cse, generate all results into pseudo registers
5276      since 1) that allows cse to find more things
5277      and 2) otherwise cse could produce an insn the machine
5278      cannot support.  */
5279
5280   if (! cse_not_expected && mode != BLKmode && target
5281       && (GET_CODE (target) != REG || REGNO (target) < FIRST_PSEUDO_REGISTER))
5282     target = subtarget;
5283
5284   switch (code)
5285     {
5286     case LABEL_DECL:
5287       {
5288         tree function = decl_function_context (exp);
5289         /* Handle using a label in a containing function.  */
5290         if (function != current_function_decl
5291             && function != inline_function_decl && function != 0)
5292           {
5293             struct function *p = find_function_data (function);
5294             /* Allocate in the memory associated with the function
5295                that the label is in.  */
5296             push_obstacks (p->function_obstack,
5297                            p->function_maybepermanent_obstack);
5298
5299             p->forced_labels = gen_rtx_EXPR_LIST (VOIDmode,
5300                                                   label_rtx (exp),
5301                                                   p->forced_labels);
5302             pop_obstacks ();
5303           }
5304         else if (modifier == EXPAND_INITIALIZER)
5305           forced_labels = gen_rtx_EXPR_LIST (VOIDmode,
5306                                              label_rtx (exp), forced_labels);
5307         temp = gen_rtx_MEM (FUNCTION_MODE,
5308                             gen_rtx_LABEL_REF (Pmode, label_rtx (exp)));
5309         if (function != current_function_decl
5310             && function != inline_function_decl && function != 0)
5311           LABEL_REF_NONLOCAL_P (XEXP (temp, 0)) = 1;
5312         return temp;
5313       }
5314
5315     case PARM_DECL:
5316       if (DECL_RTL (exp) == 0)
5317         {
5318           error_with_decl (exp, "prior parameter's size depends on `%s'");
5319           return CONST0_RTX (mode);
5320         }
5321
5322       /* ... fall through ...  */
5323
5324     case VAR_DECL:
5325       /* If a static var's type was incomplete when the decl was written,
5326          but the type is complete now, lay out the decl now.  */
5327       if (DECL_SIZE (exp) == 0 && TYPE_SIZE (TREE_TYPE (exp)) != 0
5328           && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
5329         {
5330           push_obstacks_nochange ();
5331           end_temporary_allocation ();
5332           layout_decl (exp, 0);
5333           PUT_MODE (DECL_RTL (exp), DECL_MODE (exp));
5334           pop_obstacks ();
5335         }
5336
5337       /* Only check automatic variables.  Currently, function arguments are
5338          not checked (this can be done at compile-time with prototypes).
5339          Aggregates are not checked.  */
5340       if (flag_check_memory_usage && code == VAR_DECL
5341           && GET_CODE (DECL_RTL (exp)) == MEM
5342           && DECL_CONTEXT (exp) != NULL_TREE
5343           && ! TREE_STATIC (exp)
5344           && ! AGGREGATE_TYPE_P (TREE_TYPE (exp)))
5345         {
5346           enum memory_use_mode memory_usage;
5347           memory_usage = get_memory_usage_from_modifier (modifier);
5348
5349           if (memory_usage != MEMORY_USE_DONT)
5350             emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
5351                                XEXP (DECL_RTL (exp), 0), ptr_mode,
5352                                GEN_INT (int_size_in_bytes (type)),
5353                                TYPE_MODE (sizetype),
5354                                GEN_INT (memory_usage),
5355                                TYPE_MODE (integer_type_node));
5356         }
5357
5358       /* ... fall through ...  */
5359
5360     case FUNCTION_DECL:
5361     case RESULT_DECL:
5362       if (DECL_RTL (exp) == 0)
5363         abort ();
5364
5365       /* Ensure variable marked as used even if it doesn't go through
5366          a parser.  If it hasn't be used yet, write out an external
5367          definition.  */
5368       if (! TREE_USED (exp))
5369         {
5370           assemble_external (exp);
5371           TREE_USED (exp) = 1;
5372         }
5373
5374       /* Show we haven't gotten RTL for this yet.  */
5375       temp = 0;
5376
5377       /* Handle variables inherited from containing functions.  */
5378       context = decl_function_context (exp);
5379
5380       /* We treat inline_function_decl as an alias for the current function
5381          because that is the inline function whose vars, types, etc.
5382          are being merged into the current function.
5383          See expand_inline_function.  */
5384
5385       if (context != 0 && context != current_function_decl
5386           && context != inline_function_decl
5387           /* If var is static, we don't need a static chain to access it.  */
5388           && ! (GET_CODE (DECL_RTL (exp)) == MEM
5389                 && CONSTANT_P (XEXP (DECL_RTL (exp), 0))))
5390         {
5391           rtx addr;
5392
5393           /* Mark as non-local and addressable.  */
5394           DECL_NONLOCAL (exp) = 1;
5395           if (DECL_NO_STATIC_CHAIN (current_function_decl))
5396             abort ();
5397           mark_addressable (exp);
5398           if (GET_CODE (DECL_RTL (exp)) != MEM)
5399             abort ();
5400           addr = XEXP (DECL_RTL (exp), 0);
5401           if (GET_CODE (addr) == MEM)
5402             addr = gen_rtx_MEM (Pmode,
5403                                 fix_lexical_addr (XEXP (addr, 0), exp));
5404           else
5405             addr = fix_lexical_addr (addr, exp);
5406           temp = change_address (DECL_RTL (exp), mode, addr);
5407         }
5408
5409       /* This is the case of an array whose size is to be determined
5410          from its initializer, while the initializer is still being parsed.
5411          See expand_decl.  */
5412
5413       else if (GET_CODE (DECL_RTL (exp)) == MEM
5414                && GET_CODE (XEXP (DECL_RTL (exp), 0)) == REG)
5415         temp = change_address (DECL_RTL (exp), GET_MODE (DECL_RTL (exp)),
5416                                XEXP (DECL_RTL (exp), 0));
5417
5418       /* If DECL_RTL is memory, we are in the normal case and either
5419          the address is not valid or it is not a register and -fforce-addr
5420          is specified, get the address into a register.  */
5421
5422       else if (GET_CODE (DECL_RTL (exp)) == MEM
5423                && modifier != EXPAND_CONST_ADDRESS
5424                && modifier != EXPAND_SUM
5425                && modifier != EXPAND_INITIALIZER
5426                && (! memory_address_p (DECL_MODE (exp),
5427                                        XEXP (DECL_RTL (exp), 0))
5428                    || (flag_force_addr
5429                        && GET_CODE (XEXP (DECL_RTL (exp), 0)) != REG)))
5430         temp = change_address (DECL_RTL (exp), VOIDmode,
5431                                copy_rtx (XEXP (DECL_RTL (exp), 0)));
5432
5433       /* If we got something, return it.  But first, set the alignment
5434          the address is a register.  */
5435       if (temp != 0)
5436         {
5437           if (GET_CODE (temp) == MEM && GET_CODE (XEXP (temp, 0)) == REG)
5438             mark_reg_pointer (XEXP (temp, 0),
5439                               DECL_ALIGN (exp) / BITS_PER_UNIT);
5440
5441           return temp;
5442         }
5443
5444       /* If the mode of DECL_RTL does not match that of the decl, it
5445          must be a promoted value.  We return a SUBREG of the wanted mode,
5446          but mark it so that we know that it was already extended.  */
5447
5448       if (GET_CODE (DECL_RTL (exp)) == REG
5449           && GET_MODE (DECL_RTL (exp)) != mode)
5450         {
5451           /* Get the signedness used for this variable.  Ensure we get the
5452              same mode we got when the variable was declared.  */
5453           if (GET_MODE (DECL_RTL (exp))
5454               != promote_mode (type, DECL_MODE (exp), &unsignedp, 0))
5455             abort ();
5456
5457           temp = gen_rtx_SUBREG (mode, DECL_RTL (exp), 0);
5458           SUBREG_PROMOTED_VAR_P (temp) = 1;
5459           SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
5460           return temp;
5461         }
5462
5463       return DECL_RTL (exp);
5464
5465     case INTEGER_CST:
5466       return immed_double_const (TREE_INT_CST_LOW (exp),
5467                                  TREE_INT_CST_HIGH (exp),
5468                                  mode);
5469
5470     case CONST_DECL:
5471       return expand_expr (DECL_INITIAL (exp), target, VOIDmode,
5472                           EXPAND_MEMORY_USE_BAD);
5473
5474     case REAL_CST:
5475       /* If optimized, generate immediate CONST_DOUBLE
5476          which will be turned into memory by reload if necessary. 
5477      
5478          We used to force a register so that loop.c could see it.  But
5479          this does not allow gen_* patterns to perform optimizations with
5480          the constants.  It also produces two insns in cases like "x = 1.0;".
5481          On most machines, floating-point constants are not permitted in
5482          many insns, so we'd end up copying it to a register in any case.
5483
5484          Now, we do the copying in expand_binop, if appropriate.  */
5485       return immed_real_const (exp);
5486
5487     case COMPLEX_CST:
5488     case STRING_CST:
5489       if (! TREE_CST_RTL (exp))
5490         output_constant_def (exp);
5491
5492       /* TREE_CST_RTL probably contains a constant address.
5493          On RISC machines where a constant address isn't valid,
5494          make some insns to get that address into a register.  */
5495       if (GET_CODE (TREE_CST_RTL (exp)) == MEM
5496           && modifier != EXPAND_CONST_ADDRESS
5497           && modifier != EXPAND_INITIALIZER
5498           && modifier != EXPAND_SUM
5499           && (! memory_address_p (mode, XEXP (TREE_CST_RTL (exp), 0))
5500               || (flag_force_addr
5501                   && GET_CODE (XEXP (TREE_CST_RTL (exp), 0)) != REG)))
5502         return change_address (TREE_CST_RTL (exp), VOIDmode,
5503                                copy_rtx (XEXP (TREE_CST_RTL (exp), 0)));
5504       return TREE_CST_RTL (exp);
5505
5506     case EXPR_WITH_FILE_LOCATION:
5507       {
5508         rtx to_return;
5509         char *saved_input_filename = input_filename;
5510         int saved_lineno = lineno;
5511         input_filename = EXPR_WFL_FILENAME (exp);
5512         lineno = EXPR_WFL_LINENO (exp);
5513         if (EXPR_WFL_EMIT_LINE_NOTE (exp))
5514           emit_line_note (input_filename, lineno);
5515         /* Possibly avoid switching back and force here */
5516         to_return = expand_expr (EXPR_WFL_NODE (exp), target, tmode, modifier);
5517         input_filename = saved_input_filename;
5518         lineno = saved_lineno;
5519         return to_return;
5520       }
5521
5522     case SAVE_EXPR:
5523       context = decl_function_context (exp);
5524
5525       /* If this SAVE_EXPR was at global context, assume we are an
5526          initialization function and move it into our context.  */
5527       if (context == 0)
5528         SAVE_EXPR_CONTEXT (exp) = current_function_decl;
5529
5530       /* We treat inline_function_decl as an alias for the current function
5531          because that is the inline function whose vars, types, etc.
5532          are being merged into the current function.
5533          See expand_inline_function.  */
5534       if (context == current_function_decl || context == inline_function_decl)
5535         context = 0;
5536
5537       /* If this is non-local, handle it.  */
5538       if (context)
5539         {
5540           /* The following call just exists to abort if the context is
5541              not of a containing function.  */
5542           find_function_data (context);
5543
5544           temp = SAVE_EXPR_RTL (exp);
5545           if (temp && GET_CODE (temp) == REG)
5546             {
5547               put_var_into_stack (exp);
5548               temp = SAVE_EXPR_RTL (exp);
5549             }
5550           if (temp == 0 || GET_CODE (temp) != MEM)
5551             abort ();
5552           return change_address (temp, mode,
5553                                  fix_lexical_addr (XEXP (temp, 0), exp));
5554         }
5555       if (SAVE_EXPR_RTL (exp) == 0)
5556         {
5557           if (mode == VOIDmode)
5558             temp = const0_rtx;
5559           else
5560             temp = assign_temp (type, 3, 0, 0);
5561
5562           SAVE_EXPR_RTL (exp) = temp;
5563           if (!optimize && GET_CODE (temp) == REG)
5564             save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, temp,
5565                                                 save_expr_regs);
5566
5567           /* If the mode of TEMP does not match that of the expression, it
5568              must be a promoted value.  We pass store_expr a SUBREG of the
5569              wanted mode but mark it so that we know that it was already
5570              extended.  Note that `unsignedp' was modified above in
5571              this case.  */
5572
5573           if (GET_CODE (temp) == REG && GET_MODE (temp) != mode)
5574             {
5575               temp = gen_rtx_SUBREG (mode, SAVE_EXPR_RTL (exp), 0);
5576               SUBREG_PROMOTED_VAR_P (temp) = 1;
5577               SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
5578             }
5579
5580           if (temp == const0_rtx)
5581             expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5582                          EXPAND_MEMORY_USE_BAD);
5583           else
5584             store_expr (TREE_OPERAND (exp, 0), temp, 0);
5585
5586           TREE_USED (exp) = 1;
5587         }
5588
5589       /* If the mode of SAVE_EXPR_RTL does not match that of the expression, it
5590          must be a promoted value.  We return a SUBREG of the wanted mode,
5591          but mark it so that we know that it was already extended.  */
5592
5593       if (GET_CODE (SAVE_EXPR_RTL (exp)) == REG
5594           && GET_MODE (SAVE_EXPR_RTL (exp)) != mode)
5595         {
5596           /* Compute the signedness and make the proper SUBREG.  */
5597           promote_mode (type, mode, &unsignedp, 0);
5598           temp = gen_rtx_SUBREG (mode, SAVE_EXPR_RTL (exp), 0);
5599           SUBREG_PROMOTED_VAR_P (temp) = 1;
5600           SUBREG_PROMOTED_UNSIGNED_P (temp) = unsignedp;
5601           return temp;
5602         }
5603
5604       return SAVE_EXPR_RTL (exp);
5605
5606     case UNSAVE_EXPR:
5607       {
5608         rtx temp;
5609         temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
5610         TREE_OPERAND (exp, 0) = unsave_expr_now (TREE_OPERAND (exp, 0));
5611         return temp;
5612       }
5613
5614     case PLACEHOLDER_EXPR:
5615       {
5616         tree placeholder_expr;
5617
5618         /* If there is an object on the head of the placeholder list,
5619            see if some object in it of type TYPE or a pointer to it.  For
5620            further information, see tree.def.  */
5621         for (placeholder_expr = placeholder_list;
5622              placeholder_expr != 0;
5623              placeholder_expr = TREE_CHAIN (placeholder_expr))
5624           {
5625             tree need_type = TYPE_MAIN_VARIANT (type);
5626             tree object = 0;
5627             tree old_list = placeholder_list;
5628             tree elt;
5629
5630             /* Find the outermost reference that is of the type we want.
5631                If none, see if any object has a type that is a pointer to 
5632                the type we want.  */
5633             for (elt = TREE_PURPOSE (placeholder_expr);
5634                  elt != 0 && object == 0;
5635                  elt
5636                  = ((TREE_CODE (elt) == COMPOUND_EXPR
5637                      || TREE_CODE (elt) == COND_EXPR)
5638                     ? TREE_OPERAND (elt, 1)
5639                     : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
5640                        || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
5641                        || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
5642                        || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
5643                     ? TREE_OPERAND (elt, 0) : 0))
5644               if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
5645                 object = elt;
5646
5647             for (elt = TREE_PURPOSE (placeholder_expr);
5648                  elt != 0 && object == 0;
5649                  elt
5650                  = ((TREE_CODE (elt) == COMPOUND_EXPR
5651                      || TREE_CODE (elt) == COND_EXPR)
5652                     ? TREE_OPERAND (elt, 1)
5653                     : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
5654                        || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
5655                        || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
5656                        || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
5657                     ? TREE_OPERAND (elt, 0) : 0))
5658               if (POINTER_TYPE_P (TREE_TYPE (elt))
5659                   && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
5660                       == need_type))
5661                 object = build1 (INDIRECT_REF, need_type, elt);
5662
5663             if (object != 0)
5664               {
5665                 /* Expand this object skipping the list entries before
5666                    it was found in case it is also a PLACEHOLDER_EXPR.
5667                    In that case, we want to translate it using subsequent
5668                    entries.  */
5669                 placeholder_list = TREE_CHAIN (placeholder_expr);
5670                 temp = expand_expr (object, original_target, tmode,
5671                                     ro_modifier);
5672                 placeholder_list = old_list;
5673                 return temp;
5674               }
5675           }
5676       }
5677
5678       /* We can't find the object or there was a missing WITH_RECORD_EXPR.  */
5679       abort ();
5680
5681     case WITH_RECORD_EXPR:
5682       /* Put the object on the placeholder list, expand our first operand,
5683          and pop the list.  */
5684       placeholder_list = tree_cons (TREE_OPERAND (exp, 1), NULL_TREE,
5685                                     placeholder_list);
5686       target = expand_expr (TREE_OPERAND (exp, 0), original_target,
5687                             tmode, ro_modifier);
5688       placeholder_list = TREE_CHAIN (placeholder_list);
5689       return target;
5690
5691     case EXIT_EXPR:
5692       expand_exit_loop_if_false (NULL_PTR,
5693                                  invert_truthvalue (TREE_OPERAND (exp, 0)));
5694       return const0_rtx;
5695
5696     case LOOP_EXPR:
5697       push_temp_slots ();
5698       expand_start_loop (1);
5699       expand_expr_stmt (TREE_OPERAND (exp, 0));
5700       expand_end_loop ();
5701       pop_temp_slots ();
5702
5703       return const0_rtx;
5704
5705     case BIND_EXPR:
5706       {
5707         tree vars = TREE_OPERAND (exp, 0);
5708         int vars_need_expansion = 0;
5709
5710         /* Need to open a binding contour here because
5711            if there are any cleanups they must be contained here.  */
5712         expand_start_bindings (0);
5713
5714         /* Mark the corresponding BLOCK for output in its proper place.  */
5715         if (TREE_OPERAND (exp, 2) != 0
5716             && ! TREE_USED (TREE_OPERAND (exp, 2)))
5717           insert_block (TREE_OPERAND (exp, 2));
5718
5719         /* If VARS have not yet been expanded, expand them now.  */
5720         while (vars)
5721           {
5722             if (DECL_RTL (vars) == 0)
5723               {
5724                 vars_need_expansion = 1;
5725                 expand_decl (vars);
5726               }
5727             expand_decl_init (vars);
5728             vars = TREE_CHAIN (vars);
5729           }
5730
5731         temp = expand_expr (TREE_OPERAND (exp, 1), target, tmode, ro_modifier);
5732
5733         expand_end_bindings (TREE_OPERAND (exp, 0), 0, 0);
5734
5735         return temp;
5736       }
5737
5738     case RTL_EXPR:
5739       if (RTL_EXPR_SEQUENCE (exp))
5740         {
5741           if (RTL_EXPR_SEQUENCE (exp) == const0_rtx)
5742             abort ();
5743           emit_insns (RTL_EXPR_SEQUENCE (exp));
5744           RTL_EXPR_SEQUENCE (exp) = const0_rtx;
5745         }
5746       preserve_rtl_expr_result (RTL_EXPR_RTL (exp));
5747       free_temps_for_rtl_expr (exp);
5748       return RTL_EXPR_RTL (exp);
5749
5750     case CONSTRUCTOR:
5751       /* If we don't need the result, just ensure we evaluate any
5752          subexpressions.  */
5753       if (ignore)
5754         {
5755           tree elt;
5756           for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
5757             expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode,
5758                          EXPAND_MEMORY_USE_BAD);
5759           return const0_rtx;
5760         }
5761
5762       /* All elts simple constants => refer to a constant in memory.  But
5763          if this is a non-BLKmode mode, let it store a field at a time
5764          since that should make a CONST_INT or CONST_DOUBLE when we
5765          fold.  Likewise, if we have a target we can use, it is best to
5766          store directly into the target unless the type is large enough
5767          that memcpy will be used.  If we are making an initializer and
5768          all operands are constant, put it in memory as well.  */
5769       else if ((TREE_STATIC (exp)
5770                 && ((mode == BLKmode
5771                      && ! (target != 0 && safe_from_p (target, exp, 1)))
5772                     || TREE_ADDRESSABLE (exp)
5773                     || (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
5774                         && (move_by_pieces_ninsns
5775                             (TREE_INT_CST_LOW (TYPE_SIZE (type))/BITS_PER_UNIT,
5776                              TYPE_ALIGN (type) / BITS_PER_UNIT)
5777                             > MOVE_RATIO)
5778                         && ! mostly_zeros_p (exp))))
5779                || (modifier == EXPAND_INITIALIZER && TREE_CONSTANT (exp)))
5780         {
5781           rtx constructor = output_constant_def (exp);
5782           if (modifier != EXPAND_CONST_ADDRESS
5783               && modifier != EXPAND_INITIALIZER
5784               && modifier != EXPAND_SUM
5785               && (! memory_address_p (GET_MODE (constructor),
5786                                       XEXP (constructor, 0))
5787                   || (flag_force_addr
5788                       && GET_CODE (XEXP (constructor, 0)) != REG)))
5789             constructor = change_address (constructor, VOIDmode,
5790                                           XEXP (constructor, 0));
5791           return constructor;
5792         }
5793
5794       else
5795         {
5796           /* Handle calls that pass values in multiple non-contiguous
5797              locations.  The Irix 6 ABI has examples of this.  */
5798           if (target == 0 || ! safe_from_p (target, exp, 1)
5799               || GET_CODE (target) == PARALLEL)
5800             {
5801               if (mode != BLKmode && ! TREE_ADDRESSABLE (exp))
5802                 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
5803               else
5804                 target = assign_temp (type, 0, 1, 1);
5805             }
5806
5807           if (TREE_READONLY (exp))
5808             {
5809               if (GET_CODE (target) == MEM)
5810                 target = copy_rtx (target);
5811
5812               RTX_UNCHANGING_P (target) = 1;
5813             }
5814
5815           store_constructor (exp, target, 0);
5816           return target;
5817         }
5818
5819     case INDIRECT_REF:
5820       {
5821         tree exp1 = TREE_OPERAND (exp, 0);
5822         tree exp2;
5823         tree index;
5824         tree string = string_constant (exp1, &index);
5825         int i;
5826  
5827         /* Try to optimize reads from const strings.  */
5828         if (string
5829             && TREE_CODE (string) == STRING_CST
5830             && TREE_CODE (index) == INTEGER_CST
5831             && !TREE_INT_CST_HIGH (index)
5832             && (i = TREE_INT_CST_LOW (index)) < TREE_STRING_LENGTH (string)
5833             && GET_MODE_CLASS (mode) == MODE_INT
5834             && GET_MODE_SIZE (mode) == 1
5835             && modifier != EXPAND_MEMORY_USE_WO)
5836           return GEN_INT (TREE_STRING_POINTER (string)[i]);
5837
5838         op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
5839         op0 = memory_address (mode, op0);
5840
5841         if (flag_check_memory_usage && !AGGREGATE_TYPE_P (TREE_TYPE (exp)))
5842           {
5843             enum memory_use_mode memory_usage;
5844             memory_usage = get_memory_usage_from_modifier (modifier);
5845
5846             if (memory_usage != MEMORY_USE_DONT)
5847               {
5848                 in_check_memory_usage = 1;
5849                 emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
5850                                    op0, ptr_mode,
5851                                    GEN_INT (int_size_in_bytes (type)),
5852                                    TYPE_MODE (sizetype),
5853                                    GEN_INT (memory_usage),
5854                                    TYPE_MODE (integer_type_node));
5855                 in_check_memory_usage = 0;
5856               }
5857           }
5858
5859         temp = gen_rtx_MEM (mode, op0);
5860         /* If address was computed by addition,
5861            mark this as an element of an aggregate.  */
5862         if (TREE_CODE (exp1) == PLUS_EXPR
5863             || (TREE_CODE (exp1) == SAVE_EXPR
5864                 && TREE_CODE (TREE_OPERAND (exp1, 0)) == PLUS_EXPR)
5865             || AGGREGATE_TYPE_P (TREE_TYPE (exp))
5866             || (TREE_CODE (exp1) == ADDR_EXPR
5867                 && (exp2 = TREE_OPERAND (exp1, 0))
5868                 && AGGREGATE_TYPE_P (TREE_TYPE (exp2))))
5869           MEM_IN_STRUCT_P (temp) = 1;
5870
5871         /* If the pointer is actually a REFERENCE_TYPE, this could be pointing
5872            into some aggregate too.  In theory we could fold this into the
5873            previous check and use rtx_addr_varies_p there too.
5874
5875            However, this seems safer.  */
5876         if (!MEM_IN_STRUCT_P (temp)
5877             && (TREE_CODE (TREE_TYPE (exp1)) == REFERENCE_TYPE
5878                 /* This may have been an array reference to the first element
5879                    that was optimized away from being an addition.  */
5880                 || (TREE_CODE (exp1) == NOP_EXPR
5881                     && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp1, 0)))
5882                          == REFERENCE_TYPE)
5883                         || ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp1, 0)))
5884                              == POINTER_TYPE)
5885                             && (AGGREGATE_TYPE_P
5886                                 (TREE_TYPE (TREE_TYPE
5887                                             (TREE_OPERAND (exp1, 0))))))))))
5888           MEM_IN_STRUCT_P (temp) = ! rtx_addr_varies_p (temp);
5889
5890         MEM_VOLATILE_P (temp) = TREE_THIS_VOLATILE (exp) | flag_volatile;
5891         MEM_ALIAS_SET (temp) = get_alias_set (exp);
5892
5893         /* It is incorrect to set RTX_UNCHANGING_P from TREE_READONLY
5894            here, because, in C and C++, the fact that a location is accessed
5895            through a pointer to const does not mean that the value there can
5896            never change.  Languages where it can never change should
5897            also set TREE_STATIC.  */
5898         RTX_UNCHANGING_P (temp) = TREE_READONLY (exp) & TREE_STATIC (exp);
5899         return temp;
5900       }
5901
5902     case ARRAY_REF:
5903       if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) != ARRAY_TYPE)
5904         abort ();
5905
5906       {
5907         tree array = TREE_OPERAND (exp, 0);
5908         tree domain = TYPE_DOMAIN (TREE_TYPE (array));
5909         tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
5910         tree index = TREE_OPERAND (exp, 1);
5911         tree index_type = TREE_TYPE (index);
5912         HOST_WIDE_INT i;
5913
5914         /* Optimize the special-case of a zero lower bound.
5915
5916            We convert the low_bound to sizetype to avoid some problems
5917            with constant folding.  (E.g. suppose the lower bound is 1,
5918            and its mode is QI.  Without the conversion,  (ARRAY
5919            +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
5920            +INDEX), which becomes (ARRAY+255+INDEX).  Oops!)
5921
5922            But sizetype isn't quite right either (especially if
5923            the lowbound is negative).  FIXME */
5924
5925         if (! integer_zerop (low_bound))
5926           index = fold (build (MINUS_EXPR, index_type, index,
5927                                convert (sizetype, low_bound)));
5928
5929         /* Fold an expression like: "foo"[2].
5930            This is not done in fold so it won't happen inside &.
5931            Don't fold if this is for wide characters since it's too
5932            difficult to do correctly and this is a very rare case.  */
5933
5934         if (TREE_CODE (array) == STRING_CST
5935             && TREE_CODE (index) == INTEGER_CST
5936             && !TREE_INT_CST_HIGH (index)
5937             && (i = TREE_INT_CST_LOW (index)) < TREE_STRING_LENGTH (array)
5938             && GET_MODE_CLASS (mode) == MODE_INT
5939             && GET_MODE_SIZE (mode) == 1)
5940           return GEN_INT (TREE_STRING_POINTER (array)[i]);
5941
5942         /* If this is a constant index into a constant array,
5943            just get the value from the array.  Handle both the cases when
5944            we have an explicit constructor and when our operand is a variable
5945            that was declared const.  */
5946
5947         if (TREE_CODE (array) == CONSTRUCTOR && ! TREE_SIDE_EFFECTS (array))
5948           {
5949             if (TREE_CODE (index) == INTEGER_CST
5950                 && TREE_INT_CST_HIGH (index) == 0)
5951               {
5952                 tree elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0));
5953
5954                 i = TREE_INT_CST_LOW (index);
5955                 while (elem && i--)
5956                   elem = TREE_CHAIN (elem);
5957                 if (elem)
5958                   return expand_expr (fold (TREE_VALUE (elem)), target,
5959                                       tmode, ro_modifier);
5960               }
5961           }
5962           
5963         else if (optimize >= 1
5964                  && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
5965                  && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
5966                  && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK)
5967           {
5968             if (TREE_CODE (index) == INTEGER_CST)
5969               {
5970                 tree init = DECL_INITIAL (array);
5971
5972                 i = TREE_INT_CST_LOW (index);
5973                 if (TREE_CODE (init) == CONSTRUCTOR)
5974                   {
5975                     tree elem = CONSTRUCTOR_ELTS (init);
5976
5977                     while (elem
5978                            && !tree_int_cst_equal (TREE_PURPOSE (elem), index))
5979                       elem = TREE_CHAIN (elem);
5980                     if (elem)
5981                       return expand_expr (fold (TREE_VALUE (elem)), target,
5982                                           tmode, ro_modifier);
5983                   }
5984                 else if (TREE_CODE (init) == STRING_CST
5985                          && TREE_INT_CST_HIGH (index) == 0
5986                          && (TREE_INT_CST_LOW (index)
5987                              < TREE_STRING_LENGTH (init)))
5988                   return (GEN_INT
5989                           (TREE_STRING_POINTER
5990                            (init)[TREE_INT_CST_LOW (index)]));
5991               }
5992           }
5993       }
5994
5995       /* ... fall through ... */
5996
5997     case COMPONENT_REF:
5998     case BIT_FIELD_REF:
5999       /* If the operand is a CONSTRUCTOR, we can just extract the
6000          appropriate field if it is present.  Don't do this if we have
6001          already written the data since we want to refer to that copy
6002          and varasm.c assumes that's what we'll do.  */
6003       if (code != ARRAY_REF
6004           && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
6005           && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
6006         {
6007           tree elt;
6008
6009           for (elt = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)); elt;
6010                elt = TREE_CHAIN (elt))
6011             if (TREE_PURPOSE (elt) == TREE_OPERAND (exp, 1)
6012                 /* We can normally use the value of the field in the
6013                    CONSTRUCTOR.  However, if this is a bitfield in
6014                    an integral mode that we can fit in a HOST_WIDE_INT,
6015                    we must mask only the number of bits in the bitfield,
6016                    since this is done implicitly by the constructor.  If
6017                    the bitfield does not meet either of those conditions,
6018                    we can't do this optimization.  */
6019                 && (! DECL_BIT_FIELD (TREE_PURPOSE (elt))
6020                     || ((GET_MODE_CLASS (DECL_MODE (TREE_PURPOSE (elt)))
6021                          == MODE_INT)
6022                         && (GET_MODE_BITSIZE (DECL_MODE (TREE_PURPOSE (elt)))
6023                             <= HOST_BITS_PER_WIDE_INT))))
6024               {
6025                 op0 =  expand_expr (TREE_VALUE (elt), target, tmode, modifier);
6026                 if (DECL_BIT_FIELD (TREE_PURPOSE (elt)))
6027                   {
6028                     int bitsize = DECL_FIELD_SIZE (TREE_PURPOSE (elt));
6029
6030                     if (TREE_UNSIGNED (TREE_TYPE (TREE_PURPOSE (elt))))
6031                       {
6032                         op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
6033                         op0 = expand_and (op0, op1, target);
6034                       }
6035                     else
6036                       {
6037                         enum machine_mode imode
6038                           = TYPE_MODE (TREE_TYPE (TREE_PURPOSE (elt)));
6039                         tree count
6040                           = build_int_2 (GET_MODE_BITSIZE (imode) - bitsize,
6041                                          0);
6042
6043                         op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
6044                                             target, 0);
6045                         op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
6046                                             target, 0);
6047                       }
6048                   }
6049
6050                 return op0;
6051               }
6052         }
6053
6054       {
6055         enum machine_mode mode1;
6056         int bitsize;
6057         int bitpos;
6058         tree offset;
6059         int volatilep = 0;
6060         int alignment;
6061         tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
6062                                         &mode1, &unsignedp, &volatilep,
6063                                         &alignment);
6064
6065         /* If we got back the original object, something is wrong.  Perhaps
6066            we are evaluating an expression too early.  In any event, don't
6067            infinitely recurse.  */
6068         if (tem == exp)
6069           abort ();
6070
6071         /* If TEM's type is a union of variable size, pass TARGET to the inner
6072            computation, since it will need a temporary and TARGET is known
6073            to have to do.  This occurs in unchecked conversion in Ada.  */
6074   
6075         op0 = expand_expr (tem,
6076                            (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
6077                             && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
6078                                 != INTEGER_CST)
6079                             ? target : NULL_RTX),
6080                            VOIDmode,
6081                            modifier == EXPAND_INITIALIZER
6082                            ? modifier : EXPAND_NORMAL);
6083
6084         /* If this is a constant, put it into a register if it is a
6085            legitimate constant and memory if it isn't.  */
6086         if (CONSTANT_P (op0))
6087           {
6088             enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
6089             if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0))
6090               op0 = force_reg (mode, op0);
6091             else
6092               op0 = validize_mem (force_const_mem (mode, op0));
6093           }
6094
6095         if (offset != 0)
6096           {
6097             rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
6098
6099             if (GET_CODE (op0) != MEM)
6100               abort ();
6101
6102             if (GET_MODE (offset_rtx) != ptr_mode)
6103               {
6104 #ifdef POINTERS_EXTEND_UNSIGNED
6105                 offset_rtx = convert_memory_address (ptr_mode, offset_rtx);
6106 #else
6107                 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
6108 #endif
6109               }
6110
6111             if (GET_CODE (op0) == MEM
6112                 && GET_MODE (op0) == BLKmode
6113                 && bitsize
6114                 && (bitpos % bitsize) == 0 
6115                 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
6116                 && (alignment * BITS_PER_UNIT) == GET_MODE_ALIGNMENT (mode1))
6117               {
6118                 rtx temp = change_address (op0, mode1,
6119                                            plus_constant (XEXP (op0, 0),
6120                                                           (bitpos /
6121                                                            BITS_PER_UNIT)));
6122                 if (GET_CODE (XEXP (temp, 0)) == REG)
6123                   op0 = temp;
6124                 else
6125                   op0 = change_address (op0, mode1,
6126                                         force_reg (GET_MODE (XEXP (temp, 0)),
6127                                                    XEXP (temp, 0)));
6128                 bitpos = 0;
6129               }
6130
6131
6132             op0 = change_address (op0, VOIDmode,
6133                                   gen_rtx_PLUS (ptr_mode, XEXP (op0, 0),
6134                                                 force_reg (ptr_mode, offset_rtx)));
6135           }
6136
6137         /* Don't forget about volatility even if this is a bitfield.  */
6138         if (GET_CODE (op0) == MEM && volatilep && ! MEM_VOLATILE_P (op0))
6139           {
6140             op0 = copy_rtx (op0);
6141             MEM_VOLATILE_P (op0) = 1;
6142           }
6143
6144         /* Check the access.  */
6145         if (flag_check_memory_usage && GET_CODE (op0) == MEM)
6146           {
6147             enum memory_use_mode memory_usage;
6148             memory_usage = get_memory_usage_from_modifier (modifier);
6149
6150             if (memory_usage != MEMORY_USE_DONT)
6151               {
6152                 rtx to;
6153                 int size;
6154
6155                 to = plus_constant (XEXP (op0, 0), (bitpos / BITS_PER_UNIT));
6156                 size = (bitpos % BITS_PER_UNIT) + bitsize + BITS_PER_UNIT - 1;
6157
6158                 /* Check the access right of the pointer.  */
6159                 if (size > BITS_PER_UNIT)
6160                   emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
6161                                      to, ptr_mode,
6162                                      GEN_INT (size / BITS_PER_UNIT),
6163                                      TYPE_MODE (sizetype),
6164                                      GEN_INT (memory_usage), 
6165                                      TYPE_MODE (integer_type_node));
6166               }
6167           }
6168
6169         /* In cases where an aligned union has an unaligned object
6170            as a field, we might be extracting a BLKmode value from
6171            an integer-mode (e.g., SImode) object.  Handle this case
6172            by doing the extract into an object as wide as the field
6173            (which we know to be the width of a basic mode), then
6174            storing into memory, and changing the mode to BLKmode.
6175            If we ultimately want the address (EXPAND_CONST_ADDRESS or
6176            EXPAND_INITIALIZER), then we must not copy to a temporary.  */
6177         if (mode1 == VOIDmode
6178             || GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
6179             || (modifier != EXPAND_CONST_ADDRESS
6180                 && modifier != EXPAND_INITIALIZER
6181                 && ((mode1 != BLKmode && ! direct_load[(int) mode1]
6182                      && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6183                      && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6184                     /* If the field isn't aligned enough to fetch as a memref,
6185                        fetch it as a bit field.  */
6186                     || (SLOW_UNALIGNED_ACCESS
6187                         && ((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode))
6188                             || (bitpos % GET_MODE_ALIGNMENT (mode) != 0))))))
6189           {
6190             enum machine_mode ext_mode = mode;
6191
6192             if (ext_mode == BLKmode)
6193               ext_mode = mode_for_size (bitsize, MODE_INT, 1);
6194
6195             if (ext_mode == BLKmode)
6196               {
6197                 /* In this case, BITPOS must start at a byte boundary and
6198                    TARGET, if specified, must be a MEM.  */
6199                 if (GET_CODE (op0) != MEM
6200                     || (target != 0 && GET_CODE (target) != MEM)
6201                     || bitpos % BITS_PER_UNIT != 0)
6202                   abort ();
6203
6204                 op0 = change_address (op0, VOIDmode,
6205                                       plus_constant (XEXP (op0, 0),
6206                                                      bitpos / BITS_PER_UNIT));
6207                 if (target == 0)
6208                   target = assign_temp (type, 0, 1, 1);
6209
6210                 emit_block_move (target, op0,
6211                                  GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6212                                           / BITS_PER_UNIT),
6213                                  1);
6214                 
6215                 return target;
6216               }
6217
6218             op0 = validize_mem (op0);
6219
6220             if (GET_CODE (op0) == MEM && GET_CODE (XEXP (op0, 0)) == REG)
6221               mark_reg_pointer (XEXP (op0, 0), alignment);
6222
6223             op0 = extract_bit_field (op0, bitsize, bitpos,
6224                                      unsignedp, target, ext_mode, ext_mode,
6225                                      alignment,
6226                                      int_size_in_bytes (TREE_TYPE (tem)));
6227
6228             /* If the result is a record type and BITSIZE is narrower than
6229                the mode of OP0, an integral mode, and this is a big endian
6230                machine, we must put the field into the high-order bits.  */
6231             if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
6232                 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
6233                 && bitsize < GET_MODE_BITSIZE (GET_MODE (op0)))
6234               op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
6235                                   size_int (GET_MODE_BITSIZE (GET_MODE (op0))
6236                                             - bitsize),
6237                                   op0, 1);
6238
6239             if (mode == BLKmode)
6240               {
6241                 rtx new = assign_stack_temp (ext_mode,
6242                                              bitsize / BITS_PER_UNIT, 0);
6243
6244                 emit_move_insn (new, op0);
6245                 op0 = copy_rtx (new);
6246                 PUT_MODE (op0, BLKmode);
6247                 MEM_IN_STRUCT_P (op0) = 1;
6248               }
6249
6250             return op0;
6251           }
6252
6253         /* If the result is BLKmode, use that to access the object
6254            now as well.  */
6255         if (mode == BLKmode)
6256           mode1 = BLKmode;
6257
6258         /* Get a reference to just this component.  */
6259         if (modifier == EXPAND_CONST_ADDRESS
6260             || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
6261           op0 = gen_rtx_MEM (mode1, plus_constant (XEXP (op0, 0),
6262                                                    (bitpos / BITS_PER_UNIT)));
6263         else
6264           op0 = change_address (op0, mode1,
6265                                 plus_constant (XEXP (op0, 0),
6266                                                (bitpos / BITS_PER_UNIT)));
6267
6268         if (GET_CODE (op0) == MEM)
6269           MEM_ALIAS_SET (op0) = get_alias_set (exp);
6270
6271         if (GET_CODE (XEXP (op0, 0)) == REG)
6272           mark_reg_pointer (XEXP (op0, 0), alignment);
6273
6274         MEM_IN_STRUCT_P (op0) = 1;
6275         MEM_VOLATILE_P (op0) |= volatilep;
6276         if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
6277             || modifier == EXPAND_CONST_ADDRESS
6278             || modifier == EXPAND_INITIALIZER)
6279           return op0;
6280         else if (target == 0)
6281           target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
6282
6283         convert_move (target, op0, unsignedp);
6284         return target;
6285       }
6286
6287       /* Intended for a reference to a buffer of a file-object in Pascal.
6288          But it's not certain that a special tree code will really be
6289          necessary for these.  INDIRECT_REF might work for them.  */
6290     case BUFFER_REF:
6291       abort ();
6292
6293     case IN_EXPR:
6294       {
6295         /* Pascal set IN expression.
6296
6297            Algorithm:
6298                rlo       = set_low - (set_low%bits_per_word);
6299                the_word  = set [ (index - rlo)/bits_per_word ];
6300                bit_index = index % bits_per_word;
6301                bitmask   = 1 << bit_index;
6302                return !!(the_word & bitmask);  */
6303
6304         tree set = TREE_OPERAND (exp, 0);
6305         tree index = TREE_OPERAND (exp, 1);
6306         int iunsignedp = TREE_UNSIGNED (TREE_TYPE (index));
6307         tree set_type = TREE_TYPE (set);
6308         tree set_low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (set_type));
6309         tree set_high_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (set_type));
6310         rtx index_val = expand_expr (index, 0, VOIDmode, 0);
6311         rtx lo_r = expand_expr (set_low_bound, 0, VOIDmode, 0);
6312         rtx hi_r = expand_expr (set_high_bound, 0, VOIDmode, 0);
6313         rtx setval = expand_expr (set, 0, VOIDmode, 0);
6314         rtx setaddr = XEXP (setval, 0);
6315         enum machine_mode index_mode = TYPE_MODE (TREE_TYPE (index));
6316         rtx rlow;
6317         rtx diff, quo, rem, addr, bit, result;
6318
6319         preexpand_calls (exp);
6320
6321         /* If domain is empty, answer is no.  Likewise if index is constant
6322            and out of bounds.  */
6323         if (((TREE_CODE (set_high_bound) == INTEGER_CST
6324              && TREE_CODE (set_low_bound) == INTEGER_CST
6325              && tree_int_cst_lt (set_high_bound, set_low_bound))
6326              || (TREE_CODE (index) == INTEGER_CST
6327                  && TREE_CODE (set_low_bound) == INTEGER_CST
6328                  && tree_int_cst_lt (index, set_low_bound))
6329              || (TREE_CODE (set_high_bound) == INTEGER_CST
6330                  && TREE_CODE (index) == INTEGER_CST
6331                  && tree_int_cst_lt (set_high_bound, index))))
6332           return const0_rtx;
6333
6334         if (target == 0)
6335           target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
6336
6337         /* If we get here, we have to generate the code for both cases
6338            (in range and out of range).  */
6339
6340         op0 = gen_label_rtx ();
6341         op1 = gen_label_rtx ();
6342
6343         if (! (GET_CODE (index_val) == CONST_INT
6344                && GET_CODE (lo_r) == CONST_INT))
6345           {
6346             emit_cmp_insn (index_val, lo_r, LT, NULL_RTX,
6347                            GET_MODE (index_val), iunsignedp, 0);
6348             emit_jump_insn (gen_blt (op1));
6349           }
6350
6351         if (! (GET_CODE (index_val) == CONST_INT
6352                && GET_CODE (hi_r) == CONST_INT))
6353           {
6354             emit_cmp_insn (index_val, hi_r, GT, NULL_RTX,
6355                            GET_MODE (index_val), iunsignedp, 0);
6356             emit_jump_insn (gen_bgt (op1));
6357           }
6358
6359         /* Calculate the element number of bit zero in the first word
6360            of the set.  */
6361         if (GET_CODE (lo_r) == CONST_INT)
6362           rlow = GEN_INT (INTVAL (lo_r)
6363                           & ~ ((HOST_WIDE_INT) 1 << BITS_PER_UNIT));
6364         else
6365           rlow = expand_binop (index_mode, and_optab, lo_r,
6366                                GEN_INT (~((HOST_WIDE_INT) 1 << BITS_PER_UNIT)),
6367                                NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
6368
6369         diff = expand_binop (index_mode, sub_optab, index_val, rlow,
6370                              NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
6371
6372         quo = expand_divmod (0, TRUNC_DIV_EXPR, index_mode, diff,
6373                              GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
6374         rem = expand_divmod (1, TRUNC_MOD_EXPR, index_mode, index_val,
6375                              GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
6376
6377         addr = memory_address (byte_mode,
6378                                expand_binop (index_mode, add_optab, diff,
6379                                              setaddr, NULL_RTX, iunsignedp,
6380                                              OPTAB_LIB_WIDEN));
6381
6382         /* Extract the bit we want to examine */
6383         bit = expand_shift (RSHIFT_EXPR, byte_mode,
6384                             gen_rtx_MEM (byte_mode, addr),
6385                             make_tree (TREE_TYPE (index), rem),
6386                             NULL_RTX, 1);
6387         result = expand_binop (byte_mode, and_optab, bit, const1_rtx,
6388                                GET_MODE (target) == byte_mode ? target : 0,
6389                                1, OPTAB_LIB_WIDEN);
6390
6391         if (result != target)
6392           convert_move (target, result, 1);
6393
6394         /* Output the code to handle the out-of-range case.  */
6395         emit_jump (op0);
6396         emit_label (op1);
6397         emit_move_insn (target, const0_rtx);
6398         emit_label (op0);
6399         return target;
6400       }
6401
6402     case WITH_CLEANUP_EXPR:
6403       if (RTL_EXPR_RTL (exp) == 0)
6404         {
6405           RTL_EXPR_RTL (exp)
6406             = expand_expr (TREE_OPERAND (exp, 0), target, tmode, ro_modifier);
6407           expand_decl_cleanup (NULL_TREE, TREE_OPERAND (exp, 2));
6408
6409           /* That's it for this cleanup.  */
6410           TREE_OPERAND (exp, 2) = 0;
6411         }
6412       return RTL_EXPR_RTL (exp);
6413
6414     case CLEANUP_POINT_EXPR:
6415       {
6416         extern int temp_slot_level;
6417         /* Start a new binding layer that will keep track of all cleanup
6418            actions to be performed.  */
6419         expand_start_bindings (0);
6420
6421         target_temp_slot_level = temp_slot_level;
6422
6423         op0 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, ro_modifier);
6424         /* If we're going to use this value, load it up now.  */
6425         if (! ignore)
6426           op0 = force_not_mem (op0);
6427         preserve_temp_slots (op0);
6428         expand_end_bindings (NULL_TREE, 0, 0);
6429       }
6430       return op0;
6431
6432     case CALL_EXPR:
6433       /* Check for a built-in function.  */
6434       if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6435           && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6436               == FUNCTION_DECL)
6437           && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
6438         return expand_builtin (exp, target, subtarget, tmode, ignore);
6439
6440       /* If this call was expanded already by preexpand_calls,
6441          just return the result we got.  */
6442       if (CALL_EXPR_RTL (exp) != 0)
6443         return CALL_EXPR_RTL (exp);
6444
6445       return expand_call (exp, target, ignore);
6446
6447     case NON_LVALUE_EXPR:
6448     case NOP_EXPR:
6449     case CONVERT_EXPR:
6450     case REFERENCE_EXPR:
6451       if (TREE_CODE (type) == UNION_TYPE)
6452         {
6453           tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
6454           if (target == 0)
6455             {
6456               if (mode != BLKmode)
6457                 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
6458               else
6459                 target = assign_temp (type, 0, 1, 1);
6460             }
6461
6462           if (GET_CODE (target) == MEM)
6463             /* Store data into beginning of memory target.  */
6464             store_expr (TREE_OPERAND (exp, 0),
6465                         change_address (target, TYPE_MODE (valtype), 0), 0);
6466
6467           else if (GET_CODE (target) == REG)
6468             /* Store this field into a union of the proper type.  */
6469             store_field (target, GET_MODE_BITSIZE (TYPE_MODE (valtype)), 0,
6470                          TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
6471                          VOIDmode, 0, 1,
6472                          int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0))));
6473           else
6474             abort ();
6475
6476           /* Return the entire union.  */
6477           return target;
6478         }
6479
6480       if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
6481         {
6482           op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
6483                              ro_modifier);
6484
6485           /* If the signedness of the conversion differs and OP0 is
6486              a promoted SUBREG, clear that indication since we now
6487              have to do the proper extension.  */
6488           if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
6489               && GET_CODE (op0) == SUBREG)
6490             SUBREG_PROMOTED_VAR_P (op0) = 0;
6491
6492           return op0;
6493         }
6494
6495       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, 0);
6496       if (GET_MODE (op0) == mode)
6497         return op0;
6498
6499       /* If OP0 is a constant, just convert it into the proper mode.  */
6500       if (CONSTANT_P (op0))
6501         return
6502           convert_modes (mode, TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
6503                          op0, TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
6504
6505       if (modifier == EXPAND_INITIALIZER)
6506         return gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
6507
6508       if (target == 0)
6509         return
6510           convert_to_mode (mode, op0,
6511                            TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
6512       else
6513         convert_move (target, op0,
6514                       TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
6515       return target;
6516
6517     case PLUS_EXPR:
6518       /* We come here from MINUS_EXPR when the second operand is a
6519          constant.  */
6520     plus_expr:
6521       this_optab = add_optab;
6522
6523       /* If we are adding a constant, an RTL_EXPR that is sp, fp, or ap, and
6524          something else, make sure we add the register to the constant and
6525          then to the other thing.  This case can occur during strength
6526          reduction and doing it this way will produce better code if the
6527          frame pointer or argument pointer is eliminated.
6528
6529          fold-const.c will ensure that the constant is always in the inner
6530          PLUS_EXPR, so the only case we need to do anything about is if
6531          sp, ap, or fp is our second argument, in which case we must swap
6532          the innermost first argument and our second argument.  */
6533
6534       if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
6535           && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
6536           && TREE_CODE (TREE_OPERAND (exp, 1)) == RTL_EXPR
6537           && (RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
6538               || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
6539               || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
6540         {
6541           tree t = TREE_OPERAND (exp, 1);
6542
6543           TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6544           TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
6545         }
6546
6547       /* If the result is to be ptr_mode and we are adding an integer to
6548          something, we might be forming a constant.  So try to use
6549          plus_constant.  If it produces a sum and we can't accept it,
6550          use force_operand.  This allows P = &ARR[const] to generate
6551          efficient code on machines where a SYMBOL_REF is not a valid
6552          address.
6553
6554          If this is an EXPAND_SUM call, always return the sum.  */
6555       if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
6556           || mode == ptr_mode)
6557         {
6558           if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
6559               && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
6560               && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
6561             {
6562               op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
6563                                  EXPAND_SUM);
6564               op1 = plus_constant (op1, TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)));
6565               if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
6566                 op1 = force_operand (op1, target);
6567               return op1;
6568             }
6569
6570           else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
6571                    && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
6572                    && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
6573             {
6574               op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
6575                                  EXPAND_SUM);
6576               if (! CONSTANT_P (op0))
6577                 {
6578                   op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
6579                                      VOIDmode, modifier);
6580                   /* Don't go to both_summands if modifier
6581                      says it's not right to return a PLUS.  */
6582                   if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
6583                     goto binop2;
6584                   goto both_summands;
6585                 }
6586               op0 = plus_constant (op0, TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)));
6587               if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
6588                 op0 = force_operand (op0, target);
6589               return op0;
6590             }
6591         }
6592
6593       /* No sense saving up arithmetic to be done
6594          if it's all in the wrong mode to form part of an address.
6595          And force_operand won't know whether to sign-extend or
6596          zero-extend.  */
6597       if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
6598           || mode != ptr_mode)
6599         goto binop;
6600
6601       preexpand_calls (exp);
6602       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
6603         subtarget = 0;
6604
6605       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, ro_modifier);
6606       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, ro_modifier);
6607
6608     both_summands:
6609       /* Make sure any term that's a sum with a constant comes last.  */
6610       if (GET_CODE (op0) == PLUS
6611           && CONSTANT_P (XEXP (op0, 1)))
6612         {
6613           temp = op0;
6614           op0 = op1;
6615           op1 = temp;
6616         }
6617       /* If adding to a sum including a constant,
6618          associate it to put the constant outside.  */
6619       if (GET_CODE (op1) == PLUS
6620           && CONSTANT_P (XEXP (op1, 1)))
6621         {
6622           rtx constant_term = const0_rtx;
6623
6624           temp = simplify_binary_operation (PLUS, mode, XEXP (op1, 0), op0);
6625           if (temp != 0)
6626             op0 = temp;
6627           /* Ensure that MULT comes first if there is one.  */
6628           else if (GET_CODE (op0) == MULT)
6629             op0 = gen_rtx_PLUS (mode, op0, XEXP (op1, 0));
6630           else
6631             op0 = gen_rtx_PLUS (mode, XEXP (op1, 0), op0);
6632
6633           /* Let's also eliminate constants from op0 if possible.  */
6634           op0 = eliminate_constant_term (op0, &constant_term);
6635
6636           /* CONSTANT_TERM and XEXP (op1, 1) are known to be constant, so
6637              their sum should be a constant.  Form it into OP1, since the 
6638              result we want will then be OP0 + OP1.  */
6639
6640           temp = simplify_binary_operation (PLUS, mode, constant_term,
6641                                             XEXP (op1, 1));
6642           if (temp != 0)
6643             op1 = temp;
6644           else
6645             op1 = gen_rtx_PLUS (mode, constant_term, XEXP (op1, 1));
6646         }
6647
6648       /* Put a constant term last and put a multiplication first.  */
6649       if (CONSTANT_P (op0) || GET_CODE (op1) == MULT)
6650         temp = op1, op1 = op0, op0 = temp;
6651
6652       temp = simplify_binary_operation (PLUS, mode, op0, op1);
6653       return temp ? temp : gen_rtx_PLUS (mode, op0, op1);
6654
6655     case MINUS_EXPR:
6656       /* For initializers, we are allowed to return a MINUS of two
6657          symbolic constants.  Here we handle all cases when both operands
6658          are constant.  */
6659       /* Handle difference of two symbolic constants,
6660          for the sake of an initializer.  */
6661       if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
6662           && really_constant_p (TREE_OPERAND (exp, 0))
6663           && really_constant_p (TREE_OPERAND (exp, 1)))
6664         {
6665           rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX,
6666                                  VOIDmode, ro_modifier);
6667           rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
6668                                  VOIDmode, ro_modifier);
6669
6670           /* If the last operand is a CONST_INT, use plus_constant of
6671              the negated constant.  Else make the MINUS.  */
6672           if (GET_CODE (op1) == CONST_INT)
6673             return plus_constant (op0, - INTVAL (op1));
6674           else
6675             return gen_rtx_MINUS (mode, op0, op1);
6676         }
6677       /* Convert A - const to A + (-const).  */
6678       if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
6679         {
6680           tree negated = fold (build1 (NEGATE_EXPR, type,
6681                                        TREE_OPERAND (exp, 1)));
6682
6683           /* Deal with the case where we can't negate the constant
6684              in TYPE.  */
6685           if (TREE_UNSIGNED (type) || TREE_OVERFLOW (negated))
6686             {
6687               tree newtype = signed_type (type);
6688               tree newop0 = convert (newtype, TREE_OPERAND (exp, 0));
6689               tree newop1 = convert (newtype, TREE_OPERAND (exp, 1));
6690               tree newneg = fold (build1 (NEGATE_EXPR, newtype, newop1));
6691
6692               if (! TREE_OVERFLOW (newneg))
6693                 return expand_expr (convert (type, 
6694                                              build (PLUS_EXPR, newtype,
6695                                                     newop0, newneg)),
6696                                     target, tmode, ro_modifier);
6697             }
6698           else
6699             {
6700               exp = build (PLUS_EXPR, type, TREE_OPERAND (exp, 0), negated);
6701               goto plus_expr;
6702             }
6703         }
6704       this_optab = sub_optab;
6705       goto binop;
6706
6707     case MULT_EXPR:
6708       preexpand_calls (exp);
6709       /* If first operand is constant, swap them.
6710          Thus the following special case checks need only
6711          check the second operand.  */
6712       if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
6713         {
6714           register tree t1 = TREE_OPERAND (exp, 0);
6715           TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
6716           TREE_OPERAND (exp, 1) = t1;
6717         }
6718
6719       /* Attempt to return something suitable for generating an
6720          indexed address, for machines that support that.  */
6721
6722       if (modifier == EXPAND_SUM && mode == ptr_mode
6723           && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
6724           && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
6725         {
6726           op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
6727                              EXPAND_SUM);
6728
6729           /* Apply distributive law if OP0 is x+c.  */
6730           if (GET_CODE (op0) == PLUS
6731               && GET_CODE (XEXP (op0, 1)) == CONST_INT)
6732             return gen_rtx_PLUS (mode,
6733                                  gen_rtx_MULT (mode, XEXP (op0, 0),
6734                                                GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))),
6735                             GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))
6736                                      * INTVAL (XEXP (op0, 1))));
6737
6738           if (GET_CODE (op0) != REG)
6739             op0 = force_operand (op0, NULL_RTX);
6740           if (GET_CODE (op0) != REG)
6741             op0 = copy_to_mode_reg (mode, op0);
6742
6743           return gen_rtx_MULT (mode, op0,
6744                                GEN_INT (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))));
6745         }
6746
6747       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
6748         subtarget = 0;
6749
6750       /* Check for multiplying things that have been extended
6751          from a narrower type.  If this machine supports multiplying
6752          in that narrower type with a result in the desired type,
6753          do it that way, and avoid the explicit type-conversion.  */
6754       if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
6755           && TREE_CODE (type) == INTEGER_TYPE
6756           && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
6757               < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
6758           && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
6759                && int_fits_type_p (TREE_OPERAND (exp, 1),
6760                                    TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
6761                /* Don't use a widening multiply if a shift will do.  */
6762                && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
6763                     > HOST_BITS_PER_WIDE_INT)
6764                    || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
6765               ||
6766               (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
6767                && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
6768                    ==
6769                    TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
6770                /* If both operands are extended, they must either both
6771                   be zero-extended or both be sign-extended.  */
6772                && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
6773                    ==
6774                    TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
6775         {
6776           enum machine_mode innermode
6777             = TYPE_MODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)));
6778           optab other_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
6779                         ? smul_widen_optab : umul_widen_optab);
6780           this_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
6781                         ? umul_widen_optab : smul_widen_optab);
6782           if (mode == GET_MODE_WIDER_MODE (innermode))
6783             {
6784               if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
6785                 {
6786                   op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
6787                                      NULL_RTX, VOIDmode, 0);
6788                   if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
6789                     op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
6790                                        VOIDmode, 0);
6791                   else
6792                     op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
6793                                        NULL_RTX, VOIDmode, 0);
6794                   goto binop2;
6795                 }
6796               else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
6797                        && innermode == word_mode)
6798                 {
6799                   rtx htem;
6800                   op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
6801                                      NULL_RTX, VOIDmode, 0);
6802                   if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
6803                     op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
6804                                        VOIDmode, 0);
6805                   else
6806                     op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
6807                                        NULL_RTX, VOIDmode, 0);
6808                   temp = expand_binop (mode, other_optab, op0, op1, target,
6809                                        unsignedp, OPTAB_LIB_WIDEN);
6810                   htem = expand_mult_highpart_adjust (innermode,
6811                                                       gen_highpart (innermode, temp),
6812                                                       op0, op1,
6813                                                       gen_highpart (innermode, temp),
6814                                                       unsignedp);
6815                   emit_move_insn (gen_highpart (innermode, temp), htem);
6816                   return temp;
6817                 }
6818             }
6819         }
6820       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6821       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6822       return expand_mult (mode, op0, op1, target, unsignedp);
6823
6824     case TRUNC_DIV_EXPR:
6825     case FLOOR_DIV_EXPR:
6826     case CEIL_DIV_EXPR:
6827     case ROUND_DIV_EXPR:
6828     case EXACT_DIV_EXPR:
6829       preexpand_calls (exp);
6830       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
6831         subtarget = 0;
6832       /* Possible optimization: compute the dividend with EXPAND_SUM
6833          then if the divisor is constant can optimize the case
6834          where some terms of the dividend have coeffs divisible by it.  */
6835       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6836       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6837       return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
6838
6839     case RDIV_EXPR:
6840       this_optab = flodiv_optab;
6841       goto binop;
6842
6843     case TRUNC_MOD_EXPR:
6844     case FLOOR_MOD_EXPR:
6845     case CEIL_MOD_EXPR:
6846     case ROUND_MOD_EXPR:
6847       preexpand_calls (exp);
6848       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
6849         subtarget = 0;
6850       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6851       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6852       return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
6853
6854     case FIX_ROUND_EXPR:
6855     case FIX_FLOOR_EXPR:
6856     case FIX_CEIL_EXPR:
6857       abort ();                 /* Not used for C.  */
6858
6859     case FIX_TRUNC_EXPR:
6860       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
6861       if (target == 0)
6862         target = gen_reg_rtx (mode);
6863       expand_fix (target, op0, unsignedp);
6864       return target;
6865
6866     case FLOAT_EXPR:
6867       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
6868       if (target == 0)
6869         target = gen_reg_rtx (mode);
6870       /* expand_float can't figure out what to do if FROM has VOIDmode.
6871          So give it the correct mode.  With -O, cse will optimize this.  */
6872       if (GET_MODE (op0) == VOIDmode)
6873         op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
6874                                 op0);
6875       expand_float (target, op0,
6876                     TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
6877       return target;
6878
6879     case NEGATE_EXPR:
6880       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6881       temp = expand_unop (mode, neg_optab, op0, target, 0);
6882       if (temp == 0)
6883         abort ();
6884       return temp;
6885
6886     case ABS_EXPR:
6887       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6888
6889       /* Handle complex values specially.  */
6890       if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
6891           || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
6892         return expand_complex_abs (mode, op0, target, unsignedp);
6893
6894       /* Unsigned abs is simply the operand.  Testing here means we don't
6895          risk generating incorrect code below.  */
6896       if (TREE_UNSIGNED (type))
6897         return op0;
6898
6899       return expand_abs (mode, op0, target, unsignedp,
6900                          safe_from_p (target, TREE_OPERAND (exp, 0), 1));
6901
6902     case MAX_EXPR:
6903     case MIN_EXPR:
6904       target = original_target;
6905       if (target == 0 || ! safe_from_p (target, TREE_OPERAND (exp, 1), 1)
6906           || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
6907           || GET_MODE (target) != mode
6908           || (GET_CODE (target) == REG
6909               && REGNO (target) < FIRST_PSEUDO_REGISTER))
6910         target = gen_reg_rtx (mode);
6911       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
6912       op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
6913
6914       /* First try to do it with a special MIN or MAX instruction.
6915          If that does not win, use a conditional jump to select the proper
6916          value.  */
6917       this_optab = (TREE_UNSIGNED (type)
6918                     ? (code == MIN_EXPR ? umin_optab : umax_optab)
6919                     : (code == MIN_EXPR ? smin_optab : smax_optab));
6920
6921       temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
6922                            OPTAB_WIDEN);
6923       if (temp != 0)
6924         return temp;
6925
6926       /* At this point, a MEM target is no longer useful; we will get better
6927          code without it.  */
6928          
6929       if (GET_CODE (target) == MEM)
6930         target = gen_reg_rtx (mode);
6931
6932       if (target != op0)
6933         emit_move_insn (target, op0);
6934
6935       op0 = gen_label_rtx ();
6936
6937       /* If this mode is an integer too wide to compare properly,
6938          compare word by word.  Rely on cse to optimize constant cases.  */
6939       if (GET_MODE_CLASS (mode) == MODE_INT && !can_compare_p (mode))
6940         {
6941           if (code == MAX_EXPR)
6942             do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
6943                                           target, op1, NULL_RTX, op0);
6944           else
6945             do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
6946                                           op1, target, NULL_RTX, op0);
6947           emit_move_insn (target, op1);
6948         }
6949       else
6950         {
6951           if (code == MAX_EXPR)
6952             temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
6953                     ? compare_from_rtx (target, op1, GEU, 1, mode, NULL_RTX, 0)
6954                     : compare_from_rtx (target, op1, GE, 0, mode, NULL_RTX, 0));
6955           else
6956             temp = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)))
6957                     ? compare_from_rtx (target, op1, LEU, 1, mode, NULL_RTX, 0)
6958                     : compare_from_rtx (target, op1, LE, 0, mode, NULL_RTX, 0));
6959           if (temp == const0_rtx)
6960             emit_move_insn (target, op1);
6961           else if (temp != const_true_rtx)
6962             {
6963               if (bcc_gen_fctn[(int) GET_CODE (temp)] != 0)
6964                 emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (temp)]) (op0));
6965               else
6966                 abort ();
6967               emit_move_insn (target, op1);
6968             }
6969         }
6970       emit_label (op0);
6971       return target;
6972
6973     case BIT_NOT_EXPR:
6974       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6975       temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
6976       if (temp == 0)
6977         abort ();
6978       return temp;
6979
6980     case FFS_EXPR:
6981       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
6982       temp = expand_unop (mode, ffs_optab, op0, target, 1);
6983       if (temp == 0)
6984         abort ();
6985       return temp;
6986
6987       /* ??? Can optimize bitwise operations with one arg constant.
6988          Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
6989          and (a bitwise1 b) bitwise2 b (etc)
6990          but that is probably not worth while.  */
6991
6992       /* BIT_AND_EXPR is for bitwise anding.  TRUTH_AND_EXPR is for anding two
6993          boolean values when we want in all cases to compute both of them.  In
6994          general it is fastest to do TRUTH_AND_EXPR by computing both operands
6995          as actual zero-or-1 values and then bitwise anding.  In cases where
6996          there cannot be any side effects, better code would be made by
6997          treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
6998          how to recognize those cases.  */
6999
7000     case TRUTH_AND_EXPR:
7001     case BIT_AND_EXPR:
7002       this_optab = and_optab;
7003       goto binop;
7004
7005     case TRUTH_OR_EXPR:
7006     case BIT_IOR_EXPR:
7007       this_optab = ior_optab;
7008       goto binop;
7009
7010     case TRUTH_XOR_EXPR:
7011     case BIT_XOR_EXPR:
7012       this_optab = xor_optab;
7013       goto binop;
7014
7015     case LSHIFT_EXPR:
7016     case RSHIFT_EXPR:
7017     case LROTATE_EXPR:
7018     case RROTATE_EXPR:
7019       preexpand_calls (exp);
7020       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
7021         subtarget = 0;
7022       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
7023       return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
7024                            unsignedp);
7025
7026       /* Could determine the answer when only additive constants differ.  Also,
7027          the addition of one can be handled by changing the condition.  */
7028     case LT_EXPR:
7029     case LE_EXPR:
7030     case GT_EXPR:
7031     case GE_EXPR:
7032     case EQ_EXPR:
7033     case NE_EXPR:
7034       preexpand_calls (exp);
7035       temp = do_store_flag (exp, target, tmode != VOIDmode ? tmode : mode, 0);
7036       if (temp != 0)
7037         return temp;
7038
7039       /* For foo != 0, load foo, and if it is nonzero load 1 instead.  */
7040       if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
7041           && original_target
7042           && GET_CODE (original_target) == REG
7043           && (GET_MODE (original_target)
7044               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
7045         {
7046           temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
7047                               VOIDmode, 0);
7048
7049           if (temp != original_target)
7050             temp = copy_to_reg (temp);
7051
7052           op1 = gen_label_rtx ();
7053           emit_cmp_insn (temp, const0_rtx, EQ, NULL_RTX,
7054                          GET_MODE (temp), unsignedp, 0);
7055           emit_jump_insn (gen_beq (op1));
7056           emit_move_insn (temp, const1_rtx);
7057           emit_label (op1);
7058           return temp;
7059         }
7060
7061       /* If no set-flag instruction, must generate a conditional
7062          store into a temporary variable.  Drop through
7063          and handle this like && and ||.  */
7064
7065     case TRUTH_ANDIF_EXPR:
7066     case TRUTH_ORIF_EXPR:
7067       if (! ignore
7068           && (target == 0 || ! safe_from_p (target, exp, 1)
7069               /* Make sure we don't have a hard reg (such as function's return
7070                  value) live across basic blocks, if not optimizing.  */
7071               || (!optimize && GET_CODE (target) == REG
7072                   && REGNO (target) < FIRST_PSEUDO_REGISTER)))
7073         target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7074
7075       if (target)
7076         emit_clr_insn (target);
7077
7078       op1 = gen_label_rtx ();
7079       jumpifnot (exp, op1);
7080
7081       if (target)
7082         emit_0_to_1_insn (target);
7083
7084       emit_label (op1);
7085       return ignore ? const0_rtx : target;
7086
7087     case TRUTH_NOT_EXPR:
7088       op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
7089       /* The parser is careful to generate TRUTH_NOT_EXPR
7090          only with operands that are always zero or one.  */
7091       temp = expand_binop (mode, xor_optab, op0, const1_rtx,
7092                            target, 1, OPTAB_LIB_WIDEN);
7093       if (temp == 0)
7094         abort ();
7095       return temp;
7096
7097     case COMPOUND_EXPR:
7098       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
7099       emit_queue ();
7100       return expand_expr (TREE_OPERAND (exp, 1),
7101                           (ignore ? const0_rtx : target),
7102                           VOIDmode, 0);
7103
7104     case COND_EXPR:
7105       /* If we would have a "singleton" (see below) were it not for a
7106          conversion in each arm, bring that conversion back out.  */
7107       if (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
7108           && TREE_CODE (TREE_OPERAND (exp, 2)) == NOP_EXPR
7109           && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0))
7110               == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 2), 0))))
7111         {
7112           tree true = TREE_OPERAND (TREE_OPERAND (exp, 1), 0);
7113           tree false = TREE_OPERAND (TREE_OPERAND (exp, 2), 0);
7114
7115           if ((TREE_CODE_CLASS (TREE_CODE (true)) == '2'
7116                && operand_equal_p (false, TREE_OPERAND (true, 0), 0))
7117               || (TREE_CODE_CLASS (TREE_CODE (false)) == '2'
7118                   && operand_equal_p (true, TREE_OPERAND (false, 0), 0))
7119               || (TREE_CODE_CLASS (TREE_CODE (true)) == '1'
7120                   && operand_equal_p (false, TREE_OPERAND (true, 0), 0))
7121               || (TREE_CODE_CLASS (TREE_CODE (false)) == '1'
7122                   && operand_equal_p (true, TREE_OPERAND (false, 0), 0)))
7123             return expand_expr (build1 (NOP_EXPR, type,
7124                                         build (COND_EXPR, TREE_TYPE (true),
7125                                                TREE_OPERAND (exp, 0),
7126                                                true, false)),
7127                                 target, tmode, modifier);
7128         }
7129
7130       {
7131         /* Note that COND_EXPRs whose type is a structure or union
7132            are required to be constructed to contain assignments of
7133            a temporary variable, so that we can evaluate them here
7134            for side effect only.  If type is void, we must do likewise.  */
7135
7136         /* If an arm of the branch requires a cleanup,
7137            only that cleanup is performed.  */
7138
7139         tree singleton = 0;
7140         tree binary_op = 0, unary_op = 0;
7141
7142         /* If this is (A ? 1 : 0) and A is a condition, just evaluate it and
7143            convert it to our mode, if necessary.  */
7144         if (integer_onep (TREE_OPERAND (exp, 1))
7145             && integer_zerop (TREE_OPERAND (exp, 2))
7146             && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
7147           {
7148             if (ignore)
7149               {
7150                 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
7151                              ro_modifier);
7152                 return const0_rtx;
7153               }
7154
7155             op0 = expand_expr (TREE_OPERAND (exp, 0), target, mode, ro_modifier);
7156             if (GET_MODE (op0) == mode)
7157               return op0;
7158
7159             if (target == 0)
7160               target = gen_reg_rtx (mode);
7161             convert_move (target, op0, unsignedp);
7162             return target;
7163           }
7164
7165         /* Check for X ? A + B : A.  If we have this, we can copy A to the
7166            output and conditionally add B.  Similarly for unary operations.
7167            Don't do this if X has side-effects because those side effects
7168            might affect A or B and the "?" operation is a sequence point in
7169            ANSI.  (operand_equal_p tests for side effects.)  */
7170
7171         if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '2'
7172             && operand_equal_p (TREE_OPERAND (exp, 2),
7173                                 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
7174           singleton = TREE_OPERAND (exp, 2), binary_op = TREE_OPERAND (exp, 1);
7175         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '2'
7176                  && operand_equal_p (TREE_OPERAND (exp, 1),
7177                                      TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
7178           singleton = TREE_OPERAND (exp, 1), binary_op = TREE_OPERAND (exp, 2);
7179         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '1'
7180                  && operand_equal_p (TREE_OPERAND (exp, 2),
7181                                      TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
7182           singleton = TREE_OPERAND (exp, 2), unary_op = TREE_OPERAND (exp, 1);
7183         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '1'
7184                  && operand_equal_p (TREE_OPERAND (exp, 1),
7185                                      TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
7186           singleton = TREE_OPERAND (exp, 1), unary_op = TREE_OPERAND (exp, 2);
7187
7188         /* If we are not to produce a result, we have no target.  Otherwise,
7189            if a target was specified use it; it will not be used as an
7190            intermediate target unless it is safe.  If no target, use a 
7191            temporary.  */
7192
7193         if (ignore)
7194           temp = 0;
7195         else if (original_target
7196                  && (safe_from_p (original_target, TREE_OPERAND (exp, 0), 1)
7197                      || (singleton && GET_CODE (original_target) == REG
7198                          && REGNO (original_target) >= FIRST_PSEUDO_REGISTER
7199                          && original_target == var_rtx (singleton)))
7200                  && GET_MODE (original_target) == mode
7201 #ifdef HAVE_conditional_move
7202                  && (! can_conditionally_move_p (mode)
7203                      || GET_CODE (original_target) == REG
7204                      || TREE_ADDRESSABLE (type))
7205 #endif
7206                  && ! (GET_CODE (original_target) == MEM
7207                        && MEM_VOLATILE_P (original_target)))
7208           temp = original_target;
7209         else if (TREE_ADDRESSABLE (type))
7210           abort ();
7211         else
7212           temp = assign_temp (type, 0, 0, 1);
7213
7214         /* If we had X ? A + C : A, with C a constant power of 2, and we can
7215            do the test of X as a store-flag operation, do this as
7216            A + ((X != 0) << log C).  Similarly for other simple binary
7217            operators.  Only do for C == 1 if BRANCH_COST is low.  */
7218         if (temp && singleton && binary_op
7219             && (TREE_CODE (binary_op) == PLUS_EXPR
7220                 || TREE_CODE (binary_op) == MINUS_EXPR
7221                 || TREE_CODE (binary_op) == BIT_IOR_EXPR
7222                 || TREE_CODE (binary_op) == BIT_XOR_EXPR)
7223             && (BRANCH_COST >= 3 ? integer_pow2p (TREE_OPERAND (binary_op, 1))
7224                 : integer_onep (TREE_OPERAND (binary_op, 1)))
7225             && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
7226           {
7227             rtx result;
7228             optab boptab = (TREE_CODE (binary_op) == PLUS_EXPR ? add_optab
7229                             : TREE_CODE (binary_op) == MINUS_EXPR ? sub_optab
7230                             : TREE_CODE (binary_op) == BIT_IOR_EXPR ? ior_optab
7231                             : xor_optab);
7232
7233             /* If we had X ? A : A + 1, do this as A + (X == 0).
7234
7235                We have to invert the truth value here and then put it
7236                back later if do_store_flag fails.  We cannot simply copy
7237                TREE_OPERAND (exp, 0) to another variable and modify that
7238                because invert_truthvalue can modify the tree pointed to
7239                by its argument.  */
7240             if (singleton == TREE_OPERAND (exp, 1))
7241               TREE_OPERAND (exp, 0)
7242                 = invert_truthvalue (TREE_OPERAND (exp, 0));
7243
7244             result = do_store_flag (TREE_OPERAND (exp, 0),
7245                                     (safe_from_p (temp, singleton, 1)
7246                                      ? temp : NULL_RTX),
7247                                     mode, BRANCH_COST <= 1);
7248
7249             if (result != 0 && ! integer_onep (TREE_OPERAND (binary_op, 1)))
7250               result = expand_shift (LSHIFT_EXPR, mode, result,
7251                                      build_int_2 (tree_log2
7252                                                   (TREE_OPERAND
7253                                                    (binary_op, 1)),
7254                                                   0),
7255                                      (safe_from_p (temp, singleton, 1)
7256                                       ? temp : NULL_RTX), 0);
7257
7258             if (result)
7259               {
7260                 op1 = expand_expr (singleton, NULL_RTX, VOIDmode, 0);
7261                 return expand_binop (mode, boptab, op1, result, temp,
7262                                      unsignedp, OPTAB_LIB_WIDEN);
7263               }
7264             else if (singleton == TREE_OPERAND (exp, 1))
7265               TREE_OPERAND (exp, 0)
7266                 = invert_truthvalue (TREE_OPERAND (exp, 0));
7267           }
7268             
7269         do_pending_stack_adjust ();
7270         NO_DEFER_POP;
7271         op0 = gen_label_rtx ();
7272
7273         if (singleton && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0)))
7274           {
7275             if (temp != 0)
7276               {
7277                 /* If the target conflicts with the other operand of the
7278                    binary op, we can't use it.  Also, we can't use the target
7279                    if it is a hard register, because evaluating the condition
7280                    might clobber it.  */
7281                 if ((binary_op
7282                      && ! safe_from_p (temp, TREE_OPERAND (binary_op, 1), 1))
7283                     || (GET_CODE (temp) == REG
7284                         && REGNO (temp) < FIRST_PSEUDO_REGISTER))
7285                   temp = gen_reg_rtx (mode);
7286                 store_expr (singleton, temp, 0);
7287               }
7288             else
7289               expand_expr (singleton,
7290                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
7291             if (singleton == TREE_OPERAND (exp, 1))
7292               jumpif (TREE_OPERAND (exp, 0), op0);
7293             else
7294               jumpifnot (TREE_OPERAND (exp, 0), op0);
7295
7296             start_cleanup_deferral ();
7297             if (binary_op && temp == 0)
7298               /* Just touch the other operand.  */
7299               expand_expr (TREE_OPERAND (binary_op, 1),
7300                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
7301             else if (binary_op)
7302               store_expr (build (TREE_CODE (binary_op), type,
7303                                  make_tree (type, temp),
7304                                  TREE_OPERAND (binary_op, 1)),
7305                           temp, 0);
7306             else
7307               store_expr (build1 (TREE_CODE (unary_op), type,
7308                                   make_tree (type, temp)),
7309                           temp, 0);
7310             op1 = op0;
7311           }
7312         /* Check for A op 0 ? A : FOO and A op 0 ? FOO : A where OP is any
7313            comparison operator.  If we have one of these cases, set the
7314            output to A, branch on A (cse will merge these two references),
7315            then set the output to FOO.  */
7316         else if (temp
7317                  && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
7318                  && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
7319                  && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
7320                                      TREE_OPERAND (exp, 1), 0)
7321                  && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
7322                      || TREE_CODE (TREE_OPERAND (exp, 1)) == SAVE_EXPR)
7323                  && safe_from_p (temp, TREE_OPERAND (exp, 2), 1))
7324           {
7325             if (GET_CODE (temp) == REG && REGNO (temp) < FIRST_PSEUDO_REGISTER)
7326               temp = gen_reg_rtx (mode);
7327             store_expr (TREE_OPERAND (exp, 1), temp, 0);
7328             jumpif (TREE_OPERAND (exp, 0), op0);
7329
7330             start_cleanup_deferral ();
7331             store_expr (TREE_OPERAND (exp, 2), temp, 0);
7332             op1 = op0;
7333           }
7334         else if (temp
7335                  && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
7336                  && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
7337                  && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
7338                                      TREE_OPERAND (exp, 2), 0)
7339                  && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
7340                      || TREE_CODE (TREE_OPERAND (exp, 2)) == SAVE_EXPR)
7341                  && safe_from_p (temp, TREE_OPERAND (exp, 1), 1))
7342           {
7343             if (GET_CODE (temp) == REG && REGNO (temp) < FIRST_PSEUDO_REGISTER)
7344               temp = gen_reg_rtx (mode);
7345             store_expr (TREE_OPERAND (exp, 2), temp, 0);
7346             jumpifnot (TREE_OPERAND (exp, 0), op0);
7347
7348             start_cleanup_deferral ();
7349             store_expr (TREE_OPERAND (exp, 1), temp, 0);
7350             op1 = op0;
7351           }
7352         else
7353           {
7354             op1 = gen_label_rtx ();
7355             jumpifnot (TREE_OPERAND (exp, 0), op0);
7356
7357             start_cleanup_deferral ();
7358             if (temp != 0)
7359               store_expr (TREE_OPERAND (exp, 1), temp, 0);
7360             else
7361               expand_expr (TREE_OPERAND (exp, 1),
7362                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
7363             end_cleanup_deferral ();
7364             emit_queue ();
7365             emit_jump_insn (gen_jump (op1));
7366             emit_barrier ();
7367             emit_label (op0);
7368             start_cleanup_deferral ();
7369             if (temp != 0)
7370               store_expr (TREE_OPERAND (exp, 2), temp, 0);
7371             else
7372               expand_expr (TREE_OPERAND (exp, 2),
7373                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
7374           }
7375
7376         end_cleanup_deferral ();
7377
7378         emit_queue ();
7379         emit_label (op1);
7380         OK_DEFER_POP;
7381
7382         return temp;
7383       }
7384
7385     case TARGET_EXPR:
7386       {
7387         /* Something needs to be initialized, but we didn't know
7388            where that thing was when building the tree.  For example,
7389            it could be the return value of a function, or a parameter
7390            to a function which lays down in the stack, or a temporary
7391            variable which must be passed by reference.
7392
7393            We guarantee that the expression will either be constructed
7394            or copied into our original target.  */
7395
7396         tree slot = TREE_OPERAND (exp, 0);
7397         tree cleanups = NULL_TREE;
7398         tree exp1;
7399
7400         if (TREE_CODE (slot) != VAR_DECL)
7401           abort ();
7402
7403         if (! ignore)
7404           target = original_target;
7405
7406         if (target == 0)
7407           {
7408             if (DECL_RTL (slot) != 0)
7409               {
7410                 target = DECL_RTL (slot);
7411                 /* If we have already expanded the slot, so don't do
7412                    it again.  (mrs)  */
7413                 if (TREE_OPERAND (exp, 1) == NULL_TREE)
7414                   return target;
7415               }
7416             else
7417               {
7418                 target = assign_temp (type, 2, 0, 1);
7419                 /* All temp slots at this level must not conflict.  */
7420                 preserve_temp_slots (target);
7421                 DECL_RTL (slot) = target;
7422                 if (TREE_ADDRESSABLE (slot))
7423                   {
7424                     TREE_ADDRESSABLE (slot) = 0;
7425                     mark_addressable (slot);
7426                   }
7427
7428                 /* Since SLOT is not known to the called function
7429                    to belong to its stack frame, we must build an explicit
7430                    cleanup.  This case occurs when we must build up a reference
7431                    to pass the reference as an argument.  In this case,
7432                    it is very likely that such a reference need not be
7433                    built here.  */
7434
7435                 if (TREE_OPERAND (exp, 2) == 0)
7436                   TREE_OPERAND (exp, 2) = maybe_build_cleanup (slot);
7437                 cleanups = TREE_OPERAND (exp, 2);
7438               }
7439           }
7440         else
7441           {
7442             /* This case does occur, when expanding a parameter which
7443                needs to be constructed on the stack.  The target
7444                is the actual stack address that we want to initialize.
7445                The function we call will perform the cleanup in this case.  */
7446
7447             /* If we have already assigned it space, use that space,
7448                not target that we were passed in, as our target
7449                parameter is only a hint.  */
7450             if (DECL_RTL (slot) != 0)
7451               {
7452                 target = DECL_RTL (slot);
7453                 /* If we have already expanded the slot, so don't do
7454                    it again.  (mrs)  */
7455                 if (TREE_OPERAND (exp, 1) == NULL_TREE)
7456                   return target;
7457               }
7458             else
7459               {
7460                 DECL_RTL (slot) = target;
7461                 /* If we must have an addressable slot, then make sure that
7462                    the RTL that we just stored in slot is OK.  */
7463                 if (TREE_ADDRESSABLE (slot))
7464                   {
7465                     TREE_ADDRESSABLE (slot) = 0;
7466                     mark_addressable (slot);
7467                   }
7468               }
7469           }
7470
7471         exp1 = TREE_OPERAND (exp, 3) = TREE_OPERAND (exp, 1);
7472         /* Mark it as expanded.  */
7473         TREE_OPERAND (exp, 1) = NULL_TREE;
7474
7475         TREE_USED (slot) = 1;
7476         store_expr (exp1, target, 0);
7477
7478         expand_decl_cleanup (NULL_TREE, cleanups);
7479         
7480         return target;
7481       }
7482
7483     case INIT_EXPR:
7484       {
7485         tree lhs = TREE_OPERAND (exp, 0);
7486         tree rhs = TREE_OPERAND (exp, 1);
7487         tree noncopied_parts = 0;
7488         tree lhs_type = TREE_TYPE (lhs);
7489
7490         temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
7491         if (TYPE_NONCOPIED_PARTS (lhs_type) != 0 && !fixed_type_p (rhs))
7492           noncopied_parts = init_noncopied_parts (stabilize_reference (lhs),
7493                                                   TYPE_NONCOPIED_PARTS (lhs_type));
7494         while (noncopied_parts != 0)
7495           {
7496             expand_assignment (TREE_VALUE (noncopied_parts),
7497                                TREE_PURPOSE (noncopied_parts), 0, 0);
7498             noncopied_parts = TREE_CHAIN (noncopied_parts);
7499           }
7500         return temp;
7501       }
7502
7503     case MODIFY_EXPR:
7504       {
7505         /* If lhs is complex, expand calls in rhs before computing it.
7506            That's so we don't compute a pointer and save it over a call.
7507            If lhs is simple, compute it first so we can give it as a
7508            target if the rhs is just a call.  This avoids an extra temp and copy
7509            and that prevents a partial-subsumption which makes bad code.
7510            Actually we could treat component_ref's of vars like vars.  */
7511
7512         tree lhs = TREE_OPERAND (exp, 0);
7513         tree rhs = TREE_OPERAND (exp, 1);
7514         tree noncopied_parts = 0;
7515         tree lhs_type = TREE_TYPE (lhs);
7516
7517         temp = 0;
7518
7519         if (TREE_CODE (lhs) != VAR_DECL
7520             && TREE_CODE (lhs) != RESULT_DECL
7521             && TREE_CODE (lhs) != PARM_DECL
7522             && ! (TREE_CODE (lhs) == INDIRECT_REF
7523                   && TYPE_READONLY (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
7524           preexpand_calls (exp);
7525
7526         /* Check for |= or &= of a bitfield of size one into another bitfield
7527            of size 1.  In this case, (unless we need the result of the
7528            assignment) we can do this more efficiently with a
7529            test followed by an assignment, if necessary.
7530
7531            ??? At this point, we can't get a BIT_FIELD_REF here.  But if
7532            things change so we do, this code should be enhanced to
7533            support it.  */
7534         if (ignore
7535             && TREE_CODE (lhs) == COMPONENT_REF
7536             && (TREE_CODE (rhs) == BIT_IOR_EXPR
7537                 || TREE_CODE (rhs) == BIT_AND_EXPR)
7538             && TREE_OPERAND (rhs, 0) == lhs
7539             && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
7540             && TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (lhs, 1))) == 1
7541             && TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))) == 1)
7542           {
7543             rtx label = gen_label_rtx ();
7544
7545             do_jump (TREE_OPERAND (rhs, 1),
7546                      TREE_CODE (rhs) == BIT_IOR_EXPR ? label : 0,
7547                      TREE_CODE (rhs) == BIT_AND_EXPR ? label : 0);
7548             expand_assignment (lhs, convert (TREE_TYPE (rhs),
7549                                              (TREE_CODE (rhs) == BIT_IOR_EXPR
7550                                               ? integer_one_node
7551                                               : integer_zero_node)),
7552                                0, 0);
7553             do_pending_stack_adjust ();
7554             emit_label (label);
7555             return const0_rtx;
7556           }
7557
7558         if (TYPE_NONCOPIED_PARTS (lhs_type) != 0
7559             && ! (fixed_type_p (lhs) && fixed_type_p (rhs)))
7560           noncopied_parts = save_noncopied_parts (stabilize_reference (lhs),
7561                                                   TYPE_NONCOPIED_PARTS (lhs_type));
7562
7563         temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
7564         while (noncopied_parts != 0)
7565           {
7566             expand_assignment (TREE_PURPOSE (noncopied_parts),
7567                                TREE_VALUE (noncopied_parts), 0, 0);
7568             noncopied_parts = TREE_CHAIN (noncopied_parts);
7569           }
7570         return temp;
7571       }
7572
7573     case RETURN_EXPR:
7574       if (!TREE_OPERAND (exp, 0))
7575         expand_null_return ();
7576       else
7577         expand_return (TREE_OPERAND (exp, 0));
7578       return const0_rtx;
7579
7580     case PREINCREMENT_EXPR:
7581     case PREDECREMENT_EXPR:
7582       return expand_increment (exp, 0, ignore);
7583
7584     case POSTINCREMENT_EXPR:
7585     case POSTDECREMENT_EXPR:
7586       /* Faster to treat as pre-increment if result is not used.  */
7587       return expand_increment (exp, ! ignore, ignore);
7588
7589     case ADDR_EXPR:
7590       /* If nonzero, TEMP will be set to the address of something that might
7591          be a MEM corresponding to a stack slot.  */
7592       temp = 0;
7593
7594       /* Are we taking the address of a nested function?  */
7595       if (TREE_CODE (TREE_OPERAND (exp, 0)) == FUNCTION_DECL
7596           && decl_function_context (TREE_OPERAND (exp, 0)) != 0
7597           && ! DECL_NO_STATIC_CHAIN (TREE_OPERAND (exp, 0))
7598           && ! TREE_STATIC (exp))
7599         {
7600           op0 = trampoline_address (TREE_OPERAND (exp, 0));
7601           op0 = force_operand (op0, target);
7602         }
7603       /* If we are taking the address of something erroneous, just
7604          return a zero.  */
7605       else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
7606         return const0_rtx;
7607       else
7608         {
7609           /* We make sure to pass const0_rtx down if we came in with
7610              ignore set, to avoid doing the cleanups twice for something.  */
7611           op0 = expand_expr (TREE_OPERAND (exp, 0),
7612                              ignore ? const0_rtx : NULL_RTX, VOIDmode,
7613                              (modifier == EXPAND_INITIALIZER
7614                               ? modifier : EXPAND_CONST_ADDRESS));
7615
7616           /* If we are going to ignore the result, OP0 will have been set
7617              to const0_rtx, so just return it.  Don't get confused and
7618              think we are taking the address of the constant.  */
7619           if (ignore)
7620             return op0;
7621
7622           op0 = protect_from_queue (op0, 0);
7623
7624           /* We would like the object in memory.  If it is a constant,
7625              we can have it be statically allocated into memory.  For
7626              a non-constant (REG, SUBREG or CONCAT), we need to allocate some
7627              memory and store the value into it.  */
7628
7629           if (CONSTANT_P (op0))
7630             op0 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
7631                                    op0);
7632           else if (GET_CODE (op0) == MEM)
7633             {
7634               mark_temp_addr_taken (op0);
7635               temp = XEXP (op0, 0);
7636             }
7637
7638           else if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
7639                    || GET_CODE (op0) == CONCAT || GET_CODE (op0) == ADDRESSOF)
7640             {
7641               /* If this object is in a register, it must be not
7642                  be BLKmode.  */
7643               tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7644               rtx memloc = assign_temp (inner_type, 1, 1, 1);
7645
7646               mark_temp_addr_taken (memloc);
7647               emit_move_insn (memloc, op0);
7648               op0 = memloc;
7649             }
7650
7651           if (GET_CODE (op0) != MEM)
7652             abort ();
7653   
7654           if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7655             {
7656               temp = XEXP (op0, 0);
7657 #ifdef POINTERS_EXTEND_UNSIGNED
7658               if (GET_MODE (temp) == Pmode && GET_MODE (temp) != mode
7659                   && mode == ptr_mode)
7660                 temp = convert_memory_address (ptr_mode, temp);
7661 #endif
7662               return temp;
7663             }
7664
7665           op0 = force_operand (XEXP (op0, 0), target);
7666         }
7667
7668       if (flag_force_addr && GET_CODE (op0) != REG)
7669         op0 = force_reg (Pmode, op0);
7670
7671       if (GET_CODE (op0) == REG
7672           && ! REG_USERVAR_P (op0))
7673         mark_reg_pointer (op0, TYPE_ALIGN (TREE_TYPE (type)) / BITS_PER_UNIT);
7674
7675       /* If we might have had a temp slot, add an equivalent address
7676          for it.  */
7677       if (temp != 0)
7678         update_temp_slot_address (temp, op0);
7679
7680 #ifdef POINTERS_EXTEND_UNSIGNED
7681       if (GET_MODE (op0) == Pmode && GET_MODE (op0) != mode
7682           && mode == ptr_mode)
7683         op0 = convert_memory_address (ptr_mode, op0);
7684 #endif
7685
7686       return op0;
7687
7688     case ENTRY_VALUE_EXPR:
7689       abort ();
7690
7691     /* COMPLEX type for Extended Pascal & Fortran  */
7692     case COMPLEX_EXPR:
7693       {
7694         enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
7695         rtx insns;
7696
7697         /* Get the rtx code of the operands.  */
7698         op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
7699         op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
7700
7701         if (! target)
7702           target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
7703
7704         start_sequence ();
7705
7706         /* Move the real (op0) and imaginary (op1) parts to their location.  */
7707         emit_move_insn (gen_realpart (mode, target), op0);
7708         emit_move_insn (gen_imagpart (mode, target), op1);
7709
7710         insns = get_insns ();
7711         end_sequence ();
7712
7713         /* Complex construction should appear as a single unit.  */
7714         /* If TARGET is a CONCAT, we got insns like RD = RS, ID = IS,
7715            each with a separate pseudo as destination.
7716            It's not correct for flow to treat them as a unit.  */
7717         if (GET_CODE (target) != CONCAT)
7718           emit_no_conflict_block (insns, target, op0, op1, NULL_RTX);
7719         else
7720           emit_insns (insns);
7721
7722         return target;
7723       }
7724
7725     case REALPART_EXPR:
7726       op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
7727       return gen_realpart (mode, op0);
7728       
7729     case IMAGPART_EXPR:
7730       op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
7731       return gen_imagpart (mode, op0);
7732
7733     case CONJ_EXPR:
7734       {
7735         enum machine_mode partmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
7736         rtx imag_t;
7737         rtx insns;
7738         
7739         op0  = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
7740
7741         if (! target)
7742           target = gen_reg_rtx (mode);
7743                                                                     
7744         start_sequence ();
7745
7746         /* Store the realpart and the negated imagpart to target.  */
7747         emit_move_insn (gen_realpart (partmode, target),
7748                         gen_realpart (partmode, op0));
7749
7750         imag_t = gen_imagpart (partmode, target);
7751         temp = expand_unop (partmode, neg_optab,
7752                                gen_imagpart (partmode, op0), imag_t, 0);
7753         if (temp != imag_t)
7754           emit_move_insn (imag_t, temp);
7755
7756         insns = get_insns ();
7757         end_sequence ();
7758
7759         /* Conjugate should appear as a single unit 
7760            If TARGET is a CONCAT, we got insns like RD = RS, ID = - IS,
7761            each with a separate pseudo as destination.
7762            It's not correct for flow to treat them as a unit.  */
7763         if (GET_CODE (target) != CONCAT)
7764           emit_no_conflict_block (insns, target, op0, NULL_RTX, NULL_RTX);
7765         else
7766           emit_insns (insns);
7767
7768         return target;
7769       }
7770
7771     case TRY_CATCH_EXPR:
7772       {
7773         tree handler = TREE_OPERAND (exp, 1);
7774
7775         expand_eh_region_start ();
7776
7777         op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
7778
7779         expand_eh_region_end (handler);
7780
7781         return op0;
7782       }
7783
7784     case POPDCC_EXPR:
7785       {
7786         rtx dcc = get_dynamic_cleanup_chain ();
7787         emit_move_insn (dcc, validize_mem (gen_rtx_MEM (Pmode, dcc)));
7788         return const0_rtx;
7789       }
7790
7791     case POPDHC_EXPR:
7792       {
7793         rtx dhc = get_dynamic_handler_chain ();
7794         emit_move_insn (dhc, validize_mem (gen_rtx_MEM (Pmode, dhc)));
7795         return const0_rtx;
7796       }
7797
7798     case ERROR_MARK:
7799       op0 = CONST0_RTX (tmode);
7800       if (op0 != 0)
7801         return op0;
7802       return const0_rtx;
7803
7804     default:
7805       return (*lang_expand_expr) (exp, original_target, tmode, modifier);
7806     }
7807
7808   /* Here to do an ordinary binary operator, generating an instruction
7809      from the optab already placed in `this_optab'.  */
7810  binop:
7811   preexpand_calls (exp);
7812   if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
7813     subtarget = 0;
7814   op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
7815   op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
7816  binop2:
7817   temp = expand_binop (mode, this_optab, op0, op1, target,
7818                        unsignedp, OPTAB_LIB_WIDEN);
7819   if (temp == 0)
7820     abort ();
7821   return temp;
7822 }
7823
7824
7825 \f
7826 /* Return the alignment in bits of EXP, a pointer valued expression.
7827    But don't return more than MAX_ALIGN no matter what.
7828    The alignment returned is, by default, the alignment of the thing that
7829    EXP points to (if it is not a POINTER_TYPE, 0 is returned).
7830
7831    Otherwise, look at the expression to see if we can do better, i.e., if the
7832    expression is actually pointing at an object whose alignment is tighter.  */
7833
7834 static int
7835 get_pointer_alignment (exp, max_align)
7836      tree exp;
7837      unsigned max_align;
7838 {
7839   unsigned align, inner;
7840
7841   if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
7842     return 0;
7843
7844   align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
7845   align = MIN (align, max_align);
7846
7847   while (1)
7848     {
7849       switch (TREE_CODE (exp))
7850         {
7851         case NOP_EXPR:
7852         case CONVERT_EXPR:
7853         case NON_LVALUE_EXPR:
7854           exp = TREE_OPERAND (exp, 0);
7855           if (TREE_CODE (TREE_TYPE (exp)) != POINTER_TYPE)
7856             return align;
7857           inner = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp)));
7858           align = MIN (inner, max_align);
7859           break;
7860
7861         case PLUS_EXPR:
7862           /* If sum of pointer + int, restrict our maximum alignment to that
7863              imposed by the integer.  If not, we can't do any better than
7864              ALIGN.  */
7865           if (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST)
7866             return align;
7867
7868           while (((TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)) * BITS_PER_UNIT)
7869                   & (max_align - 1))
7870                  != 0)
7871             max_align >>= 1;
7872
7873           exp = TREE_OPERAND (exp, 0);
7874           break;
7875
7876         case ADDR_EXPR:
7877           /* See what we are pointing at and look at its alignment.  */
7878           exp = TREE_OPERAND (exp, 0);
7879           if (TREE_CODE (exp) == FUNCTION_DECL)
7880             align = FUNCTION_BOUNDARY;
7881           else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
7882             align = DECL_ALIGN (exp);
7883 #ifdef CONSTANT_ALIGNMENT
7884           else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c')
7885             align = CONSTANT_ALIGNMENT (exp, align);
7886 #endif
7887           return MIN (align, max_align);
7888
7889         default:
7890           return align;
7891         }
7892     }
7893 }
7894 \f
7895 /* Return the tree node and offset if a given argument corresponds to
7896    a string constant.  */
7897
7898 static tree
7899 string_constant (arg, ptr_offset)
7900      tree arg;
7901      tree *ptr_offset;
7902 {
7903   STRIP_NOPS (arg);
7904
7905   if (TREE_CODE (arg) == ADDR_EXPR
7906       && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
7907     {
7908       *ptr_offset = integer_zero_node;
7909       return TREE_OPERAND (arg, 0);
7910     }
7911   else if (TREE_CODE (arg) == PLUS_EXPR)
7912     {
7913       tree arg0 = TREE_OPERAND (arg, 0);
7914       tree arg1 = TREE_OPERAND (arg, 1);
7915
7916       STRIP_NOPS (arg0);
7917       STRIP_NOPS (arg1);
7918
7919       if (TREE_CODE (arg0) == ADDR_EXPR
7920           && TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST)
7921         {
7922           *ptr_offset = arg1;
7923           return TREE_OPERAND (arg0, 0);
7924         }
7925       else if (TREE_CODE (arg1) == ADDR_EXPR
7926                && TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST)
7927         {
7928           *ptr_offset = arg0;
7929           return TREE_OPERAND (arg1, 0);
7930         }
7931     }
7932
7933   return 0;
7934 }
7935
7936 /* Compute the length of a C string.  TREE_STRING_LENGTH is not the right
7937    way, because it could contain a zero byte in the middle.
7938    TREE_STRING_LENGTH is the size of the character array, not the string.
7939
7940    Unfortunately, string_constant can't access the values of const char
7941    arrays with initializers, so neither can we do so here.  */
7942
7943 static tree
7944 c_strlen (src)
7945      tree src;
7946 {
7947   tree offset_node;
7948   int offset, max;
7949   char *ptr;
7950
7951   src = string_constant (src, &offset_node);
7952   if (src == 0)
7953     return 0;
7954   max = TREE_STRING_LENGTH (src);
7955   ptr = TREE_STRING_POINTER (src);
7956   if (offset_node && TREE_CODE (offset_node) != INTEGER_CST)
7957     {
7958       /* If the string has an internal zero byte (e.g., "foo\0bar"), we can't
7959          compute the offset to the following null if we don't know where to
7960          start searching for it.  */
7961       int i;
7962       for (i = 0; i < max; i++)
7963         if (ptr[i] == 0)
7964           return 0;
7965       /* We don't know the starting offset, but we do know that the string
7966          has no internal zero bytes.  We can assume that the offset falls
7967          within the bounds of the string; otherwise, the programmer deserves
7968          what he gets.  Subtract the offset from the length of the string,
7969          and return that.  */
7970       /* This would perhaps not be valid if we were dealing with named
7971          arrays in addition to literal string constants.  */
7972       return size_binop (MINUS_EXPR, size_int (max), offset_node);
7973     }
7974
7975   /* We have a known offset into the string.  Start searching there for
7976      a null character.  */
7977   if (offset_node == 0)
7978     offset = 0;
7979   else
7980     {
7981       /* Did we get a long long offset?  If so, punt.  */
7982       if (TREE_INT_CST_HIGH (offset_node) != 0)
7983         return 0;
7984       offset = TREE_INT_CST_LOW (offset_node);
7985     }
7986   /* If the offset is known to be out of bounds, warn, and call strlen at
7987      runtime.  */
7988   if (offset < 0 || offset > max)
7989     {
7990       warning ("offset outside bounds of constant string");
7991       return 0;
7992     }
7993   /* Use strlen to search for the first zero byte.  Since any strings
7994      constructed with build_string will have nulls appended, we win even
7995      if we get handed something like (char[4])"abcd".
7996
7997      Since OFFSET is our starting index into the string, no further
7998      calculation is needed.  */
7999   return size_int (strlen (ptr + offset));
8000 }
8001
8002 rtx
8003 expand_builtin_return_addr (fndecl_code, count, tem)
8004      enum built_in_function fndecl_code;
8005      int count;
8006      rtx tem;
8007 {
8008   int i;
8009
8010   /* Some machines need special handling before we can access
8011      arbitrary frames.  For example, on the sparc, we must first flush
8012      all register windows to the stack.  */
8013 #ifdef SETUP_FRAME_ADDRESSES
8014   if (count > 0)
8015     SETUP_FRAME_ADDRESSES ();
8016 #endif
8017
8018   /* On the sparc, the return address is not in the frame, it is in a
8019      register.  There is no way to access it off of the current frame
8020      pointer, but it can be accessed off the previous frame pointer by
8021      reading the value from the register window save area.  */
8022 #ifdef RETURN_ADDR_IN_PREVIOUS_FRAME
8023   if (fndecl_code == BUILT_IN_RETURN_ADDRESS)
8024     count--;
8025 #endif
8026
8027   /* Scan back COUNT frames to the specified frame.  */
8028   for (i = 0; i < count; i++)
8029     {
8030       /* Assume the dynamic chain pointer is in the word that the
8031          frame address points to, unless otherwise specified.  */
8032 #ifdef DYNAMIC_CHAIN_ADDRESS
8033       tem = DYNAMIC_CHAIN_ADDRESS (tem);
8034 #endif
8035       tem = memory_address (Pmode, tem);
8036       tem = copy_to_reg (gen_rtx_MEM (Pmode, tem));
8037     }
8038
8039   /* For __builtin_frame_address, return what we've got.  */
8040   if (fndecl_code == BUILT_IN_FRAME_ADDRESS)
8041     return tem;
8042
8043   /* For __builtin_return_address, Get the return address from that
8044      frame.  */
8045 #ifdef RETURN_ADDR_RTX
8046   tem = RETURN_ADDR_RTX (count, tem);
8047 #else
8048   tem = memory_address (Pmode,
8049                         plus_constant (tem, GET_MODE_SIZE (Pmode)));
8050   tem = gen_rtx_MEM (Pmode, tem);
8051 #endif
8052   return tem;
8053 }
8054
8055 /* __builtin_setjmp is passed a pointer to an array of five words (not
8056    all will be used on all machines).  It operates similarly to the C
8057    library function of the same name, but is more efficient.  Much of
8058    the code below (and for longjmp) is copied from the handling of
8059    non-local gotos.
8060
8061    NOTE: This is intended for use by GNAT and the exception handling
8062    scheme in the compiler and will only work in the method used by
8063    them.  */
8064
8065 rtx
8066 expand_builtin_setjmp (buf_addr, target, first_label, next_label)
8067      rtx buf_addr;
8068      rtx target;
8069      rtx first_label, next_label;
8070 {
8071   rtx lab1 = gen_label_rtx ();
8072   enum machine_mode sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
8073   enum machine_mode value_mode;
8074   rtx stack_save;
8075
8076   value_mode = TYPE_MODE (integer_type_node);
8077
8078 #ifdef POINTERS_EXTEND_UNSIGNED
8079   buf_addr = convert_memory_address (Pmode, buf_addr);
8080 #endif
8081
8082   buf_addr = force_reg (Pmode, buf_addr);
8083
8084   if (target == 0 || GET_CODE (target) != REG
8085       || REGNO (target) < FIRST_PSEUDO_REGISTER)
8086     target = gen_reg_rtx (value_mode);
8087
8088   emit_queue ();
8089
8090   /* We store the frame pointer and the address of lab1 in the buffer
8091      and use the rest of it for the stack save area, which is
8092      machine-dependent.  */
8093
8094 #ifndef BUILTIN_SETJMP_FRAME_VALUE
8095 #define BUILTIN_SETJMP_FRAME_VALUE virtual_stack_vars_rtx
8096 #endif
8097
8098   emit_move_insn (gen_rtx_MEM (Pmode, buf_addr),
8099                   BUILTIN_SETJMP_FRAME_VALUE);
8100   emit_move_insn (validize_mem
8101                   (gen_rtx_MEM (Pmode,
8102                                 plus_constant (buf_addr,
8103                                                GET_MODE_SIZE (Pmode)))),
8104                   gen_rtx_LABEL_REF (Pmode, lab1));
8105
8106   stack_save = gen_rtx_MEM (sa_mode,
8107                             plus_constant (buf_addr,
8108                                            2 * GET_MODE_SIZE (Pmode)));
8109   emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
8110
8111   /* If there is further processing to do, do it.  */
8112 #ifdef HAVE_builtin_setjmp_setup
8113   if (HAVE_builtin_setjmp_setup)
8114     emit_insn (gen_builtin_setjmp_setup (buf_addr));
8115 #endif
8116
8117   /* Set TARGET to zero and branch to the first-time-through label.  */
8118   emit_move_insn (target, const0_rtx);
8119   emit_jump_insn (gen_jump (first_label));
8120   emit_barrier ();
8121   emit_label (lab1);
8122
8123   /* Tell flow about the strange goings on.  */
8124   current_function_has_nonlocal_label = 1;
8125
8126   /* Clobber the FP when we get here, so we have to make sure it's
8127      marked as used by this function.  */
8128   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
8129
8130   /* Mark the static chain as clobbered here so life information
8131      doesn't get messed up for it.  */
8132   emit_insn (gen_rtx_CLOBBER (VOIDmode, static_chain_rtx));
8133
8134   /* Now put in the code to restore the frame pointer, and argument
8135      pointer, if needed.  The code below is from expand_end_bindings
8136      in stmt.c; see detailed documentation there.  */
8137 #ifdef HAVE_nonlocal_goto
8138   if (! HAVE_nonlocal_goto)
8139 #endif
8140     emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
8141
8142 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8143   if (fixed_regs[ARG_POINTER_REGNUM])
8144     {
8145 #ifdef ELIMINABLE_REGS
8146       int i;
8147       static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
8148
8149       for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
8150         if (elim_regs[i].from == ARG_POINTER_REGNUM
8151             && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
8152           break;
8153
8154       if (i == sizeof elim_regs / sizeof elim_regs [0])
8155 #endif
8156         {
8157           /* Now restore our arg pointer from the address at which it
8158              was saved in our stack frame.
8159              If there hasn't be space allocated for it yet, make
8160              some now.  */
8161           if (arg_pointer_save_area == 0)
8162             arg_pointer_save_area
8163               = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
8164           emit_move_insn (virtual_incoming_args_rtx,
8165                           copy_to_reg (arg_pointer_save_area));
8166         }
8167     }
8168 #endif
8169
8170 #ifdef HAVE_builtin_setjmp_receiver
8171   if (HAVE_builtin_setjmp_receiver)
8172     emit_insn (gen_builtin_setjmp_receiver (lab1));
8173   else
8174 #endif
8175 #ifdef HAVE_nonlocal_goto_receiver
8176     if (HAVE_nonlocal_goto_receiver)
8177       emit_insn (gen_nonlocal_goto_receiver ());
8178     else
8179 #endif
8180       {
8181         ; /* Nothing */
8182       }
8183
8184   /* Set TARGET, and branch to the next-time-through label.  */
8185   emit_move_insn (target, const1_rtx);
8186   emit_jump_insn (gen_jump (next_label));
8187   emit_barrier ();
8188
8189   return target;
8190 }
8191
8192 void
8193 expand_builtin_longjmp (buf_addr, value)
8194      rtx buf_addr, value;
8195 {
8196   rtx fp, lab, stack;
8197   enum machine_mode sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
8198
8199 #ifdef POINTERS_EXTEND_UNSIGNED
8200   buf_addr = convert_memory_address (Pmode, buf_addr);
8201 #endif
8202   buf_addr = force_reg (Pmode, buf_addr);
8203
8204   /* We used to store value in static_chain_rtx, but that fails if pointers
8205      are smaller than integers.  We instead require that the user must pass
8206      a second argument of 1, because that is what builtin_setjmp will
8207      return.  This also makes EH slightly more efficient, since we are no
8208      longer copying around a value that we don't care about.  */
8209   if (value != const1_rtx)
8210     abort ();
8211
8212 #ifdef HAVE_builtin_longjmp
8213   if (HAVE_builtin_longjmp)
8214     emit_insn (gen_builtin_longjmp (buf_addr));
8215   else
8216 #endif
8217     {
8218       fp = gen_rtx_MEM (Pmode, buf_addr);
8219       lab = gen_rtx_MEM (Pmode, plus_constant (buf_addr,
8220                                                GET_MODE_SIZE (Pmode)));
8221
8222       stack = gen_rtx_MEM (sa_mode, plus_constant (buf_addr,
8223                                                    2 * GET_MODE_SIZE (Pmode)));
8224
8225       /* Pick up FP, label, and SP from the block and jump.  This code is
8226          from expand_goto in stmt.c; see there for detailed comments.  */
8227 #if HAVE_nonlocal_goto
8228       if (HAVE_nonlocal_goto)
8229         /* We have to pass a value to the nonlocal_goto pattern that will
8230            get copied into the static_chain pointer, but it does not matter
8231            what that value is, because builtin_setjmp does not use it.  */
8232         emit_insn (gen_nonlocal_goto (value, fp, stack, lab));
8233       else
8234 #endif
8235         {
8236           lab = copy_to_reg (lab);
8237
8238           emit_move_insn (hard_frame_pointer_rtx, fp);
8239           emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
8240
8241           emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
8242           emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
8243           emit_indirect_jump (lab);
8244         }
8245     }
8246 }
8247
8248 static rtx
8249 get_memory_rtx (exp)
8250      tree exp;
8251 {
8252   rtx mem;
8253   int is_aggregate;
8254
8255   mem = gen_rtx_MEM (BLKmode,
8256                      memory_address (BLKmode,
8257                                      expand_expr (exp, NULL_RTX,
8258                                                   ptr_mode, EXPAND_SUM)));
8259
8260   RTX_UNCHANGING_P (mem) = TREE_READONLY (exp);
8261
8262   /* Figure out the type of the object pointed to.  Set MEM_IN_STRUCT_P
8263      if the value is the address of a structure or if the expression is
8264      cast to a pointer to structure type.  */
8265   is_aggregate = 0;
8266
8267   while (TREE_CODE (exp) == NOP_EXPR)
8268     {
8269       tree cast_type = TREE_TYPE (exp);
8270       if (TREE_CODE (cast_type) == POINTER_TYPE
8271           && AGGREGATE_TYPE_P (TREE_TYPE (cast_type)))
8272         {
8273           is_aggregate = 1;
8274           break;
8275         }
8276       exp = TREE_OPERAND (exp, 0);
8277     }
8278
8279   if (is_aggregate == 0)
8280     {
8281       tree type;
8282
8283       if (TREE_CODE (exp) == ADDR_EXPR)
8284         /* If this is the address of an object, check whether the
8285            object is an array.  */
8286         type = TREE_TYPE (TREE_OPERAND (exp, 0));
8287       else
8288         type = TREE_TYPE (TREE_TYPE (exp));
8289       is_aggregate = AGGREGATE_TYPE_P (type);
8290     }
8291
8292   MEM_IN_STRUCT_P (mem) = is_aggregate;
8293   return mem;
8294 }
8295
8296 \f
8297 /* Expand an expression EXP that calls a built-in function,
8298    with result going to TARGET if that's convenient
8299    (and in mode MODE if that's convenient).
8300    SUBTARGET may be used as the target for computing one of EXP's operands.
8301    IGNORE is nonzero if the value is to be ignored.  */
8302
8303 #define CALLED_AS_BUILT_IN(NODE) \
8304    (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
8305
8306 static rtx
8307 expand_builtin (exp, target, subtarget, mode, ignore)
8308      tree exp;
8309      rtx target;
8310      rtx subtarget;
8311      enum machine_mode mode;
8312      int ignore;
8313 {
8314   tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8315   tree arglist = TREE_OPERAND (exp, 1);
8316   rtx op0;
8317   rtx lab1, insns;
8318   enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
8319   optab builtin_optab;
8320
8321   switch (DECL_FUNCTION_CODE (fndecl))
8322     {
8323     case BUILT_IN_ABS:
8324     case BUILT_IN_LABS:
8325     case BUILT_IN_FABS:
8326       /* build_function_call changes these into ABS_EXPR.  */
8327       abort ();
8328
8329     case BUILT_IN_SIN:
8330     case BUILT_IN_COS:
8331       /* Treat these like sqrt, but only if the user asks for them.  */
8332       if (! flag_fast_math)
8333         break;
8334     case BUILT_IN_FSQRT:
8335       /* If not optimizing, call the library function.  */
8336       if (! optimize)
8337         break;
8338
8339       if (arglist == 0
8340           /* Arg could be wrong type if user redeclared this fcn wrong.  */
8341           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != REAL_TYPE)
8342         break;
8343
8344       /* Stabilize and compute the argument.  */
8345       if (TREE_CODE (TREE_VALUE (arglist)) != VAR_DECL
8346           && TREE_CODE (TREE_VALUE (arglist)) != PARM_DECL)
8347         {
8348           exp = copy_node (exp);
8349           arglist = copy_node (arglist);
8350           TREE_OPERAND (exp, 1) = arglist;
8351           TREE_VALUE (arglist) = save_expr (TREE_VALUE (arglist));
8352         }
8353       op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
8354
8355       /* Make a suitable register to place result in.  */
8356       target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
8357
8358       emit_queue ();
8359       start_sequence ();
8360
8361       switch (DECL_FUNCTION_CODE (fndecl))
8362         {
8363         case BUILT_IN_SIN:
8364           builtin_optab = sin_optab; break;
8365         case BUILT_IN_COS:
8366           builtin_optab = cos_optab; break;
8367         case BUILT_IN_FSQRT:
8368           builtin_optab = sqrt_optab; break;
8369         default:
8370           abort ();
8371         }
8372
8373       /* Compute into TARGET.
8374          Set TARGET to wherever the result comes back.  */
8375       target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
8376                             builtin_optab, op0, target, 0);
8377
8378       /* If we were unable to expand via the builtin, stop the
8379          sequence (without outputting the insns) and break, causing
8380          a call to the library function.  */
8381       if (target == 0)
8382         {
8383           end_sequence ();
8384           break;
8385         }
8386
8387       /* Check the results by default.  But if flag_fast_math is turned on,
8388          then assume sqrt will always be called with valid arguments.  */
8389
8390       if (! flag_fast_math)
8391         {
8392           /* Don't define the builtin FP instructions
8393              if your machine is not IEEE.  */
8394           if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
8395             abort ();
8396
8397           lab1 = gen_label_rtx ();
8398
8399           /* Test the result; if it is NaN, set errno=EDOM because
8400              the argument was not in the domain.  */
8401           emit_cmp_insn (target, target, EQ, 0, GET_MODE (target), 0, 0);
8402           emit_jump_insn (gen_beq (lab1));
8403
8404 #ifdef TARGET_EDOM
8405           {
8406 #ifdef GEN_ERRNO_RTX
8407             rtx errno_rtx = GEN_ERRNO_RTX;
8408 #else
8409             rtx errno_rtx
8410               = gen_rtx_MEM (word_mode, gen_rtx_SYMBOL_REF (Pmode, "errno"));
8411 #endif
8412
8413             emit_move_insn (errno_rtx, GEN_INT (TARGET_EDOM));
8414           }
8415 #else
8416           /* We can't set errno=EDOM directly; let the library call do it.
8417              Pop the arguments right away in case the call gets deleted.  */
8418           NO_DEFER_POP;
8419           expand_call (exp, target, 0);
8420           OK_DEFER_POP;
8421 #endif
8422
8423           emit_label (lab1);
8424         }
8425
8426       /* Output the entire sequence.  */
8427       insns = get_insns ();
8428       end_sequence ();
8429       emit_insns (insns);
8430  
8431       return target;
8432
8433     case BUILT_IN_FMOD:
8434       break;
8435
8436       /* __builtin_apply_args returns block of memory allocated on
8437          the stack into which is stored the arg pointer, structure
8438          value address, static chain, and all the registers that might
8439          possibly be used in performing a function call.  The code is
8440          moved to the start of the function so the incoming values are
8441          saved.  */
8442     case BUILT_IN_APPLY_ARGS:
8443       /* Don't do __builtin_apply_args more than once in a function.
8444          Save the result of the first call and reuse it.  */
8445       if (apply_args_value != 0)
8446         return apply_args_value;
8447       {
8448         /* When this function is called, it means that registers must be
8449            saved on entry to this function.  So we migrate the
8450            call to the first insn of this function.  */
8451         rtx temp;
8452         rtx seq;
8453
8454         start_sequence ();
8455         temp = expand_builtin_apply_args ();
8456         seq = get_insns ();
8457         end_sequence ();
8458
8459         apply_args_value = temp;
8460
8461         /* Put the sequence after the NOTE that starts the function.
8462            If this is inside a SEQUENCE, make the outer-level insn
8463            chain current, so the code is placed at the start of the
8464            function.  */
8465         push_topmost_sequence ();
8466         emit_insns_before (seq, NEXT_INSN (get_insns ()));
8467         pop_topmost_sequence ();
8468         return temp;
8469       }
8470
8471       /* __builtin_apply (FUNCTION, ARGUMENTS, ARGSIZE) invokes
8472          FUNCTION with a copy of the parameters described by
8473          ARGUMENTS, and ARGSIZE.  It returns a block of memory
8474          allocated on the stack into which is stored all the registers
8475          that might possibly be used for returning the result of a
8476          function.  ARGUMENTS is the value returned by
8477          __builtin_apply_args.  ARGSIZE is the number of bytes of
8478          arguments that must be copied.  ??? How should this value be
8479          computed?  We'll also need a safe worst case value for varargs
8480          functions.  */
8481     case BUILT_IN_APPLY:
8482       if (arglist == 0
8483           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
8484           || ! POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (arglist)))
8485           || TREE_CHAIN (arglist) == 0
8486           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
8487           || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
8488           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
8489         return const0_rtx;
8490       else
8491         {
8492           int i;
8493           tree t;
8494           rtx ops[3];
8495
8496           for (t = arglist, i = 0; t; t = TREE_CHAIN (t), i++)
8497             ops[i] = expand_expr (TREE_VALUE (t), NULL_RTX, VOIDmode, 0);
8498
8499           return expand_builtin_apply (ops[0], ops[1], ops[2]);
8500         }
8501
8502       /* __builtin_return (RESULT) causes the function to return the
8503          value described by RESULT.  RESULT is address of the block of
8504          memory returned by __builtin_apply.  */
8505     case BUILT_IN_RETURN:
8506       if (arglist
8507           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
8508           && TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == POINTER_TYPE)
8509         expand_builtin_return (expand_expr (TREE_VALUE (arglist),
8510                                             NULL_RTX, VOIDmode, 0));
8511       return const0_rtx;
8512
8513     case BUILT_IN_SAVEREGS:
8514       /* Don't do __builtin_saveregs more than once in a function.
8515          Save the result of the first call and reuse it.  */
8516       if (saveregs_value != 0)
8517         return saveregs_value;
8518       {
8519         /* When this function is called, it means that registers must be
8520            saved on entry to this function.  So we migrate the
8521            call to the first insn of this function.  */
8522         rtx temp;
8523         rtx seq;
8524
8525         /* Now really call the function.  `expand_call' does not call
8526            expand_builtin, so there is no danger of infinite recursion here.  */
8527         start_sequence ();
8528
8529 #ifdef EXPAND_BUILTIN_SAVEREGS
8530         /* Do whatever the machine needs done in this case.  */
8531         temp = EXPAND_BUILTIN_SAVEREGS (arglist);
8532 #else
8533         /* The register where the function returns its value
8534            is likely to have something else in it, such as an argument.
8535            So preserve that register around the call.  */
8536
8537         if (value_mode != VOIDmode)
8538           {
8539             rtx valreg = hard_libcall_value (value_mode);
8540             rtx saved_valreg = gen_reg_rtx (value_mode);
8541
8542             emit_move_insn (saved_valreg, valreg);
8543             temp = expand_call (exp, target, ignore);
8544             emit_move_insn (valreg, saved_valreg);
8545           }
8546         else
8547           /* Generate the call, putting the value in a pseudo.  */
8548           temp = expand_call (exp, target, ignore);
8549 #endif
8550
8551         seq = get_insns ();
8552         end_sequence ();
8553
8554         saveregs_value = temp;
8555
8556         /* Put the sequence after the NOTE that starts the function.
8557            If this is inside a SEQUENCE, make the outer-level insn
8558            chain current, so the code is placed at the start of the
8559            function.  */
8560         push_topmost_sequence ();
8561         emit_insns_before (seq, NEXT_INSN (get_insns ()));
8562         pop_topmost_sequence ();
8563         return temp;
8564       }
8565
8566       /* __builtin_args_info (N) returns word N of the arg space info
8567          for the current function.  The number and meanings of words
8568          is controlled by the definition of CUMULATIVE_ARGS.  */
8569     case BUILT_IN_ARGS_INFO:
8570       {
8571         int nwords = sizeof (CUMULATIVE_ARGS) / sizeof (int);
8572         int *word_ptr = (int *) &current_function_args_info;
8573 #if 0   
8574         /* These are used by the code below that is if 0'ed away */
8575         int i;
8576         tree type, elts, result;
8577 #endif
8578
8579         if (sizeof (CUMULATIVE_ARGS) % sizeof (int) != 0)
8580           fatal ("CUMULATIVE_ARGS type defined badly; see %s, line %d",
8581                  __FILE__, __LINE__);
8582
8583         if (arglist != 0)
8584           {
8585             tree arg = TREE_VALUE (arglist);
8586             if (TREE_CODE (arg) != INTEGER_CST)
8587               error ("argument of `__builtin_args_info' must be constant");
8588             else
8589               {
8590                 int wordnum = TREE_INT_CST_LOW (arg);
8591
8592                 if (wordnum < 0 || wordnum >= nwords || TREE_INT_CST_HIGH (arg))
8593                   error ("argument of `__builtin_args_info' out of range");
8594                 else
8595                   return GEN_INT (word_ptr[wordnum]);
8596               }
8597           }
8598         else
8599           error ("missing argument in `__builtin_args_info'");
8600
8601         return const0_rtx;
8602
8603 #if 0
8604         for (i = 0; i < nwords; i++)
8605           elts = tree_cons (NULL_TREE, build_int_2 (word_ptr[i], 0));
8606
8607         type = build_array_type (integer_type_node,
8608                                  build_index_type (build_int_2 (nwords, 0)));
8609         result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (elts));
8610         TREE_CONSTANT (result) = 1;
8611         TREE_STATIC (result) = 1;
8612         result = build (INDIRECT_REF, build_pointer_type (type), result);
8613         TREE_CONSTANT (result) = 1;
8614         return expand_expr (result, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD);
8615 #endif
8616       }
8617
8618       /* Return the address of the first anonymous stack arg.  */
8619     case BUILT_IN_NEXT_ARG:
8620       {
8621         tree fntype = TREE_TYPE (current_function_decl);
8622
8623         if ((TYPE_ARG_TYPES (fntype) == 0
8624              || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
8625                  == void_type_node))
8626             && ! current_function_varargs)
8627           {
8628             error ("`va_start' used in function with fixed args");
8629             return const0_rtx;
8630           }
8631
8632         if (arglist)
8633           {
8634             tree last_parm = tree_last (DECL_ARGUMENTS (current_function_decl));
8635             tree arg = TREE_VALUE (arglist);
8636
8637             /* Strip off all nops for the sake of the comparison.  This
8638                is not quite the same as STRIP_NOPS.  It does more.  
8639                We must also strip off INDIRECT_EXPR for C++ reference
8640                parameters.  */
8641             while (TREE_CODE (arg) == NOP_EXPR
8642                    || TREE_CODE (arg) == CONVERT_EXPR
8643                    || TREE_CODE (arg) == NON_LVALUE_EXPR
8644                    || TREE_CODE (arg) == INDIRECT_REF)
8645               arg = TREE_OPERAND (arg, 0);
8646             if (arg != last_parm)
8647               warning ("second parameter of `va_start' not last named argument");
8648           }
8649         else if (! current_function_varargs)
8650           /* Evidently an out of date version of <stdarg.h>; can't validate
8651              va_start's second argument, but can still work as intended.  */
8652           warning ("`__builtin_next_arg' called without an argument");
8653       }
8654
8655       return expand_binop (Pmode, add_optab,
8656                            current_function_internal_arg_pointer,
8657                            current_function_arg_offset_rtx,
8658                            NULL_RTX, 0, OPTAB_LIB_WIDEN);
8659
8660     case BUILT_IN_CLASSIFY_TYPE:
8661       if (arglist != 0)
8662         {
8663           tree type = TREE_TYPE (TREE_VALUE (arglist));
8664           enum tree_code code = TREE_CODE (type);
8665           if (code == VOID_TYPE)
8666             return GEN_INT (void_type_class);
8667           if (code == INTEGER_TYPE)
8668             return GEN_INT (integer_type_class);
8669           if (code == CHAR_TYPE)
8670             return GEN_INT (char_type_class);
8671           if (code == ENUMERAL_TYPE)
8672             return GEN_INT (enumeral_type_class);
8673           if (code == BOOLEAN_TYPE)
8674             return GEN_INT (boolean_type_class);
8675           if (code == POINTER_TYPE)
8676             return GEN_INT (pointer_type_class);
8677           if (code == REFERENCE_TYPE)
8678             return GEN_INT (reference_type_class);
8679           if (code == OFFSET_TYPE)
8680             return GEN_INT (offset_type_class);
8681           if (code == REAL_TYPE)
8682             return GEN_INT (real_type_class);
8683           if (code == COMPLEX_TYPE)
8684             return GEN_INT (complex_type_class);
8685           if (code == FUNCTION_TYPE)
8686             return GEN_INT (function_type_class);
8687           if (code == METHOD_TYPE)
8688             return GEN_INT (method_type_class);
8689           if (code == RECORD_TYPE)
8690             return GEN_INT (record_type_class);
8691           if (code == UNION_TYPE || code == QUAL_UNION_TYPE)
8692             return GEN_INT (union_type_class);
8693           if (code == ARRAY_TYPE)
8694             {
8695               if (TYPE_STRING_FLAG (type))
8696                 return GEN_INT (string_type_class);
8697               else
8698                 return GEN_INT (array_type_class);
8699             }
8700           if (code == SET_TYPE)
8701             return GEN_INT (set_type_class);
8702           if (code == FILE_TYPE)
8703             return GEN_INT (file_type_class);
8704           if (code == LANG_TYPE)
8705             return GEN_INT (lang_type_class);
8706         }
8707       return GEN_INT (no_type_class);
8708
8709     case BUILT_IN_CONSTANT_P:
8710       if (arglist == 0)
8711         return const0_rtx;
8712       else
8713         {
8714           tree arg = TREE_VALUE (arglist);
8715
8716           STRIP_NOPS (arg);
8717           if (really_constant_p (arg)
8718               || (TREE_CODE (arg) == ADDR_EXPR
8719                   && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST))
8720             return const1_rtx;
8721
8722           /* Only emit CONSTANT_P_RTX if CSE will be run. 
8723              Moreover, we don't want to expand trees that have side effects,
8724              as the original __builtin_constant_p did not evaluate its      
8725              argument at all, and we would break existing usage by changing 
8726              this.  This quirk was generally useful, eliminating a bit of hair
8727              in the writing of the macros that use this function.  Now the    
8728              same thing can be better accomplished in an inline function.  */
8729
8730           if (! cse_not_expected && ! TREE_SIDE_EFFECTS (arg))
8731             {
8732               /* Lazy fixup of old code: issue a warning and fail the test.  */
8733               if (! can_handle_constant_p)
8734                 {
8735                   warning ("Delayed evaluation of __builtin_constant_p not supported on this target.");
8736                   warning ("Please report this as a bug to egcs-bugs@cygnus.com.");
8737                   return const0_rtx;
8738                 }
8739               return gen_rtx_CONSTANT_P_RTX (TYPE_MODE (integer_type_node),
8740                                              expand_expr (arg, NULL_RTX,
8741                                                           VOIDmode, 0));
8742             }
8743
8744           return const0_rtx;
8745         }
8746
8747     case BUILT_IN_FRAME_ADDRESS:
8748       /* The argument must be a nonnegative integer constant.
8749          It counts the number of frames to scan up the stack.
8750          The value is the address of that frame.  */
8751     case BUILT_IN_RETURN_ADDRESS:
8752       /* The argument must be a nonnegative integer constant.
8753          It counts the number of frames to scan up the stack.
8754          The value is the return address saved in that frame.  */
8755       if (arglist == 0)
8756         /* Warning about missing arg was already issued.  */
8757         return const0_rtx;
8758       else if (TREE_CODE (TREE_VALUE (arglist)) != INTEGER_CST
8759                || tree_int_cst_sgn (TREE_VALUE (arglist)) < 0)
8760         {
8761           if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
8762             error ("invalid arg to `__builtin_frame_address'");
8763           else
8764             error ("invalid arg to `__builtin_return_address'");
8765           return const0_rtx;
8766         }
8767       else
8768         {
8769           rtx tem = expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl),
8770                                                 TREE_INT_CST_LOW (TREE_VALUE (arglist)),
8771                                                 hard_frame_pointer_rtx);
8772
8773           /* Some ports cannot access arbitrary stack frames.  */
8774           if (tem == NULL)
8775             {
8776               if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
8777                 warning ("unsupported arg to `__builtin_frame_address'");
8778               else
8779                 warning ("unsupported arg to `__builtin_return_address'");
8780               return const0_rtx;
8781             }
8782
8783           /* For __builtin_frame_address, return what we've got.  */
8784           if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FRAME_ADDRESS)
8785             return tem;
8786
8787           if (GET_CODE (tem) != REG)
8788             tem = copy_to_reg (tem);
8789           return tem;
8790         }
8791
8792     /* Returns the address of the area where the structure is returned.
8793        0 otherwise.  */
8794     case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
8795       if (arglist != 0
8796           || ! AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl)))
8797           || GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) != MEM)
8798         return const0_rtx;
8799       else
8800         return XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
8801
8802     case BUILT_IN_ALLOCA:
8803       if (arglist == 0
8804           /* Arg could be non-integer if user redeclared this fcn wrong.  */
8805           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
8806         break;
8807
8808       /* Compute the argument.  */
8809       op0 = expand_expr (TREE_VALUE (arglist), NULL_RTX, VOIDmode, 0);
8810
8811       /* Allocate the desired space.  */
8812       return allocate_dynamic_stack_space (op0, target, BITS_PER_UNIT);
8813
8814     case BUILT_IN_FFS:
8815       /* If not optimizing, call the library function.  */
8816       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8817         break;
8818
8819       if (arglist == 0
8820           /* Arg could be non-integer if user redeclared this fcn wrong.  */
8821           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != INTEGER_TYPE)
8822         break;
8823
8824       /* Compute the argument.  */
8825       op0 = expand_expr (TREE_VALUE (arglist), subtarget, VOIDmode, 0);
8826       /* Compute ffs, into TARGET if possible.
8827          Set TARGET to wherever the result comes back.  */
8828       target = expand_unop (TYPE_MODE (TREE_TYPE (TREE_VALUE (arglist))),
8829                             ffs_optab, op0, target, 1);
8830       if (target == 0)
8831         abort ();
8832       return target;
8833
8834     case BUILT_IN_STRLEN:
8835       /* If not optimizing, call the library function.  */
8836       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8837         break;
8838
8839       if (arglist == 0
8840           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
8841           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
8842         break;
8843       else
8844         {
8845           tree src = TREE_VALUE (arglist);
8846           tree len = c_strlen (src);
8847
8848           int align
8849             = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8850
8851           rtx result, src_rtx, char_rtx;
8852           enum machine_mode insn_mode = value_mode, char_mode;
8853           enum insn_code icode;
8854
8855           /* If the length is known, just return it.  */
8856           if (len != 0)
8857             return expand_expr (len, target, mode, EXPAND_MEMORY_USE_BAD);
8858
8859           /* If SRC is not a pointer type, don't do this operation inline.  */
8860           if (align == 0)
8861             break;
8862
8863           /* Call a function if we can't compute strlen in the right mode.  */
8864
8865           while (insn_mode != VOIDmode)
8866             {
8867               icode = strlen_optab->handlers[(int) insn_mode].insn_code;
8868               if (icode != CODE_FOR_nothing)
8869                 break;
8870
8871               insn_mode = GET_MODE_WIDER_MODE (insn_mode);
8872             }
8873           if (insn_mode == VOIDmode)
8874             break;
8875
8876           /* Make a place to write the result of the instruction.  */
8877           result = target;
8878           if (! (result != 0
8879                  && GET_CODE (result) == REG
8880                  && GET_MODE (result) == insn_mode
8881                  && REGNO (result) >= FIRST_PSEUDO_REGISTER))
8882             result = gen_reg_rtx (insn_mode);
8883
8884           /* Make sure the operands are acceptable to the predicates.  */
8885
8886           if (! (*insn_operand_predicate[(int)icode][0]) (result, insn_mode))
8887             result = gen_reg_rtx (insn_mode);
8888           src_rtx = memory_address (BLKmode,
8889                                     expand_expr (src, NULL_RTX, ptr_mode,
8890                                                  EXPAND_NORMAL));
8891
8892           if (! (*insn_operand_predicate[(int)icode][1]) (src_rtx, Pmode))
8893             src_rtx = copy_to_mode_reg (Pmode, src_rtx);
8894
8895           /* Check the string is readable and has an end.  */
8896           if (flag_check_memory_usage)
8897             emit_library_call (chkr_check_str_libfunc, 1, VOIDmode, 2,
8898                                src_rtx, ptr_mode,
8899                                GEN_INT (MEMORY_USE_RO),
8900                                TYPE_MODE (integer_type_node));
8901
8902           char_rtx = const0_rtx;
8903           char_mode = insn_operand_mode[(int)icode][2];
8904           if (! (*insn_operand_predicate[(int)icode][2]) (char_rtx, char_mode))
8905             char_rtx = copy_to_mode_reg (char_mode, char_rtx);
8906
8907           emit_insn (GEN_FCN (icode) (result,
8908                                       gen_rtx_MEM (BLKmode, src_rtx),
8909                                       char_rtx, GEN_INT (align)));
8910
8911           /* Return the value in the proper mode for this function.  */
8912           if (GET_MODE (result) == value_mode)
8913             return result;
8914           else if (target != 0)
8915             {
8916               convert_move (target, result, 0);
8917               return target;
8918             }
8919           else
8920             return convert_to_mode (value_mode, result, 0);
8921         }
8922
8923     case BUILT_IN_STRCPY:
8924       /* If not optimizing, call the library function.  */
8925       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8926         break;
8927
8928       if (arglist == 0
8929           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
8930           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8931           || TREE_CHAIN (arglist) == 0
8932           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
8933         break;
8934       else
8935         {
8936           tree len = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)));
8937
8938           if (len == 0)
8939             break;
8940
8941           len = size_binop (PLUS_EXPR, len, integer_one_node);
8942
8943           chainon (arglist, build_tree_list (NULL_TREE, len));
8944         }
8945
8946       /* Drops in.  */
8947     case BUILT_IN_MEMCPY:
8948       /* If not optimizing, call the library function.  */
8949       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
8950         break;
8951
8952       if (arglist == 0
8953           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
8954           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
8955           || TREE_CHAIN (arglist) == 0
8956           || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
8957               != POINTER_TYPE)
8958           || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
8959           || (TREE_CODE (TREE_TYPE (TREE_VALUE
8960                                     (TREE_CHAIN (TREE_CHAIN (arglist)))))
8961               != INTEGER_TYPE))
8962         break;
8963       else
8964         {
8965           tree dest = TREE_VALUE (arglist);
8966           tree src = TREE_VALUE (TREE_CHAIN (arglist));
8967           tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
8968
8969           int src_align
8970             = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8971           int dest_align
8972             = get_pointer_alignment (dest, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
8973           rtx dest_mem, src_mem, dest_addr, len_rtx;
8974
8975           /* If either SRC or DEST is not a pointer type, don't do
8976              this operation in-line.  */
8977           if (src_align == 0 || dest_align == 0)
8978             {
8979               if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRCPY)
8980                 TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
8981               break;
8982             }
8983
8984           dest_mem = get_memory_rtx (dest);
8985           src_mem = get_memory_rtx (src);
8986           len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
8987
8988           /* Just copy the rights of SRC to the rights of DEST.  */
8989           if (flag_check_memory_usage)
8990             emit_library_call (chkr_copy_bitmap_libfunc, 1, VOIDmode, 3,
8991                                XEXP (dest_mem, 0), ptr_mode,
8992                                XEXP (src_mem, 0), ptr_mode,
8993                                len_rtx, TYPE_MODE (sizetype));
8994
8995           /* Copy word part most expediently.  */
8996           dest_addr
8997             = emit_block_move (dest_mem, src_mem, len_rtx,
8998                                MIN (src_align, dest_align));
8999
9000           if (dest_addr == 0)
9001             dest_addr = force_operand (XEXP (dest_mem, 0), NULL_RTX);
9002
9003           return dest_addr;
9004         }
9005
9006     case BUILT_IN_MEMSET:
9007       /* If not optimizing, call the library function.  */
9008       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
9009         break;
9010
9011       if (arglist == 0
9012           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
9013           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
9014           || TREE_CHAIN (arglist) == 0
9015           || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
9016               != INTEGER_TYPE)
9017           || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
9018           || (INTEGER_TYPE
9019               != (TREE_CODE (TREE_TYPE
9020                              (TREE_VALUE
9021                               (TREE_CHAIN (TREE_CHAIN (arglist))))))))
9022         break;
9023       else
9024         {
9025           tree dest = TREE_VALUE (arglist);
9026           tree val = TREE_VALUE (TREE_CHAIN (arglist));
9027           tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
9028
9029           int dest_align
9030             = get_pointer_alignment (dest, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
9031           rtx dest_mem, dest_addr, len_rtx;
9032
9033           /* If DEST is not a pointer type, don't do this 
9034              operation in-line.  */
9035           if (dest_align == 0)
9036             break;
9037
9038           /* If the arguments have side-effects, then we can only evaluate
9039              them at most once.  The following code evaluates them twice if
9040              they are not constants because we break out to expand_call
9041              in that case.  They can't be constants if they have side-effects
9042              so we can check for that first.  Alternatively, we could call
9043              save_expr to make multiple evaluation safe.  */
9044           if (TREE_SIDE_EFFECTS (val) || TREE_SIDE_EFFECTS (len))
9045             break;
9046
9047           /* If VAL is not 0, don't do this operation in-line. */
9048           if (expand_expr (val, NULL_RTX, VOIDmode, 0) != const0_rtx)
9049             break;
9050
9051           /* If LEN does not expand to a constant, don't do this
9052              operation in-line.  */
9053           len_rtx = expand_expr (len, NULL_RTX, VOIDmode, 0);
9054           if (GET_CODE (len_rtx) != CONST_INT)
9055             break;
9056
9057           dest_mem = get_memory_rtx (dest);
9058            
9059           /* Just check DST is writable and mark it as readable.  */
9060           if (flag_check_memory_usage)
9061             emit_library_call (chkr_check_addr_libfunc, 1, VOIDmode, 3,
9062                                XEXP (dest_mem, 0), ptr_mode,
9063                                len_rtx, TYPE_MODE (sizetype),
9064                                GEN_INT (MEMORY_USE_WO),
9065                                TYPE_MODE (integer_type_node));
9066
9067
9068           dest_addr = clear_storage (dest_mem, len_rtx, dest_align);
9069
9070           if (dest_addr == 0)
9071             dest_addr = force_operand (XEXP (dest_mem, 0), NULL_RTX);
9072
9073           return dest_addr;
9074         }
9075
9076 /* These comparison functions need an instruction that returns an actual
9077    index.  An ordinary compare that just sets the condition codes
9078    is not enough.  */
9079 #ifdef HAVE_cmpstrsi
9080     case BUILT_IN_STRCMP:
9081       /* If not optimizing, call the library function.  */
9082       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
9083         break;
9084
9085       /* If we need to check memory accesses, call the library function.  */
9086       if (flag_check_memory_usage)
9087         break;
9088
9089       if (arglist == 0
9090           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
9091           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
9092           || TREE_CHAIN (arglist) == 0
9093           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE)
9094         break;
9095       else if (!HAVE_cmpstrsi)
9096         break;
9097       {
9098         tree arg1 = TREE_VALUE (arglist);
9099         tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
9100         tree len, len2;
9101
9102         len = c_strlen (arg1);
9103         if (len)
9104           len = size_binop (PLUS_EXPR, integer_one_node, len);
9105         len2 = c_strlen (arg2);
9106         if (len2)
9107           len2 = size_binop (PLUS_EXPR, integer_one_node, len2);
9108
9109         /* If we don't have a constant length for the first, use the length
9110            of the second, if we know it.  We don't require a constant for
9111            this case; some cost analysis could be done if both are available
9112            but neither is constant.  For now, assume they're equally cheap.
9113
9114            If both strings have constant lengths, use the smaller.  This
9115            could arise if optimization results in strcpy being called with
9116            two fixed strings, or if the code was machine-generated.  We should
9117            add some code to the `memcmp' handler below to deal with such
9118            situations, someday.  */
9119         if (!len || TREE_CODE (len) != INTEGER_CST)
9120           {
9121             if (len2)
9122               len = len2;
9123             else if (len == 0)
9124               break;
9125           }
9126         else if (len2 && TREE_CODE (len2) == INTEGER_CST)
9127           {
9128             if (tree_int_cst_lt (len2, len))
9129               len = len2;
9130           }
9131
9132         chainon (arglist, build_tree_list (NULL_TREE, len));
9133       }
9134
9135       /* Drops in.  */
9136     case BUILT_IN_MEMCMP:
9137       /* If not optimizing, call the library function.  */
9138       if (!optimize && ! CALLED_AS_BUILT_IN (fndecl))
9139         break;
9140
9141       /* If we need to check memory accesses, call the library function.  */
9142       if (flag_check_memory_usage)
9143         break;
9144
9145       if (arglist == 0
9146           /* Arg could be non-pointer if user redeclared this fcn wrong.  */
9147           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
9148           || TREE_CHAIN (arglist) == 0
9149           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) != POINTER_TYPE
9150           || TREE_CHAIN (TREE_CHAIN (arglist)) == 0
9151           || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))))) != INTEGER_TYPE)
9152         break;
9153       else if (!HAVE_cmpstrsi)
9154         break;
9155       {
9156         tree arg1 = TREE_VALUE (arglist);
9157         tree arg2 = TREE_VALUE (TREE_CHAIN (arglist));
9158         tree len = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
9159         rtx result;
9160
9161         int arg1_align
9162           = get_pointer_alignment (arg1, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
9163         int arg2_align
9164           = get_pointer_alignment (arg2, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
9165         enum machine_mode insn_mode
9166           = insn_operand_mode[(int) CODE_FOR_cmpstrsi][0];
9167
9168         /* If we don't have POINTER_TYPE, call the function.  */
9169         if (arg1_align == 0 || arg2_align == 0)
9170           {
9171             if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRCMP)
9172               TREE_CHAIN (TREE_CHAIN (arglist)) = 0;
9173             break;
9174           }
9175
9176         /* Make a place to write the result of the instruction.  */
9177         result = target;
9178         if (! (result != 0
9179                && GET_CODE (result) == REG && GET_MODE (result) == insn_mode
9180                && REGNO (result) >= FIRST_PSEUDO_REGISTER))
9181           result = gen_reg_rtx (insn_mode);
9182
9183         emit_insn (gen_cmpstrsi (result, get_memory_rtx (arg1),
9184                                  get_memory_rtx (arg2),
9185                                  expand_expr (len, NULL_RTX, VOIDmode, 0),
9186                                  GEN_INT (MIN (arg1_align, arg2_align))));
9187
9188         /* Return the value in the proper mode for this function.  */
9189         mode = TYPE_MODE (TREE_TYPE (exp));
9190         if (GET_MODE (result) == mode)
9191           return result;
9192         else if (target != 0)
9193           {
9194             convert_move (target, result, 0);
9195             return target;
9196           }
9197         else
9198           return convert_to_mode (mode, result, 0);
9199       } 
9200 #else
9201     case BUILT_IN_STRCMP:
9202     case BUILT_IN_MEMCMP:
9203       break;
9204 #endif
9205
9206     case BUILT_IN_SETJMP:
9207       if (arglist == 0
9208           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
9209         break;
9210       else
9211         {
9212           rtx buf_addr = expand_expr (TREE_VALUE (arglist), subtarget,
9213                                       VOIDmode, 0);
9214           rtx lab = gen_label_rtx ();
9215           rtx ret = expand_builtin_setjmp (buf_addr, target, lab, lab);
9216           emit_label (lab);
9217           return ret;
9218         }
9219
9220       /* __builtin_longjmp is passed a pointer to an array of five words.
9221          It's similar to the C library longjmp function but works with
9222          __builtin_setjmp above.  */
9223     case BUILT_IN_LONGJMP:
9224       if (arglist == 0 || TREE_CHAIN (arglist) == 0
9225           || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
9226         break;
9227       else
9228         {
9229           rtx buf_addr = expand_expr (TREE_VALUE (arglist), subtarget,
9230                                       VOIDmode, 0);
9231           rtx value = expand_expr (TREE_VALUE (TREE_CHAIN (arglist)),
9232                                    NULL_RTX, VOIDmode, 0);
9233
9234           if (value != const1_rtx)
9235             {
9236               error ("__builtin_longjmp second argument must be 1");
9237               return const0_rtx;
9238             }
9239
9240           expand_builtin_longjmp (buf_addr, value);
9241           return const0_rtx;
9242         }
9243
9244     case BUILT_IN_TRAP:
9245 #ifdef HAVE_trap
9246       if (HAVE_trap)
9247         emit_insn (gen_trap ());
9248       else
9249 #endif
9250         error ("__builtin_trap not supported by this target");
9251       emit_barrier ();
9252       return const0_rtx;
9253
9254       /* Various hooks for the DWARF 2 __throw routine.  */
9255     case BUILT_IN_UNWIND_INIT:
9256       expand_builtin_unwind_init ();
9257       return const0_rtx;
9258     case BUILT_IN_FP:
9259       return frame_pointer_rtx;
9260     case BUILT_IN_SP:
9261       return stack_pointer_rtx;
9262 #ifdef DWARF2_UNWIND_INFO
9263     case BUILT_IN_DWARF_FP_REGNUM:
9264       return expand_builtin_dwarf_fp_regnum ();
9265     case BUILT_IN_DWARF_REG_SIZE:
9266       return expand_builtin_dwarf_reg_size (TREE_VALUE (arglist), target);
9267 #endif
9268     case BUILT_IN_FROB_RETURN_ADDR:
9269       return expand_builtin_frob_return_addr (TREE_VALUE (arglist));
9270     case BUILT_IN_EXTRACT_RETURN_ADDR:
9271       return expand_builtin_extract_return_addr (TREE_VALUE (arglist));
9272     case BUILT_IN_SET_RETURN_ADDR_REG:
9273       expand_builtin_set_return_addr_reg (TREE_VALUE (arglist));
9274       return const0_rtx;
9275     case BUILT_IN_EH_STUB_OLD:
9276       return expand_builtin_eh_stub_old ();
9277     case BUILT_IN_EH_STUB:
9278       return expand_builtin_eh_stub ();
9279     case BUILT_IN_SET_EH_REGS:
9280       expand_builtin_set_eh_regs (TREE_VALUE (arglist),
9281                                   TREE_VALUE (TREE_CHAIN (arglist)));
9282       return const0_rtx;
9283
9284     default:                    /* just do library call, if unknown builtin */
9285       error ("built-in function `%s' not currently supported",
9286              IDENTIFIER_POINTER (DECL_NAME (fndecl)));
9287     }
9288
9289   /* The switch statement above can drop through to cause the function
9290      to be called normally.  */
9291
9292   return expand_call (exp, target, ignore);
9293 }
9294 \f
9295 /* Built-in functions to perform an untyped call and return.  */
9296
9297 /* For each register that may be used for calling a function, this
9298    gives a mode used to copy the register's value.  VOIDmode indicates
9299    the register is not used for calling a function.  If the machine
9300    has register windows, this gives only the outbound registers.
9301    INCOMING_REGNO gives the corresponding inbound register.  */
9302 static enum machine_mode apply_args_mode[FIRST_PSEUDO_REGISTER];
9303
9304 /* For each register that may be used for returning values, this gives
9305    a mode used to copy the register's value.  VOIDmode indicates the
9306    register is not used for returning values.  If the machine has
9307    register windows, this gives only the outbound registers.
9308    INCOMING_REGNO gives the corresponding inbound register.  */
9309 static enum machine_mode apply_result_mode[FIRST_PSEUDO_REGISTER];
9310
9311 /* For each register that may be used for calling a function, this
9312    gives the offset of that register into the block returned by
9313    __builtin_apply_args.  0 indicates that the register is not
9314    used for calling a function.  */
9315 static int apply_args_reg_offset[FIRST_PSEUDO_REGISTER];
9316
9317 /* Return the offset of register REGNO into the block returned by 
9318    __builtin_apply_args.  This is not declared static, since it is
9319    needed in objc-act.c.  */
9320
9321 int 
9322 apply_args_register_offset (regno)
9323      int regno;
9324 {
9325   apply_args_size ();
9326
9327   /* Arguments are always put in outgoing registers (in the argument
9328      block) if such make sense.  */
9329 #ifdef OUTGOING_REGNO
9330   regno = OUTGOING_REGNO(regno);
9331 #endif
9332   return apply_args_reg_offset[regno];
9333 }
9334
9335 /* Return the size required for the block returned by __builtin_apply_args,
9336    and initialize apply_args_mode.  */
9337
9338 static int
9339 apply_args_size ()
9340 {
9341   static int size = -1;
9342   int align, regno;
9343   enum machine_mode mode;
9344
9345   /* The values computed by this function never change.  */
9346   if (size < 0)
9347     {
9348       /* The first value is the incoming arg-pointer.  */
9349       size = GET_MODE_SIZE (Pmode);
9350
9351       /* The second value is the structure value address unless this is
9352          passed as an "invisible" first argument.  */
9353       if (struct_value_rtx)
9354         size += GET_MODE_SIZE (Pmode);
9355
9356       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9357         if (FUNCTION_ARG_REGNO_P (regno))
9358           {
9359             /* Search for the proper mode for copying this register's
9360                value.  I'm not sure this is right, but it works so far.  */
9361             enum machine_mode best_mode = VOIDmode;
9362
9363             for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
9364                  mode != VOIDmode;
9365                  mode = GET_MODE_WIDER_MODE (mode))
9366               if (HARD_REGNO_MODE_OK (regno, mode)
9367                   && HARD_REGNO_NREGS (regno, mode) == 1)
9368                 best_mode = mode;
9369
9370             if (best_mode == VOIDmode)
9371               for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
9372                    mode != VOIDmode;
9373                    mode = GET_MODE_WIDER_MODE (mode))
9374                 if (HARD_REGNO_MODE_OK (regno, mode)
9375                     && (mov_optab->handlers[(int) mode].insn_code
9376                         != CODE_FOR_nothing))
9377                   best_mode = mode;
9378
9379             mode = best_mode;
9380             if (mode == VOIDmode)
9381               abort ();
9382
9383             align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9384             if (size % align != 0)
9385               size = CEIL (size, align) * align;
9386             apply_args_reg_offset[regno] = size;
9387             size += GET_MODE_SIZE (mode);
9388             apply_args_mode[regno] = mode;
9389           }
9390         else
9391           {
9392             apply_args_mode[regno] = VOIDmode;
9393             apply_args_reg_offset[regno] = 0;
9394           }
9395     }
9396   return size;
9397 }
9398
9399 /* Return the size required for the block returned by __builtin_apply,
9400    and initialize apply_result_mode.  */
9401
9402 static int
9403 apply_result_size ()
9404 {
9405   static int size = -1;
9406   int align, regno;
9407   enum machine_mode mode;
9408
9409   /* The values computed by this function never change.  */
9410   if (size < 0)
9411     {
9412       size = 0;
9413
9414       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9415         if (FUNCTION_VALUE_REGNO_P (regno))
9416           {
9417             /* Search for the proper mode for copying this register's
9418                value.  I'm not sure this is right, but it works so far.  */
9419             enum machine_mode best_mode = VOIDmode;
9420
9421             for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
9422                  mode != TImode;
9423                  mode = GET_MODE_WIDER_MODE (mode))
9424               if (HARD_REGNO_MODE_OK (regno, mode))
9425                 best_mode = mode;
9426
9427             if (best_mode == VOIDmode)
9428               for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
9429                    mode != VOIDmode;
9430                    mode = GET_MODE_WIDER_MODE (mode))
9431                 if (HARD_REGNO_MODE_OK (regno, mode)
9432                     && (mov_optab->handlers[(int) mode].insn_code
9433                         != CODE_FOR_nothing))
9434                   best_mode = mode;
9435
9436             mode = best_mode;
9437             if (mode == VOIDmode)
9438               abort ();
9439
9440             align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9441             if (size % align != 0)
9442               size = CEIL (size, align) * align;
9443             size += GET_MODE_SIZE (mode);
9444             apply_result_mode[regno] = mode;
9445           }
9446         else
9447           apply_result_mode[regno] = VOIDmode;
9448
9449       /* Allow targets that use untyped_call and untyped_return to override
9450          the size so that machine-specific information can be stored here.  */
9451 #ifdef APPLY_RESULT_SIZE
9452       size = APPLY_RESULT_SIZE;
9453 #endif
9454     }
9455   return size;
9456 }
9457
9458 #if defined (HAVE_untyped_call) || defined (HAVE_untyped_return)
9459 /* Create a vector describing the result block RESULT.  If SAVEP is true,
9460    the result block is used to save the values; otherwise it is used to
9461    restore the values.  */
9462
9463 static rtx
9464 result_vector (savep, result)
9465      int savep;
9466      rtx result;
9467 {
9468   int regno, size, align, nelts;
9469   enum machine_mode mode;
9470   rtx reg, mem;
9471   rtx *savevec = (rtx *) alloca (FIRST_PSEUDO_REGISTER * sizeof (rtx));
9472   
9473   size = nelts = 0;
9474   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9475     if ((mode = apply_result_mode[regno]) != VOIDmode)
9476       {
9477         align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9478         if (size % align != 0)
9479           size = CEIL (size, align) * align;
9480         reg = gen_rtx_REG (mode, savep ? regno : INCOMING_REGNO (regno));
9481         mem = change_address (result, mode,
9482                               plus_constant (XEXP (result, 0), size));
9483         savevec[nelts++] = (savep
9484                             ? gen_rtx_SET (VOIDmode, mem, reg)
9485                             : gen_rtx_SET (VOIDmode, reg, mem));
9486         size += GET_MODE_SIZE (mode);
9487       }
9488   return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelts, savevec));
9489 }
9490 #endif /* HAVE_untyped_call or HAVE_untyped_return */
9491
9492 /* Save the state required to perform an untyped call with the same
9493    arguments as were passed to the current function.  */
9494
9495 static rtx
9496 expand_builtin_apply_args ()
9497 {
9498   rtx registers;
9499   int size, align, regno;
9500   enum machine_mode mode;
9501
9502   /* Create a block where the arg-pointer, structure value address,
9503      and argument registers can be saved.  */
9504   registers = assign_stack_local (BLKmode, apply_args_size (), -1);
9505
9506   /* Walk past the arg-pointer and structure value address.  */
9507   size = GET_MODE_SIZE (Pmode);
9508   if (struct_value_rtx)
9509     size += GET_MODE_SIZE (Pmode);
9510
9511   /* Save each register used in calling a function to the block.  */
9512   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9513     if ((mode = apply_args_mode[regno]) != VOIDmode)
9514       {
9515         rtx tem;
9516
9517         align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9518         if (size % align != 0)
9519           size = CEIL (size, align) * align;
9520
9521         tem = gen_rtx_REG (mode, INCOMING_REGNO (regno));
9522
9523 #ifdef STACK_REGS
9524         /* For reg-stack.c's stack register household.
9525            Compare with a similar piece of code in function.c.  */
9526
9527         emit_insn (gen_rtx_USE (mode, tem));
9528 #endif
9529
9530         emit_move_insn (change_address (registers, mode,
9531                                         plus_constant (XEXP (registers, 0),
9532                                                        size)),
9533                         tem);
9534         size += GET_MODE_SIZE (mode);
9535       }
9536
9537   /* Save the arg pointer to the block.  */
9538   emit_move_insn (change_address (registers, Pmode, XEXP (registers, 0)),
9539                   copy_to_reg (virtual_incoming_args_rtx));
9540   size = GET_MODE_SIZE (Pmode);
9541
9542   /* Save the structure value address unless this is passed as an
9543      "invisible" first argument.  */
9544   if (struct_value_incoming_rtx)
9545     {
9546       emit_move_insn (change_address (registers, Pmode,
9547                                       plus_constant (XEXP (registers, 0),
9548                                                      size)),
9549                       copy_to_reg (struct_value_incoming_rtx));
9550       size += GET_MODE_SIZE (Pmode);
9551     }
9552
9553   /* Return the address of the block.  */
9554   return copy_addr_to_reg (XEXP (registers, 0));
9555 }
9556
9557 /* Perform an untyped call and save the state required to perform an
9558    untyped return of whatever value was returned by the given function.  */
9559
9560 static rtx
9561 expand_builtin_apply (function, arguments, argsize)
9562      rtx function, arguments, argsize;
9563 {
9564   int size, align, regno;
9565   enum machine_mode mode;
9566   rtx incoming_args, result, reg, dest, call_insn;
9567   rtx old_stack_level = 0;
9568   rtx call_fusage = 0;
9569
9570   /* Create a block where the return registers can be saved.  */
9571   result = assign_stack_local (BLKmode, apply_result_size (), -1);
9572
9573   /* ??? The argsize value should be adjusted here.  */
9574
9575   /* Fetch the arg pointer from the ARGUMENTS block.  */
9576   incoming_args = gen_reg_rtx (Pmode);
9577   emit_move_insn (incoming_args,
9578                   gen_rtx_MEM (Pmode, arguments));
9579 #ifndef STACK_GROWS_DOWNWARD
9580   incoming_args = expand_binop (Pmode, sub_optab, incoming_args, argsize,
9581                                 incoming_args, 0, OPTAB_LIB_WIDEN);
9582 #endif
9583
9584   /* Perform postincrements before actually calling the function.  */
9585   emit_queue ();
9586
9587   /* Push a new argument block and copy the arguments.  */
9588   do_pending_stack_adjust ();
9589
9590   /* Save the stack with nonlocal if available */
9591 #ifdef HAVE_save_stack_nonlocal
9592   if (HAVE_save_stack_nonlocal)
9593     emit_stack_save (SAVE_NONLOCAL, &old_stack_level, NULL_RTX);
9594   else
9595 #endif
9596     emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
9597
9598   /* Push a block of memory onto the stack to store the memory arguments.
9599      Save the address in a register, and copy the memory arguments.  ??? I
9600      haven't figured out how the calling convention macros effect this,
9601      but it's likely that the source and/or destination addresses in
9602      the block copy will need updating in machine specific ways.  */
9603   dest = allocate_dynamic_stack_space (argsize, 0, 0);
9604   emit_block_move (gen_rtx_MEM (BLKmode, dest),
9605                    gen_rtx_MEM (BLKmode, incoming_args),
9606                    argsize,
9607                    PARM_BOUNDARY / BITS_PER_UNIT);
9608
9609   /* Refer to the argument block.  */
9610   apply_args_size ();
9611   arguments = gen_rtx_MEM (BLKmode, arguments);
9612
9613   /* Walk past the arg-pointer and structure value address.  */
9614   size = GET_MODE_SIZE (Pmode);
9615   if (struct_value_rtx)
9616     size += GET_MODE_SIZE (Pmode);
9617
9618   /* Restore each of the registers previously saved.  Make USE insns
9619      for each of these registers for use in making the call.  */
9620   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9621     if ((mode = apply_args_mode[regno]) != VOIDmode)
9622       {
9623         align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9624         if (size % align != 0)
9625           size = CEIL (size, align) * align;
9626         reg = gen_rtx_REG (mode, regno);
9627         emit_move_insn (reg,
9628                         change_address (arguments, mode,
9629                                         plus_constant (XEXP (arguments, 0),
9630                                                        size)));
9631
9632         use_reg (&call_fusage, reg);
9633         size += GET_MODE_SIZE (mode);
9634       }
9635
9636   /* Restore the structure value address unless this is passed as an
9637      "invisible" first argument.  */
9638   size = GET_MODE_SIZE (Pmode);
9639   if (struct_value_rtx)
9640     {
9641       rtx value = gen_reg_rtx (Pmode);
9642       emit_move_insn (value,
9643                       change_address (arguments, Pmode,
9644                                       plus_constant (XEXP (arguments, 0),
9645                                                      size)));
9646       emit_move_insn (struct_value_rtx, value);
9647       if (GET_CODE (struct_value_rtx) == REG)
9648           use_reg (&call_fusage, struct_value_rtx);
9649       size += GET_MODE_SIZE (Pmode);
9650     }
9651
9652   /* All arguments and registers used for the call are set up by now!  */
9653   function = prepare_call_address (function, NULL_TREE, &call_fusage, 0);
9654
9655   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
9656      and we don't want to load it into a register as an optimization,
9657      because prepare_call_address already did it if it should be done.  */
9658   if (GET_CODE (function) != SYMBOL_REF)
9659     function = memory_address (FUNCTION_MODE, function);
9660
9661   /* Generate the actual call instruction and save the return value.  */
9662 #ifdef HAVE_untyped_call
9663   if (HAVE_untyped_call)
9664     emit_call_insn (gen_untyped_call (gen_rtx_MEM (FUNCTION_MODE, function),
9665                                       result, result_vector (1, result)));
9666   else
9667 #endif
9668 #ifdef HAVE_call_value
9669   if (HAVE_call_value)
9670     {
9671       rtx valreg = 0;
9672
9673       /* Locate the unique return register.  It is not possible to
9674          express a call that sets more than one return register using
9675          call_value; use untyped_call for that.  In fact, untyped_call
9676          only needs to save the return registers in the given block.  */
9677       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9678         if ((mode = apply_result_mode[regno]) != VOIDmode)
9679           {
9680             if (valreg)
9681               abort (); /* HAVE_untyped_call required.  */
9682             valreg = gen_rtx_REG (mode, regno);
9683           }
9684
9685       emit_call_insn (gen_call_value (valreg,
9686                                       gen_rtx_MEM (FUNCTION_MODE, function),
9687                                       const0_rtx, NULL_RTX, const0_rtx));
9688
9689       emit_move_insn (change_address (result, GET_MODE (valreg),
9690                                       XEXP (result, 0)),
9691                       valreg);
9692     }
9693   else
9694 #endif
9695     abort ();
9696
9697   /* Find the CALL insn we just emitted.  */
9698   for (call_insn = get_last_insn ();
9699        call_insn && GET_CODE (call_insn) != CALL_INSN;
9700        call_insn = PREV_INSN (call_insn))
9701     ;
9702
9703   if (! call_insn)
9704     abort ();
9705
9706   /* Put the register usage information on the CALL.  If there is already
9707      some usage information, put ours at the end.  */
9708   if (CALL_INSN_FUNCTION_USAGE (call_insn))
9709     {
9710       rtx link;
9711
9712       for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
9713            link = XEXP (link, 1))
9714         ;
9715
9716       XEXP (link, 1) = call_fusage;
9717     }
9718   else
9719     CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
9720
9721   /* Restore the stack.  */
9722 #ifdef HAVE_save_stack_nonlocal
9723   if (HAVE_save_stack_nonlocal)
9724     emit_stack_restore (SAVE_NONLOCAL, old_stack_level, NULL_RTX);
9725   else
9726 #endif
9727     emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
9728
9729   /* Return the address of the result block.  */
9730   return copy_addr_to_reg (XEXP (result, 0));
9731 }
9732
9733 /* Perform an untyped return.  */
9734
9735 static void
9736 expand_builtin_return (result)
9737      rtx result;
9738 {
9739   int size, align, regno;
9740   enum machine_mode mode;
9741   rtx reg;
9742   rtx call_fusage = 0;
9743
9744   apply_result_size ();
9745   result = gen_rtx_MEM (BLKmode, result);
9746
9747 #ifdef HAVE_untyped_return
9748   if (HAVE_untyped_return)
9749     {
9750       emit_jump_insn (gen_untyped_return (result, result_vector (0, result)));
9751       emit_barrier ();
9752       return;
9753     }
9754 #endif
9755
9756   /* Restore the return value and note that each value is used.  */
9757   size = 0;
9758   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9759     if ((mode = apply_result_mode[regno]) != VOIDmode)
9760       {
9761         align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
9762         if (size % align != 0)
9763           size = CEIL (size, align) * align;
9764         reg = gen_rtx_REG (mode, INCOMING_REGNO (regno));
9765         emit_move_insn (reg,
9766                         change_address (result, mode,
9767                                         plus_constant (XEXP (result, 0),
9768                                                        size)));
9769
9770         push_to_sequence (call_fusage);
9771         emit_insn (gen_rtx_USE (VOIDmode, reg));
9772         call_fusage = get_insns ();
9773         end_sequence ();
9774         size += GET_MODE_SIZE (mode);
9775       }
9776
9777   /* Put the USE insns before the return.  */
9778   emit_insns (call_fusage);
9779
9780   /* Return whatever values was restored by jumping directly to the end
9781      of the function.  */
9782   expand_null_return ();
9783 }
9784 \f
9785 /* Expand code for a post- or pre- increment or decrement
9786    and return the RTX for the result.
9787    POST is 1 for postinc/decrements and 0 for preinc/decrements.  */
9788
9789 static rtx
9790 expand_increment (exp, post, ignore)
9791      register tree exp;
9792      int post, ignore;
9793 {
9794   register rtx op0, op1;
9795   register rtx temp, value;
9796   register tree incremented = TREE_OPERAND (exp, 0);
9797   optab this_optab = add_optab;
9798   int icode;
9799   enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
9800   int op0_is_copy = 0;
9801   int single_insn = 0;
9802   /* 1 means we can't store into OP0 directly,
9803      because it is a subreg narrower than a word,
9804      and we don't dare clobber the rest of the word.  */
9805   int bad_subreg = 0;
9806
9807   /* Stabilize any component ref that might need to be
9808      evaluated more than once below.  */
9809   if (!post
9810       || TREE_CODE (incremented) == BIT_FIELD_REF
9811       || (TREE_CODE (incremented) == COMPONENT_REF
9812           && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
9813               || DECL_BIT_FIELD (TREE_OPERAND (incremented, 1)))))
9814     incremented = stabilize_reference (incremented);
9815   /* Nested *INCREMENT_EXPRs can happen in C++.  We must force innermost
9816      ones into save exprs so that they don't accidentally get evaluated
9817      more than once by the code below.  */
9818   if (TREE_CODE (incremented) == PREINCREMENT_EXPR
9819       || TREE_CODE (incremented) == PREDECREMENT_EXPR)
9820     incremented = save_expr (incremented);
9821
9822   /* Compute the operands as RTX.
9823      Note whether OP0 is the actual lvalue or a copy of it:
9824      I believe it is a copy iff it is a register or subreg
9825      and insns were generated in computing it.   */
9826
9827   temp = get_last_insn ();
9828   op0 = expand_expr (incremented, NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_RW);
9829
9830   /* If OP0 is a SUBREG made for a promoted variable, we cannot increment
9831      in place but instead must do sign- or zero-extension during assignment,
9832      so we copy it into a new register and let the code below use it as
9833      a copy.
9834
9835      Note that we can safely modify this SUBREG since it is know not to be
9836      shared (it was made by the expand_expr call above).  */
9837
9838   if (GET_CODE (op0) == SUBREG && SUBREG_PROMOTED_VAR_P (op0))
9839     {
9840       if (post)
9841         SUBREG_REG (op0) = copy_to_reg (SUBREG_REG (op0));
9842       else
9843         bad_subreg = 1;
9844     }
9845   else if (GET_CODE (op0) == SUBREG
9846            && GET_MODE_BITSIZE (GET_MODE (op0)) < BITS_PER_WORD)
9847     {
9848       /* We cannot increment this SUBREG in place.  If we are
9849          post-incrementing, get a copy of the old value.  Otherwise,
9850          just mark that we cannot increment in place.  */
9851       if (post)
9852         op0 = copy_to_reg (op0);
9853       else
9854         bad_subreg = 1;
9855     }
9856
9857   op0_is_copy = ((GET_CODE (op0) == SUBREG || GET_CODE (op0) == REG)
9858                  && temp != get_last_insn ());
9859   op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode,
9860                      EXPAND_MEMORY_USE_BAD);
9861
9862   /* Decide whether incrementing or decrementing.  */
9863   if (TREE_CODE (exp) == POSTDECREMENT_EXPR
9864       || TREE_CODE (exp) == PREDECREMENT_EXPR)
9865     this_optab = sub_optab;
9866
9867   /* Convert decrement by a constant into a negative increment.  */
9868   if (this_optab == sub_optab
9869       && GET_CODE (op1) == CONST_INT)
9870     {
9871       op1 = GEN_INT (- INTVAL (op1));
9872       this_optab = add_optab;
9873     }
9874
9875   /* For a preincrement, see if we can do this with a single instruction.  */
9876   if (!post)
9877     {
9878       icode = (int) this_optab->handlers[(int) mode].insn_code;
9879       if (icode != (int) CODE_FOR_nothing
9880           /* Make sure that OP0 is valid for operands 0 and 1
9881              of the insn we want to queue.  */
9882           && (*insn_operand_predicate[icode][0]) (op0, mode)
9883           && (*insn_operand_predicate[icode][1]) (op0, mode)
9884           && (*insn_operand_predicate[icode][2]) (op1, mode))
9885         single_insn = 1;
9886     }
9887
9888   /* If OP0 is not the actual lvalue, but rather a copy in a register,
9889      then we cannot just increment OP0.  We must therefore contrive to
9890      increment the original value.  Then, for postincrement, we can return
9891      OP0 since it is a copy of the old value.  For preincrement, expand here
9892      unless we can do it with a single insn.
9893
9894      Likewise if storing directly into OP0 would clobber high bits
9895      we need to preserve (bad_subreg).  */
9896   if (op0_is_copy || (!post && !single_insn) || bad_subreg)
9897     {
9898       /* This is the easiest way to increment the value wherever it is.
9899          Problems with multiple evaluation of INCREMENTED are prevented
9900          because either (1) it is a component_ref or preincrement,
9901          in which case it was stabilized above, or (2) it is an array_ref
9902          with constant index in an array in a register, which is
9903          safe to reevaluate.  */
9904       tree newexp = build (((TREE_CODE (exp) == POSTDECREMENT_EXPR
9905                              || TREE_CODE (exp) == PREDECREMENT_EXPR)
9906                             ? MINUS_EXPR : PLUS_EXPR),
9907                            TREE_TYPE (exp),
9908                            incremented,
9909                            TREE_OPERAND (exp, 1));
9910
9911       while (TREE_CODE (incremented) == NOP_EXPR
9912              || TREE_CODE (incremented) == CONVERT_EXPR)
9913         {
9914           newexp = convert (TREE_TYPE (incremented), newexp);
9915           incremented = TREE_OPERAND (incremented, 0);
9916         }
9917
9918       temp = expand_assignment (incremented, newexp, ! post && ! ignore , 0);
9919       return post ? op0 : temp;
9920     }
9921
9922   if (post)
9923     {
9924       /* We have a true reference to the value in OP0.
9925          If there is an insn to add or subtract in this mode, queue it.
9926          Queueing the increment insn avoids the register shuffling
9927          that often results if we must increment now and first save
9928          the old value for subsequent use.  */
9929
9930 #if 0  /* Turned off to avoid making extra insn for indexed memref.  */
9931       op0 = stabilize (op0);
9932 #endif
9933
9934       icode = (int) this_optab->handlers[(int) mode].insn_code;
9935       if (icode != (int) CODE_FOR_nothing
9936           /* Make sure that OP0 is valid for operands 0 and 1
9937              of the insn we want to queue.  */
9938           && (*insn_operand_predicate[icode][0]) (op0, mode)
9939           && (*insn_operand_predicate[icode][1]) (op0, mode))
9940         {
9941           if (! (*insn_operand_predicate[icode][2]) (op1, mode))
9942             op1 = force_reg (mode, op1);
9943
9944           return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
9945         }
9946       if (icode != (int) CODE_FOR_nothing && GET_CODE (op0) == MEM)
9947         {
9948           rtx addr = (general_operand (XEXP (op0, 0), mode)
9949                       ? force_reg (Pmode, XEXP (op0, 0))
9950                       : copy_to_reg (XEXP (op0, 0)));
9951           rtx temp, result;
9952
9953           op0 = change_address (op0, VOIDmode, addr);
9954           temp = force_reg (GET_MODE (op0), op0);
9955           if (! (*insn_operand_predicate[icode][2]) (op1, mode))
9956             op1 = force_reg (mode, op1);
9957
9958           /* The increment queue is LIFO, thus we have to `queue'
9959              the instructions in reverse order.  */
9960           enqueue_insn (op0, gen_move_insn (op0, temp));
9961           result = enqueue_insn (temp, GEN_FCN (icode) (temp, temp, op1));
9962           return result;
9963         }
9964     }
9965
9966   /* Preincrement, or we can't increment with one simple insn.  */
9967   if (post)
9968     /* Save a copy of the value before inc or dec, to return it later.  */
9969     temp = value = copy_to_reg (op0);
9970   else
9971     /* Arrange to return the incremented value.  */
9972     /* Copy the rtx because expand_binop will protect from the queue,
9973        and the results of that would be invalid for us to return
9974        if our caller does emit_queue before using our result.  */
9975     temp = copy_rtx (value = op0);
9976
9977   /* Increment however we can.  */
9978   op1 = expand_binop (mode, this_optab, value, op1,
9979                       flag_check_memory_usage ? NULL_RTX : op0,
9980                       TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
9981   /* Make sure the value is stored into OP0.  */
9982   if (op1 != op0)
9983     emit_move_insn (op0, op1);
9984
9985   return temp;
9986 }
9987 \f
9988 /* Expand all function calls contained within EXP, innermost ones first.
9989    But don't look within expressions that have sequence points.
9990    For each CALL_EXPR, record the rtx for its value
9991    in the CALL_EXPR_RTL field.  */
9992
9993 static void
9994 preexpand_calls (exp)
9995      tree exp;
9996 {
9997   register int nops, i;
9998   int type = TREE_CODE_CLASS (TREE_CODE (exp));
9999
10000   if (! do_preexpand_calls)
10001     return;
10002
10003   /* Only expressions and references can contain calls.  */
10004
10005   if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r')
10006     return;
10007
10008   switch (TREE_CODE (exp))
10009     {
10010     case CALL_EXPR:
10011       /* Do nothing if already expanded.  */
10012       if (CALL_EXPR_RTL (exp) != 0
10013           /* Do nothing if the call returns a variable-sized object.  */
10014           || TREE_CODE (TYPE_SIZE (TREE_TYPE(exp))) != INTEGER_CST
10015           /* Do nothing to built-in functions.  */
10016           || (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
10017               && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
10018                   == FUNCTION_DECL)
10019               && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
10020         return;
10021
10022       CALL_EXPR_RTL (exp) = expand_call (exp, NULL_RTX, 0);
10023       return;
10024
10025     case COMPOUND_EXPR:
10026     case COND_EXPR:
10027     case TRUTH_ANDIF_EXPR:
10028     case TRUTH_ORIF_EXPR:
10029       /* If we find one of these, then we can be sure
10030          the adjust will be done for it (since it makes jumps).
10031          Do it now, so that if this is inside an argument
10032          of a function, we don't get the stack adjustment
10033          after some other args have already been pushed.  */
10034       do_pending_stack_adjust ();
10035       return;
10036
10037     case BLOCK:
10038     case RTL_EXPR:
10039     case WITH_CLEANUP_EXPR:
10040     case CLEANUP_POINT_EXPR:
10041     case TRY_CATCH_EXPR:
10042       return;
10043
10044     case SAVE_EXPR:
10045       if (SAVE_EXPR_RTL (exp) != 0)
10046         return;
10047       
10048     default:
10049       break;
10050     }
10051
10052   nops = tree_code_length[(int) TREE_CODE (exp)];
10053   for (i = 0; i < nops; i++)
10054     if (TREE_OPERAND (exp, i) != 0)
10055       {
10056         type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
10057         if (type == 'e' || type == '<' || type == '1' || type == '2'
10058             || type == 'r')
10059           preexpand_calls (TREE_OPERAND (exp, i));
10060       }
10061 }
10062 \f
10063 /* At the start of a function, record that we have no previously-pushed
10064    arguments waiting to be popped.  */
10065
10066 void
10067 init_pending_stack_adjust ()
10068 {
10069   pending_stack_adjust = 0;
10070 }
10071
10072 /* When exiting from function, if safe, clear out any pending stack adjust
10073    so the adjustment won't get done.
10074
10075    Note, if the current function calls alloca, then it must have a
10076    frame pointer regardless of the value of flag_omit_frame_pointer.  */
10077
10078 void
10079 clear_pending_stack_adjust ()
10080 {
10081 #ifdef EXIT_IGNORE_STACK
10082   if (optimize > 0
10083       && (! flag_omit_frame_pointer || current_function_calls_alloca)
10084       && EXIT_IGNORE_STACK
10085       && ! (DECL_INLINE (current_function_decl) && ! flag_no_inline)
10086       && ! flag_inline_functions)
10087     pending_stack_adjust = 0;
10088 #endif
10089 }
10090
10091 /* Pop any previously-pushed arguments that have not been popped yet.  */
10092
10093 void
10094 do_pending_stack_adjust ()
10095 {
10096   if (inhibit_defer_pop == 0)
10097     {
10098       if (pending_stack_adjust != 0)
10099         adjust_stack (GEN_INT (pending_stack_adjust));
10100       pending_stack_adjust = 0;
10101     }
10102 }
10103 \f
10104 /* Expand conditional expressions.  */
10105
10106 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
10107    LABEL is an rtx of code CODE_LABEL, in this function and all the
10108    functions here.  */
10109
10110 void
10111 jumpifnot (exp, label)
10112      tree exp;
10113      rtx label;
10114 {
10115   do_jump (exp, label, NULL_RTX);
10116 }
10117
10118 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero.  */
10119
10120 void
10121 jumpif (exp, label)
10122      tree exp;
10123      rtx label;
10124 {
10125   do_jump (exp, NULL_RTX, label);
10126 }
10127
10128 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
10129    the result is zero, or IF_TRUE_LABEL if the result is one.
10130    Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
10131    meaning fall through in that case.
10132
10133    do_jump always does any pending stack adjust except when it does not
10134    actually perform a jump.  An example where there is no jump
10135    is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
10136
10137    This function is responsible for optimizing cases such as
10138    &&, || and comparison operators in EXP.  */
10139
10140 void
10141 do_jump (exp, if_false_label, if_true_label)
10142      tree exp;
10143      rtx if_false_label, if_true_label;
10144 {
10145   register enum tree_code code = TREE_CODE (exp);
10146   /* Some cases need to create a label to jump to
10147      in order to properly fall through.
10148      These cases set DROP_THROUGH_LABEL nonzero.  */
10149   rtx drop_through_label = 0;
10150   rtx temp;
10151   rtx comparison = 0;
10152   int i;
10153   tree type;
10154   enum machine_mode mode;
10155
10156 #ifdef MAX_INTEGER_COMPUTATION_MODE
10157   check_max_integer_computation_mode (exp);
10158 #endif
10159
10160   emit_queue ();
10161
10162   switch (code)
10163     {
10164     case ERROR_MARK:
10165       break;
10166
10167     case INTEGER_CST:
10168       temp = integer_zerop (exp) ? if_false_label : if_true_label;
10169       if (temp)
10170         emit_jump (temp);
10171       break;
10172
10173 #if 0
10174       /* This is not true with #pragma weak  */
10175     case ADDR_EXPR:
10176       /* The address of something can never be zero.  */
10177       if (if_true_label)
10178         emit_jump (if_true_label);
10179       break;
10180 #endif
10181
10182     case NOP_EXPR:
10183       if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
10184           || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
10185           || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF)
10186         goto normal;
10187     case CONVERT_EXPR:
10188       /* If we are narrowing the operand, we have to do the compare in the
10189          narrower mode.  */
10190       if ((TYPE_PRECISION (TREE_TYPE (exp))
10191            < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
10192         goto normal;
10193     case NON_LVALUE_EXPR:
10194     case REFERENCE_EXPR:
10195     case ABS_EXPR:
10196     case NEGATE_EXPR:
10197     case LROTATE_EXPR:
10198     case RROTATE_EXPR:
10199       /* These cannot change zero->non-zero or vice versa.  */
10200       do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
10201       break;
10202
10203 #if 0
10204       /* This is never less insns than evaluating the PLUS_EXPR followed by
10205          a test and can be longer if the test is eliminated.  */
10206     case PLUS_EXPR:
10207       /* Reduce to minus.  */
10208       exp = build (MINUS_EXPR, TREE_TYPE (exp),
10209                    TREE_OPERAND (exp, 0),
10210                    fold (build1 (NEGATE_EXPR, TREE_TYPE (TREE_OPERAND (exp, 1)),
10211                                  TREE_OPERAND (exp, 1))));
10212       /* Process as MINUS.  */
10213 #endif
10214
10215     case MINUS_EXPR:
10216       /* Non-zero iff operands of minus differ.  */
10217       comparison = compare (build (NE_EXPR, TREE_TYPE (exp),
10218                                    TREE_OPERAND (exp, 0),
10219                                    TREE_OPERAND (exp, 1)),
10220                             NE, NE);
10221       break;
10222
10223     case BIT_AND_EXPR:
10224       /* If we are AND'ing with a small constant, do this comparison in the
10225          smallest type that fits.  If the machine doesn't have comparisons
10226          that small, it will be converted back to the wider comparison.
10227          This helps if we are testing the sign bit of a narrower object.
10228          combine can't do this for us because it can't know whether a
10229          ZERO_EXTRACT or a compare in a smaller mode exists, but we do.  */
10230
10231       if (! SLOW_BYTE_ACCESS
10232           && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
10233           && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
10234           && (i = floor_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)))) >= 0
10235           && (mode = mode_for_size (i + 1, MODE_INT, 0)) != BLKmode
10236           && (type = type_for_mode (mode, 1)) != 0
10237           && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
10238           && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
10239               != CODE_FOR_nothing))
10240         {
10241           do_jump (convert (type, exp), if_false_label, if_true_label);
10242           break;
10243         }
10244       goto normal;
10245
10246     case TRUTH_NOT_EXPR:
10247       do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
10248       break;
10249
10250     case TRUTH_ANDIF_EXPR:
10251       if (if_false_label == 0)
10252         if_false_label = drop_through_label = gen_label_rtx ();
10253       do_jump (TREE_OPERAND (exp, 0), if_false_label, NULL_RTX);
10254       start_cleanup_deferral ();
10255       do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
10256       end_cleanup_deferral ();
10257       break;
10258
10259     case TRUTH_ORIF_EXPR:
10260       if (if_true_label == 0)
10261         if_true_label = drop_through_label = gen_label_rtx ();
10262       do_jump (TREE_OPERAND (exp, 0), NULL_RTX, if_true_label);
10263       start_cleanup_deferral ();
10264       do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
10265       end_cleanup_deferral ();
10266       break;
10267
10268     case COMPOUND_EXPR:
10269       push_temp_slots ();
10270       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
10271       preserve_temp_slots (NULL_RTX);
10272       free_temp_slots ();
10273       pop_temp_slots ();
10274       emit_queue ();
10275       do_pending_stack_adjust ();
10276       do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
10277       break;
10278
10279     case COMPONENT_REF:
10280     case BIT_FIELD_REF:
10281     case ARRAY_REF:
10282       {
10283         int bitsize, bitpos, unsignedp;
10284         enum machine_mode mode;
10285         tree type;
10286         tree offset;
10287         int volatilep = 0;
10288         int alignment;
10289
10290         /* Get description of this reference.  We don't actually care
10291            about the underlying object here.  */
10292         get_inner_reference (exp, &bitsize, &bitpos, &offset,
10293                              &mode, &unsignedp, &volatilep,
10294                              &alignment);
10295
10296         type = type_for_size (bitsize, unsignedp);
10297         if (! SLOW_BYTE_ACCESS
10298             && type != 0 && bitsize >= 0
10299             && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
10300             && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
10301                 != CODE_FOR_nothing))
10302           {
10303             do_jump (convert (type, exp), if_false_label, if_true_label);
10304             break;
10305           }
10306         goto normal;
10307       }
10308
10309     case COND_EXPR:
10310       /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases.  */
10311       if (integer_onep (TREE_OPERAND (exp, 1))
10312           && integer_zerop (TREE_OPERAND (exp, 2)))
10313         do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
10314
10315       else if (integer_zerop (TREE_OPERAND (exp, 1))
10316                && integer_onep (TREE_OPERAND (exp, 2)))
10317         do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
10318
10319       else
10320         {
10321           register rtx label1 = gen_label_rtx ();
10322           drop_through_label = gen_label_rtx ();
10323
10324           do_jump (TREE_OPERAND (exp, 0), label1, NULL_RTX);
10325
10326           start_cleanup_deferral ();
10327           /* Now the THEN-expression.  */
10328           do_jump (TREE_OPERAND (exp, 1),
10329                    if_false_label ? if_false_label : drop_through_label,
10330                    if_true_label ? if_true_label : drop_through_label);
10331           /* In case the do_jump just above never jumps.  */
10332           do_pending_stack_adjust ();
10333           emit_label (label1);
10334
10335           /* Now the ELSE-expression.  */
10336           do_jump (TREE_OPERAND (exp, 2),
10337                    if_false_label ? if_false_label : drop_through_label,
10338                    if_true_label ? if_true_label : drop_through_label);
10339           end_cleanup_deferral ();
10340         }
10341       break;
10342
10343     case EQ_EXPR:
10344       {
10345         tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10346
10347         if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
10348             || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
10349           {
10350             tree exp0 = save_expr (TREE_OPERAND (exp, 0));
10351             tree exp1 = save_expr (TREE_OPERAND (exp, 1));
10352             do_jump
10353               (fold
10354                (build (TRUTH_ANDIF_EXPR, TREE_TYPE (exp),
10355                        fold (build (EQ_EXPR, TREE_TYPE (exp),
10356                                     fold (build1 (REALPART_EXPR,
10357                                                   TREE_TYPE (inner_type),
10358                                                   exp0)),
10359                                     fold (build1 (REALPART_EXPR,
10360                                                   TREE_TYPE (inner_type),
10361                                                   exp1)))),
10362                        fold (build (EQ_EXPR, TREE_TYPE (exp),
10363                                     fold (build1 (IMAGPART_EXPR,
10364                                                   TREE_TYPE (inner_type),
10365                                                   exp0)),
10366                                     fold (build1 (IMAGPART_EXPR,
10367                                                   TREE_TYPE (inner_type),
10368                                                   exp1)))))),
10369                if_false_label, if_true_label);
10370           }
10371
10372         else if (integer_zerop (TREE_OPERAND (exp, 1)))
10373           do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
10374
10375         else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
10376                  && !can_compare_p (TYPE_MODE (inner_type)))
10377           do_jump_by_parts_equality (exp, if_false_label, if_true_label);
10378         else
10379           comparison = compare (exp, EQ, EQ);
10380         break;
10381       }
10382
10383     case NE_EXPR:
10384       {
10385         tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10386
10387         if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
10388             || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
10389           {
10390             tree exp0 = save_expr (TREE_OPERAND (exp, 0));
10391             tree exp1 = save_expr (TREE_OPERAND (exp, 1));
10392             do_jump
10393               (fold
10394                (build (TRUTH_ORIF_EXPR, TREE_TYPE (exp),
10395                        fold (build (NE_EXPR, TREE_TYPE (exp),
10396                                     fold (build1 (REALPART_EXPR,
10397                                                   TREE_TYPE (inner_type),
10398                                                   exp0)),
10399                                     fold (build1 (REALPART_EXPR,
10400                                                   TREE_TYPE (inner_type),
10401                                                   exp1)))),
10402                        fold (build (NE_EXPR, TREE_TYPE (exp),
10403                                     fold (build1 (IMAGPART_EXPR,
10404                                                   TREE_TYPE (inner_type),
10405                                                   exp0)),
10406                                     fold (build1 (IMAGPART_EXPR,
10407                                                   TREE_TYPE (inner_type),
10408                                                   exp1)))))),
10409                if_false_label, if_true_label);
10410           }
10411
10412         else if (integer_zerop (TREE_OPERAND (exp, 1)))
10413           do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
10414
10415         else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
10416                  && !can_compare_p (TYPE_MODE (inner_type)))
10417           do_jump_by_parts_equality (exp, if_true_label, if_false_label);
10418         else
10419           comparison = compare (exp, NE, NE);
10420         break;
10421       }
10422
10423     case LT_EXPR:
10424       if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10425            == MODE_INT)
10426           && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
10427         do_jump_by_parts_greater (exp, 1, if_false_label, if_true_label);
10428       else
10429         comparison = compare (exp, LT, LTU);
10430       break;
10431
10432     case LE_EXPR:
10433       if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10434            == MODE_INT)
10435           && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
10436         do_jump_by_parts_greater (exp, 0, if_true_label, if_false_label);
10437       else
10438         comparison = compare (exp, LE, LEU);
10439       break;
10440
10441     case GT_EXPR:
10442       if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10443            == MODE_INT)
10444           && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
10445         do_jump_by_parts_greater (exp, 0, if_false_label, if_true_label);
10446       else
10447         comparison = compare (exp, GT, GTU);
10448       break;
10449
10450     case GE_EXPR:
10451       if ((GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10452            == MODE_INT)
10453           && !can_compare_p (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
10454         do_jump_by_parts_greater (exp, 1, if_true_label, if_false_label);
10455       else
10456         comparison = compare (exp, GE, GEU);
10457       break;
10458
10459     default:
10460     normal:
10461       temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
10462 #if 0
10463       /* This is not needed any more and causes poor code since it causes
10464          comparisons and tests from non-SI objects to have different code
10465          sequences.  */
10466       /* Copy to register to avoid generating bad insns by cse
10467          from (set (mem ...) (arithop))  (set (cc0) (mem ...)).  */
10468       if (!cse_not_expected && GET_CODE (temp) == MEM)
10469         temp = copy_to_reg (temp);
10470 #endif
10471       do_pending_stack_adjust ();
10472       if (GET_CODE (temp) == CONST_INT)
10473         comparison = (temp == const0_rtx ? const0_rtx : const_true_rtx);
10474       else if (GET_CODE (temp) == LABEL_REF)
10475         comparison = const_true_rtx;
10476       else if (GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
10477                && !can_compare_p (GET_MODE (temp)))
10478         /* Note swapping the labels gives us not-equal.  */
10479         do_jump_by_parts_equality_rtx (temp, if_true_label, if_false_label);
10480       else if (GET_MODE (temp) != VOIDmode)
10481         comparison = compare_from_rtx (temp, CONST0_RTX (GET_MODE (temp)),
10482                                        NE, TREE_UNSIGNED (TREE_TYPE (exp)),
10483                                        GET_MODE (temp), NULL_RTX, 0);
10484       else
10485         abort ();
10486     }
10487
10488   /* Do any postincrements in the expression that was tested.  */
10489   emit_queue ();
10490
10491   /* If COMPARISON is nonzero here, it is an rtx that can be substituted
10492      straight into a conditional jump instruction as the jump condition.
10493      Otherwise, all the work has been done already.  */
10494
10495   if (comparison == const_true_rtx)
10496     {
10497       if (if_true_label)
10498         emit_jump (if_true_label);
10499     }
10500   else if (comparison == const0_rtx)
10501     {
10502       if (if_false_label)
10503         emit_jump (if_false_label);
10504     }
10505   else if (comparison)
10506     do_jump_for_compare (comparison, if_false_label, if_true_label);
10507
10508   if (drop_through_label)
10509     {
10510       /* If do_jump produces code that might be jumped around,
10511          do any stack adjusts from that code, before the place
10512          where control merges in.  */
10513       do_pending_stack_adjust ();
10514       emit_label (drop_through_label);
10515     }
10516 }
10517 \f
10518 /* Given a comparison expression EXP for values too wide to be compared
10519    with one insn, test the comparison and jump to the appropriate label.
10520    The code of EXP is ignored; we always test GT if SWAP is 0,
10521    and LT if SWAP is 1.  */
10522
10523 static void
10524 do_jump_by_parts_greater (exp, swap, if_false_label, if_true_label)
10525      tree exp;
10526      int swap;
10527      rtx if_false_label, if_true_label;
10528 {
10529   rtx op0 = expand_expr (TREE_OPERAND (exp, swap), NULL_RTX, VOIDmode, 0);
10530   rtx op1 = expand_expr (TREE_OPERAND (exp, !swap), NULL_RTX, VOIDmode, 0);
10531   enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10532   int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10533   rtx drop_through_label = 0;
10534   int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
10535   int i;
10536
10537   if (! if_true_label || ! if_false_label)
10538     drop_through_label = gen_label_rtx ();
10539   if (! if_true_label)
10540     if_true_label = drop_through_label;
10541   if (! if_false_label)
10542     if_false_label = drop_through_label;
10543
10544   /* Compare a word at a time, high order first.  */
10545   for (i = 0; i < nwords; i++)
10546     {
10547       rtx comp;
10548       rtx op0_word, op1_word;
10549
10550       if (WORDS_BIG_ENDIAN)
10551         {
10552           op0_word = operand_subword_force (op0, i, mode);
10553           op1_word = operand_subword_force (op1, i, mode);
10554         }
10555       else
10556         {
10557           op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
10558           op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
10559         }
10560
10561       /* All but high-order word must be compared as unsigned.  */
10562       comp = compare_from_rtx (op0_word, op1_word,
10563                                (unsignedp || i > 0) ? GTU : GT,
10564                                unsignedp, word_mode, NULL_RTX, 0);
10565       if (comp == const_true_rtx)
10566         emit_jump (if_true_label);
10567       else if (comp != const0_rtx)
10568         do_jump_for_compare (comp, NULL_RTX, if_true_label);
10569
10570       /* Consider lower words only if these are equal.  */
10571       comp = compare_from_rtx (op0_word, op1_word, NE, unsignedp, word_mode,
10572                                NULL_RTX, 0);
10573       if (comp == const_true_rtx)
10574         emit_jump (if_false_label);
10575       else if (comp != const0_rtx)
10576         do_jump_for_compare (comp, NULL_RTX, if_false_label);
10577     }
10578
10579   if (if_false_label)
10580     emit_jump (if_false_label);
10581   if (drop_through_label)
10582     emit_label (drop_through_label);
10583 }
10584
10585 /* Compare OP0 with OP1, word at a time, in mode MODE.
10586    UNSIGNEDP says to do unsigned comparison.
10587    Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise.  */
10588
10589 void
10590 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label, if_true_label)
10591      enum machine_mode mode;
10592      int unsignedp;
10593      rtx op0, op1;
10594      rtx if_false_label, if_true_label;
10595 {
10596   int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10597   rtx drop_through_label = 0;
10598   int i;
10599
10600   if (! if_true_label || ! if_false_label)
10601     drop_through_label = gen_label_rtx ();
10602   if (! if_true_label)
10603     if_true_label = drop_through_label;
10604   if (! if_false_label)
10605     if_false_label = drop_through_label;
10606
10607   /* Compare a word at a time, high order first.  */
10608   for (i = 0; i < nwords; i++)
10609     {
10610       rtx comp;
10611       rtx op0_word, op1_word;
10612
10613       if (WORDS_BIG_ENDIAN)
10614         {
10615           op0_word = operand_subword_force (op0, i, mode);
10616           op1_word = operand_subword_force (op1, i, mode);
10617         }
10618       else
10619         {
10620           op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
10621           op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
10622         }
10623
10624       /* All but high-order word must be compared as unsigned.  */
10625       comp = compare_from_rtx (op0_word, op1_word,
10626                                (unsignedp || i > 0) ? GTU : GT,
10627                                unsignedp, word_mode, NULL_RTX, 0);
10628       if (comp == const_true_rtx)
10629         emit_jump (if_true_label);
10630       else if (comp != const0_rtx)
10631         do_jump_for_compare (comp, NULL_RTX, if_true_label);
10632
10633       /* Consider lower words only if these are equal.  */
10634       comp = compare_from_rtx (op0_word, op1_word, NE, unsignedp, word_mode,
10635                                NULL_RTX, 0);
10636       if (comp == const_true_rtx)
10637         emit_jump (if_false_label);
10638       else if (comp != const0_rtx)
10639         do_jump_for_compare (comp, NULL_RTX, if_false_label);
10640     }
10641
10642   if (if_false_label)
10643     emit_jump (if_false_label);
10644   if (drop_through_label)
10645     emit_label (drop_through_label);
10646 }
10647
10648 /* Given an EQ_EXPR expression EXP for values too wide to be compared
10649    with one insn, test the comparison and jump to the appropriate label.  */
10650
10651 static void
10652 do_jump_by_parts_equality (exp, if_false_label, if_true_label)
10653      tree exp;
10654      rtx if_false_label, if_true_label;
10655 {
10656   rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10657   rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10658   enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10659   int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10660   int i;
10661   rtx drop_through_label = 0;
10662
10663   if (! if_false_label)
10664     drop_through_label = if_false_label = gen_label_rtx ();
10665
10666   for (i = 0; i < nwords; i++)
10667     {
10668       rtx comp = compare_from_rtx (operand_subword_force (op0, i, mode),
10669                                    operand_subword_force (op1, i, mode),
10670                                    EQ, TREE_UNSIGNED (TREE_TYPE (exp)),
10671                                    word_mode, NULL_RTX, 0);
10672       if (comp == const_true_rtx)
10673         emit_jump (if_false_label);
10674       else if (comp != const0_rtx)
10675         do_jump_for_compare (comp, if_false_label, NULL_RTX);
10676     }
10677
10678   if (if_true_label)
10679     emit_jump (if_true_label);
10680   if (drop_through_label)
10681     emit_label (drop_through_label);
10682 }
10683 \f
10684 /* Jump according to whether OP0 is 0.
10685    We assume that OP0 has an integer mode that is too wide
10686    for the available compare insns.  */
10687
10688 void
10689 do_jump_by_parts_equality_rtx (op0, if_false_label, if_true_label)
10690      rtx op0;
10691      rtx if_false_label, if_true_label;
10692 {
10693   int nwords = GET_MODE_SIZE (GET_MODE (op0)) / UNITS_PER_WORD;
10694   rtx part;
10695   int i;
10696   rtx drop_through_label = 0;
10697
10698   /* The fastest way of doing this comparison on almost any machine is to
10699      "or" all the words and compare the result.  If all have to be loaded
10700      from memory and this is a very wide item, it's possible this may
10701      be slower, but that's highly unlikely.  */
10702
10703   part = gen_reg_rtx (word_mode);
10704   emit_move_insn (part, operand_subword_force (op0, 0, GET_MODE (op0)));
10705   for (i = 1; i < nwords && part != 0; i++)
10706     part = expand_binop (word_mode, ior_optab, part,
10707                          operand_subword_force (op0, i, GET_MODE (op0)),
10708                          part, 1, OPTAB_WIDEN);
10709
10710   if (part != 0)
10711     {
10712       rtx comp = compare_from_rtx (part, const0_rtx, EQ, 1, word_mode,
10713                                    NULL_RTX, 0);
10714
10715       if (comp == const_true_rtx)
10716         emit_jump (if_false_label);
10717       else if (comp == const0_rtx)
10718         emit_jump (if_true_label);
10719       else
10720         do_jump_for_compare (comp, if_false_label, if_true_label);
10721
10722       return;
10723     }
10724
10725   /* If we couldn't do the "or" simply, do this with a series of compares.  */
10726   if (! if_false_label)
10727     drop_through_label = if_false_label = gen_label_rtx ();
10728
10729   for (i = 0; i < nwords; i++)
10730     {
10731       rtx comp = compare_from_rtx (operand_subword_force (op0, i,
10732                                                           GET_MODE (op0)),
10733                                    const0_rtx, EQ, 1, word_mode, NULL_RTX, 0);
10734       if (comp == const_true_rtx)
10735         emit_jump (if_false_label);
10736       else if (comp != const0_rtx)
10737         do_jump_for_compare (comp, if_false_label, NULL_RTX);
10738     }
10739
10740   if (if_true_label)
10741     emit_jump (if_true_label);
10742
10743   if (drop_through_label)
10744     emit_label (drop_through_label);
10745 }
10746
10747 /* Given a comparison expression in rtl form, output conditional branches to
10748    IF_TRUE_LABEL, IF_FALSE_LABEL, or both.  */
10749
10750 static void
10751 do_jump_for_compare (comparison, if_false_label, if_true_label)
10752      rtx comparison, if_false_label, if_true_label;
10753 {
10754   if (if_true_label)
10755     {
10756       if (bcc_gen_fctn[(int) GET_CODE (comparison)] != 0)
10757         emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (comparison)]) (if_true_label));
10758       else
10759         abort ();
10760
10761       if (if_false_label)
10762         emit_jump (if_false_label);
10763     }
10764   else if (if_false_label)
10765     {
10766       rtx insn;
10767       rtx prev = get_last_insn ();
10768       rtx branch = 0;
10769
10770       /* Output the branch with the opposite condition.  Then try to invert
10771          what is generated.  If more than one insn is a branch, or if the
10772          branch is not the last insn written, abort. If we can't invert
10773          the branch, emit make a true label, redirect this jump to that,
10774          emit a jump to the false label and define the true label.  */
10775
10776       if (bcc_gen_fctn[(int) GET_CODE (comparison)] != 0)
10777         emit_jump_insn ((*bcc_gen_fctn[(int) GET_CODE (comparison)])(if_false_label));
10778       else
10779         abort ();
10780
10781       /* Here we get the first insn that was just emitted.  It used to be  the
10782          case that, on some machines, emitting the branch would discard
10783          the previous compare insn and emit a replacement.  This isn't
10784          done anymore, but abort if we see that PREV is deleted.  */
10785
10786       if (prev == 0)
10787         insn = get_insns ();
10788       else if (INSN_DELETED_P (prev))
10789         abort ();
10790       else
10791         insn = NEXT_INSN (prev);
10792
10793       for (; insn; insn = NEXT_INSN (insn))
10794         if (GET_CODE (insn) == JUMP_INSN)
10795           {
10796             if (branch)
10797               abort ();
10798             branch = insn;
10799           }
10800
10801       if (branch != get_last_insn ())
10802         abort ();
10803
10804       JUMP_LABEL (branch) = if_false_label;
10805       if (! invert_jump (branch, if_false_label))
10806         {
10807           if_true_label = gen_label_rtx ();
10808           redirect_jump (branch, if_true_label);
10809           emit_jump (if_false_label);
10810           emit_label (if_true_label);
10811         }
10812     }
10813 }
10814 \f
10815 /* Generate code for a comparison expression EXP
10816    (including code to compute the values to be compared)
10817    and set (CC0) according to the result.
10818    SIGNED_CODE should be the rtx operation for this comparison for
10819    signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
10820
10821    We force a stack adjustment unless there are currently
10822    things pushed on the stack that aren't yet used.  */
10823
10824 static rtx
10825 compare (exp, signed_code, unsigned_code)
10826      register tree exp;
10827      enum rtx_code signed_code, unsigned_code;
10828 {
10829   register rtx op0
10830     = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10831   register rtx op1
10832     = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10833   register tree type = TREE_TYPE (TREE_OPERAND (exp, 0));
10834   register enum machine_mode mode = TYPE_MODE (type);
10835   int unsignedp = TREE_UNSIGNED (type);
10836   enum rtx_code code = unsignedp ? unsigned_code : signed_code;
10837
10838 #ifdef HAVE_canonicalize_funcptr_for_compare
10839   /* If function pointers need to be "canonicalized" before they can
10840      be reliably compared, then canonicalize them.  */
10841   if (HAVE_canonicalize_funcptr_for_compare
10842       && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
10843       && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10844           == FUNCTION_TYPE))
10845     {
10846       rtx new_op0 = gen_reg_rtx (mode);
10847
10848       emit_insn (gen_canonicalize_funcptr_for_compare (new_op0, op0));
10849       op0 = new_op0;
10850     }
10851
10852   if (HAVE_canonicalize_funcptr_for_compare
10853       && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
10854       && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
10855           == FUNCTION_TYPE))
10856     {
10857       rtx new_op1 = gen_reg_rtx (mode);
10858
10859       emit_insn (gen_canonicalize_funcptr_for_compare (new_op1, op1));
10860       op1 = new_op1;
10861     }
10862 #endif
10863
10864   return compare_from_rtx (op0, op1, code, unsignedp, mode,
10865                            ((mode == BLKmode)
10866                             ? expr_size (TREE_OPERAND (exp, 0)) : NULL_RTX),
10867                            TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
10868 }
10869
10870 /* Like compare but expects the values to compare as two rtx's.
10871    The decision as to signed or unsigned comparison must be made by the caller.
10872
10873    If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
10874    compared.
10875
10876    If ALIGN is non-zero, it is the alignment of this type; if zero, the
10877    size of MODE should be used.  */
10878
10879 rtx
10880 compare_from_rtx (op0, op1, code, unsignedp, mode, size, align)
10881      register rtx op0, op1;
10882      enum rtx_code code;
10883      int unsignedp;
10884      enum machine_mode mode;
10885      rtx size;
10886      int align;
10887 {
10888   rtx tem;
10889
10890   /* If one operand is constant, make it the second one.  Only do this
10891      if the other operand is not constant as well.  */
10892
10893   if ((CONSTANT_P (op0) && ! CONSTANT_P (op1))
10894       || (GET_CODE (op0) == CONST_INT && GET_CODE (op1) != CONST_INT))
10895     {
10896       tem = op0;
10897       op0 = op1;
10898       op1 = tem;
10899       code = swap_condition (code);
10900     }
10901
10902   if (flag_force_mem)
10903     {
10904       op0 = force_not_mem (op0);
10905       op1 = force_not_mem (op1);
10906     }
10907
10908   do_pending_stack_adjust ();
10909
10910   if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT
10911       && (tem = simplify_relational_operation (code, mode, op0, op1)) != 0)
10912     return tem;
10913
10914 #if 0
10915   /* There's no need to do this now that combine.c can eliminate lots of
10916      sign extensions.  This can be less efficient in certain cases on other
10917      machines.  */
10918
10919   /* If this is a signed equality comparison, we can do it as an
10920      unsigned comparison since zero-extension is cheaper than sign
10921      extension and comparisons with zero are done as unsigned.  This is
10922      the case even on machines that can do fast sign extension, since
10923      zero-extension is easier to combine with other operations than
10924      sign-extension is.  If we are comparing against a constant, we must
10925      convert it to what it would look like unsigned.  */
10926   if ((code == EQ || code == NE) && ! unsignedp
10927       && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
10928     {
10929       if (GET_CODE (op1) == CONST_INT
10930           && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
10931         op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
10932       unsignedp = 1;
10933     }
10934 #endif
10935         
10936   emit_cmp_insn (op0, op1, code, size, mode, unsignedp, align);
10937
10938   return gen_rtx_fmt_ee (code, VOIDmode, cc0_rtx, const0_rtx);
10939 }
10940 \f
10941 /* Generate code to calculate EXP using a store-flag instruction
10942    and return an rtx for the result.  EXP is either a comparison
10943    or a TRUTH_NOT_EXPR whose operand is a comparison.
10944
10945    If TARGET is nonzero, store the result there if convenient.
10946
10947    If ONLY_CHEAP is non-zero, only do this if it is likely to be very
10948    cheap.
10949
10950    Return zero if there is no suitable set-flag instruction
10951    available on this machine.
10952
10953    Once expand_expr has been called on the arguments of the comparison,
10954    we are committed to doing the store flag, since it is not safe to
10955    re-evaluate the expression.  We emit the store-flag insn by calling
10956    emit_store_flag, but only expand the arguments if we have a reason
10957    to believe that emit_store_flag will be successful.  If we think that
10958    it will, but it isn't, we have to simulate the store-flag with a
10959    set/jump/set sequence.  */
10960
10961 static rtx
10962 do_store_flag (exp, target, mode, only_cheap)
10963      tree exp;
10964      rtx target;
10965      enum machine_mode mode;
10966      int only_cheap;
10967 {
10968   enum rtx_code code;
10969   tree arg0, arg1, type;
10970   tree tem;
10971   enum machine_mode operand_mode;
10972   int invert = 0;
10973   int unsignedp;
10974   rtx op0, op1;
10975   enum insn_code icode;
10976   rtx subtarget = target;
10977   rtx result, label;
10978
10979   /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
10980      result at the end.  We can't simply invert the test since it would
10981      have already been inverted if it were valid.  This case occurs for
10982      some floating-point comparisons.  */
10983
10984   if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
10985     invert = 1, exp = TREE_OPERAND (exp, 0);
10986
10987   arg0 = TREE_OPERAND (exp, 0);
10988   arg1 = TREE_OPERAND (exp, 1);
10989   type = TREE_TYPE (arg0);
10990   operand_mode = TYPE_MODE (type);
10991   unsignedp = TREE_UNSIGNED (type);
10992
10993   /* We won't bother with BLKmode store-flag operations because it would mean
10994      passing a lot of information to emit_store_flag.  */
10995   if (operand_mode == BLKmode)
10996     return 0;
10997
10998   /* We won't bother with store-flag operations involving function pointers
10999      when function pointers must be canonicalized before comparisons.  */
11000 #ifdef HAVE_canonicalize_funcptr_for_compare
11001   if (HAVE_canonicalize_funcptr_for_compare
11002       && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
11003            && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
11004                == FUNCTION_TYPE))
11005           || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
11006               && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
11007                   == FUNCTION_TYPE))))
11008     return 0;
11009 #endif
11010
11011   STRIP_NOPS (arg0);
11012   STRIP_NOPS (arg1);
11013
11014   /* Get the rtx comparison code to use.  We know that EXP is a comparison
11015      operation of some type.  Some comparisons against 1 and -1 can be
11016      converted to comparisons with zero.  Do so here so that the tests
11017      below will be aware that we have a comparison with zero.   These
11018      tests will not catch constants in the first operand, but constants
11019      are rarely passed as the first operand.  */
11020
11021   switch (TREE_CODE (exp))
11022     {
11023     case EQ_EXPR:
11024       code = EQ;
11025       break;
11026     case NE_EXPR:
11027       code = NE;
11028       break;
11029     case LT_EXPR:
11030       if (integer_onep (arg1))
11031         arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
11032       else
11033         code = unsignedp ? LTU : LT;
11034       break;
11035     case LE_EXPR:
11036       if (! unsignedp && integer_all_onesp (arg1))
11037         arg1 = integer_zero_node, code = LT;
11038       else
11039         code = unsignedp ? LEU : LE;
11040       break;
11041     case GT_EXPR:
11042       if (! unsignedp && integer_all_onesp (arg1))
11043         arg1 = integer_zero_node, code = GE;
11044       else
11045         code = unsignedp ? GTU : GT;
11046       break;
11047     case GE_EXPR:
11048       if (integer_onep (arg1))
11049         arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
11050       else
11051         code = unsignedp ? GEU : GE;
11052       break;
11053     default:
11054       abort ();
11055     }
11056
11057   /* Put a constant second.  */
11058   if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
11059     {
11060       tem = arg0; arg0 = arg1; arg1 = tem;
11061       code = swap_condition (code);
11062     }
11063
11064   /* If this is an equality or inequality test of a single bit, we can
11065      do this by shifting the bit being tested to the low-order bit and
11066      masking the result with the constant 1.  If the condition was EQ,
11067      we xor it with 1.  This does not require an scc insn and is faster
11068      than an scc insn even if we have it.  */
11069
11070   if ((code == NE || code == EQ)
11071       && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
11072       && integer_pow2p (TREE_OPERAND (arg0, 1)))
11073     {
11074       tree inner = TREE_OPERAND (arg0, 0);
11075       int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
11076       int ops_unsignedp;
11077
11078       /* If INNER is a right shift of a constant and it plus BITNUM does
11079          not overflow, adjust BITNUM and INNER.  */
11080
11081       if (TREE_CODE (inner) == RSHIFT_EXPR
11082           && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
11083           && TREE_INT_CST_HIGH (TREE_OPERAND (inner, 1)) == 0
11084           && (bitnum + TREE_INT_CST_LOW (TREE_OPERAND (inner, 1))
11085               < TYPE_PRECISION (type)))
11086         {
11087           bitnum += TREE_INT_CST_LOW (TREE_OPERAND (inner, 1));
11088           inner = TREE_OPERAND (inner, 0);
11089         }
11090
11091       /* If we are going to be able to omit the AND below, we must do our
11092          operations as unsigned.  If we must use the AND, we have a choice.
11093          Normally unsigned is faster, but for some machines signed is.  */
11094       ops_unsignedp = (bitnum == TYPE_PRECISION (type) - 1 ? 1
11095 #ifdef LOAD_EXTEND_OP
11096                        : (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND ? 0 : 1)
11097 #else
11098                        : 1
11099 #endif
11100                        );
11101
11102       if (subtarget == 0 || GET_CODE (subtarget) != REG
11103           || GET_MODE (subtarget) != operand_mode
11104           || ! safe_from_p (subtarget, inner, 1))
11105         subtarget = 0;
11106
11107       op0 = expand_expr (inner, subtarget, VOIDmode, 0);
11108
11109       if (bitnum != 0)
11110         op0 = expand_shift (RSHIFT_EXPR, GET_MODE (op0), op0,
11111                             size_int (bitnum), subtarget, ops_unsignedp);
11112
11113       if (GET_MODE (op0) != mode)
11114         op0 = convert_to_mode (mode, op0, ops_unsignedp);
11115
11116       if ((code == EQ && ! invert) || (code == NE && invert))
11117         op0 = expand_binop (mode, xor_optab, op0, const1_rtx, subtarget,
11118                             ops_unsignedp, OPTAB_LIB_WIDEN);
11119
11120       /* Put the AND last so it can combine with more things.  */
11121       if (bitnum != TYPE_PRECISION (type) - 1)
11122         op0 = expand_and (op0, const1_rtx, subtarget);
11123
11124       return op0;
11125     }
11126
11127   /* Now see if we are likely to be able to do this.  Return if not.  */
11128   if (! can_compare_p (operand_mode))
11129     return 0;
11130   icode = setcc_gen_code[(int) code];
11131   if (icode == CODE_FOR_nothing
11132       || (only_cheap && insn_operand_mode[(int) icode][0] != mode))
11133     {
11134       /* We can only do this if it is one of the special cases that
11135          can be handled without an scc insn.  */
11136       if ((code == LT && integer_zerop (arg1))
11137           || (! only_cheap && code == GE && integer_zerop (arg1)))
11138         ;
11139       else if (BRANCH_COST >= 0
11140                && ! only_cheap && (code == NE || code == EQ)
11141                && TREE_CODE (type) != REAL_TYPE
11142                && ((abs_optab->handlers[(int) operand_mode].insn_code
11143                     != CODE_FOR_nothing)
11144                    || (ffs_optab->handlers[(int) operand_mode].insn_code
11145                        != CODE_FOR_nothing)))
11146         ;
11147       else
11148         return 0;
11149     }
11150       
11151   preexpand_calls (exp);
11152   if (subtarget == 0 || GET_CODE (subtarget) != REG
11153       || GET_MODE (subtarget) != operand_mode
11154       || ! safe_from_p (subtarget, arg1, 1))
11155     subtarget = 0;
11156
11157   op0 = expand_expr (arg0, subtarget, VOIDmode, 0);
11158   op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
11159
11160   if (target == 0)
11161     target = gen_reg_rtx (mode);
11162
11163   /* Pass copies of OP0 and OP1 in case they contain a QUEUED.  This is safe
11164      because, if the emit_store_flag does anything it will succeed and
11165      OP0 and OP1 will not be used subsequently.  */
11166
11167   result = emit_store_flag (target, code,
11168                             queued_subexp_p (op0) ? copy_rtx (op0) : op0,
11169                             queued_subexp_p (op1) ? copy_rtx (op1) : op1,
11170                             operand_mode, unsignedp, 1);
11171
11172   if (result)
11173     {
11174       if (invert)
11175         result = expand_binop (mode, xor_optab, result, const1_rtx,
11176                                result, 0, OPTAB_LIB_WIDEN);
11177       return result;
11178     }
11179
11180   /* If this failed, we have to do this with set/compare/jump/set code.  */
11181   if (GET_CODE (target) != REG
11182       || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
11183     target = gen_reg_rtx (GET_MODE (target));
11184
11185   emit_move_insn (target, invert ? const0_rtx : const1_rtx);
11186   result = compare_from_rtx (op0, op1, code, unsignedp,
11187                              operand_mode, NULL_RTX, 0);
11188   if (GET_CODE (result) == CONST_INT)
11189     return (((result == const0_rtx && ! invert)
11190              || (result != const0_rtx && invert))
11191             ? const0_rtx : const1_rtx);
11192
11193   label = gen_label_rtx ();
11194   if (bcc_gen_fctn[(int) code] == 0)
11195     abort ();
11196
11197   emit_jump_insn ((*bcc_gen_fctn[(int) code]) (label));
11198   emit_move_insn (target, invert ? const1_rtx : const0_rtx);
11199   emit_label (label);
11200
11201   return target;
11202 }
11203 \f
11204 /* Generate a tablejump instruction (used for switch statements).  */
11205
11206 #ifdef HAVE_tablejump
11207
11208 /* INDEX is the value being switched on, with the lowest value
11209    in the table already subtracted.
11210    MODE is its expected mode (needed if INDEX is constant).
11211    RANGE is the length of the jump table.
11212    TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11213
11214    DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11215    index value is out of range.  */
11216
11217 void
11218 do_tablejump (index, mode, range, table_label, default_label)
11219      rtx index, range, table_label, default_label;
11220      enum machine_mode mode;
11221 {
11222   register rtx temp, vector;
11223
11224   /* Do an unsigned comparison (in the proper mode) between the index
11225      expression and the value which represents the length of the range.
11226      Since we just finished subtracting the lower bound of the range
11227      from the index expression, this comparison allows us to simultaneously
11228      check that the original index expression value is both greater than
11229      or equal to the minimum value of the range and less than or equal to
11230      the maximum value of the range.  */
11231
11232   emit_cmp_insn (index, range, GTU, NULL_RTX, mode, 1, 0);
11233   emit_jump_insn (gen_bgtu (default_label));
11234
11235   /* If index is in range, it must fit in Pmode.
11236      Convert to Pmode so we can index with it.  */
11237   if (mode != Pmode)
11238     index = convert_to_mode (Pmode, index, 1);
11239
11240   /* Don't let a MEM slip thru, because then INDEX that comes
11241      out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11242      and break_out_memory_refs will go to work on it and mess it up.  */
11243 #ifdef PIC_CASE_VECTOR_ADDRESS
11244   if (flag_pic && GET_CODE (index) != REG)
11245     index = copy_to_mode_reg (Pmode, index);
11246 #endif
11247
11248   /* If flag_force_addr were to affect this address
11249      it could interfere with the tricky assumptions made
11250      about addresses that contain label-refs,
11251      which may be valid only very near the tablejump itself.  */
11252   /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11253      GET_MODE_SIZE, because this indicates how large insns are.  The other
11254      uses should all be Pmode, because they are addresses.  This code
11255      could fail if addresses and insns are not the same size.  */
11256   index = gen_rtx_PLUS (Pmode,
11257                         gen_rtx_MULT (Pmode, index,
11258                                       GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
11259                         gen_rtx_LABEL_REF (Pmode, table_label));
11260 #ifdef PIC_CASE_VECTOR_ADDRESS
11261   if (flag_pic)
11262     index = PIC_CASE_VECTOR_ADDRESS (index);
11263   else
11264 #endif
11265     index = memory_address_noforce (CASE_VECTOR_MODE, index);
11266   temp = gen_reg_rtx (CASE_VECTOR_MODE);
11267   vector = gen_rtx_MEM (CASE_VECTOR_MODE, index);
11268   RTX_UNCHANGING_P (vector) = 1;
11269   convert_move (temp, vector, 0);
11270
11271   emit_jump_insn (gen_tablejump (temp, table_label));
11272
11273   /* If we are generating PIC code or if the table is PC-relative, the
11274      table and JUMP_INSN must be adjacent, so don't output a BARRIER.  */
11275   if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
11276     emit_barrier ();
11277 }
11278
11279 #endif /* HAVE_tablejump */