OSDN Git Service

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