OSDN Git Service

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