|
|
1.1 root 1: /* Optimize by combining instructions for GNU compiler.
1.1.1.2 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
1.1.1.13 root 6: GNU CC is free software; you can redistribute it and/or modify
7: it under the terms of the GNU General Public License as published by
8: the Free Software Foundation; either version 1, or (at your option)
9: any later version.
10:
1.1 root 11: GNU CC is distributed in the hope that it will be useful,
1.1.1.13 root 12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with GNU CC; see the file COPYING. If not, write to
18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
1.1 root 19:
20:
21: /* This module is essentially the "combiner" phase of the U. of Arizona
22: Portable Optimizer, but redone to work on our list-structured
23: representation for RTL instead of their string representation.
24:
25: The LOG_LINKS of each insn identify the most recent assignment
26: to each REG used in the insn. It is a list of previous insns,
27: each of which contains a SET for a REG that is used in this insn
28: and not used or set in between. LOG_LINKs never cross basic blocks.
29: They were set up by the preceding pass (lifetime analysis).
30:
31: We try to combine each pair of insns joined by a logical link.
32: We also try to combine triples of insns A, B and C when
33: C has a link back to B and B has a link back to A.
34:
35: LOG_LINKS does not have links for use of the CC0. They don't
36: need to, because the insn that sets the CC0 is always immediately
37: before the insn that tests it. So we always regard a branch
38: insn as having a logical link to the preceding insn.
39:
40: We check (with use_crosses_set_p) to avoid combining in such a way
41: as to move a computation to a place where its value would be different.
42:
43: Combination is done by mathematically substituting the previous
44: insn(s) values for the regs they set into the expressions in
45: the later insns that refer to these regs. If the result is a valid insn
46: for our target machine, according to the machine description,
47: we install it, delete the earlier insns, and update the data flow
48: information (LOG_LINKS and REG_NOTES) for what we did.
49:
50: To simplify substitution, we combine only when the earlier insn(s)
51: consist of only a single assignment. To simplify updating afterward,
52: we never combine when a subroutine call appears in the middle.
53:
54: Since we do not represent assignments to CC0 explicitly except when that
55: is all an insn does, there is no LOG_LINKS entry in an insn that uses
56: the condition code for the insn that set the condition code.
57: Fortunately, these two insns must be consecutive.
58: Therefore, every JUMP_INSN is taken to have an implicit logical link
59: to the preceding insn. This is not quite right, since non-jumps can
60: also use the condition code; but in practice such insns would not
61: combine anyway. */
62:
1.1.1.15 root 63: #include <stdio.h>
64:
1.1 root 65: #include "config.h"
66: #include "rtl.h"
1.1.1.2 root 67: #include "flags.h"
1.1 root 68: #include "regs.h"
69: #include "basic-block.h"
70: #include "insn-config.h"
71: #include "recog.h"
72:
73: #define max(A,B) ((A) > (B) ? (A) : (B))
74: #define min(A,B) ((A) < (B) ? (A) : (B))
75:
1.1.1.2 root 76: /* It is not safe to use ordinary gen_lowpart in combine.
77: Use gen_lowpart_for_combine instead. See comments there. */
78: #define gen_lowpart dont_use_gen_lowpart_you_dummy
79:
1.1 root 80: /* Number of attempts to combine instructions in this function. */
81:
82: static int combine_attempts;
1.1.1.7 root 83: static int distrib_attempts;
1.1 root 84:
85: /* Number of attempts that got as far as substitution in this function. */
86:
87: static int combine_merges;
1.1.1.7 root 88: static int distrib_merges_1, distrib_merges_2;
1.1 root 89:
90: /* Number of instructions combined with added SETs in this function. */
91:
92: static int combine_extras;
93:
94: /* Number of instructions combined in this function. */
95:
96: static int combine_successes;
1.1.1.7 root 97: static int distrib_successes;
1.1 root 98:
99: /* Totals over entire compilation. */
100:
101: static int total_attempts, total_merges, total_extras, total_successes;
1.1.1.7 root 102: static int total_distrib_attempts, total_distrib_merges_1, total_distrib_merges_2, total_distrib_successes;
1.1 root 103:
104:
105: /* Vector mapping INSN_UIDs to cuids.
106: The cuids are like uids but increase monononically always.
107: Combine always uses cuids so that it can compare them.
108: But actually renumbering the uids, which we used to do,
109: proves to be a bad idea because it makes it hard to compare
110: the dumps produced by earlier passes with those from later passes. */
111:
1.1.1.16! root 112: static int *uid_cuid;
1.1 root 113:
114: /* Get the cuid of an insn. */
115:
116: #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
117:
118:
119: /* Record last point of death of (hard or pseudo) register n. */
120:
121: static rtx *reg_last_death;
122:
123: /* Record last point of modification of (hard or pseudo) register n. */
124:
125: static rtx *reg_last_set;
126:
127: /* Record the cuid of the last insn that invalidated memory
128: (anything that writes memory, and subroutine calls). */
129:
130: static int mem_last_set;
131:
132: /* Record the cuid of the last CALL_INSN
133: so we can tell whether a potential combination crosses any calls. */
134:
135: static int last_call_cuid;
136:
137: /* When `subst' is called, this is the insn that is being modified
138: (by combining in a previous insn). The PATTERN of this insn
139: is still the old pattern partially modified and it should not be
140: looked at, but this may be used to examine the successors of the insn
141: to judge whether a simplification is valid. */
142:
143: static rtx subst_insn;
144:
145: /* Record one modification to rtl structure
1.1.1.12 root 146: to be undone by storing old_contents into *where.
147: is_int is 1 if the contents are an int. */
1.1 root 148:
149: struct undo
150: {
151: rtx *where;
152: rtx old_contents;
1.1.1.12 root 153: int is_int;
1.1 root 154: };
155:
1.1.1.11 root 156: struct undo_int
157: {
158: int *where;
159: int old_contents;
1.1.1.12 root 160: int is_int;
1.1.1.11 root 161: };
162:
1.1 root 163: /* Record a bunch of changes to be undone, up to MAX_UNDO of them.
164: num_undo says how many are currently recorded.
165: storage is nonzero if we must undo the allocation of new storage.
166: The value of storage is what to pass to obfree. */
167:
168: #define MAX_UNDO 10
169:
170: struct undobuf
171: {
172: int num_undo;
173: char *storage;
174: struct undo undo[MAX_UNDO];
175: };
176:
177: static struct undobuf undobuf;
178:
1.1.1.2 root 179: /* Number of times the pseudo being substituted for
180: was found and replaced. */
181:
182: static int n_occurrences;
183:
1.1 root 184: static void move_deaths ();
1.1.1.7 root 185: static void move_deaths_2 ();
1.1.1.4 root 186: void remove_death ();
1.1 root 187: static void record_dead_and_set_regs ();
188: int regno_dead_p ();
189: static int use_crosses_set_p ();
1.1.1.4 root 190: static int try_combine ();
1.1.1.7 root 191: static rtx try_distrib ();
1.1 root 192: static rtx subst ();
193: static void undo_all ();
1.1.1.2 root 194: static void copy_substitutions ();
1.1 root 195: static void add_links ();
1.1.1.7 root 196: static void remove_links ();
1.1 root 197: static void add_incs ();
198: static int adjacent_insns_p ();
1.1.1.11 root 199: static int check_asm_operands ();
1.1 root 200: static rtx simplify_and_const_int ();
201: static rtx gen_lowpart_for_combine ();
202: static void simplify_set_cc0_and ();
203:
204: /* Main entry point for combiner. F is the first insn of the function.
205: NREGS is the first unused pseudo-reg number. */
206:
207: void
208: combine_instructions (f, nregs)
209: rtx f;
210: int nregs;
211: {
212: register rtx insn;
213: register int i;
214: register rtx links, nextlinks;
215: rtx prev;
216:
217: combine_attempts = 0;
218: combine_merges = 0;
219: combine_extras = 0;
220: combine_successes = 0;
1.1.1.7 root 221: distrib_attempts = 0;
222: distrib_merges_1 = 0;
223: distrib_merges_2 = 0;
224: distrib_successes = 0;
1.1 root 225:
226: reg_last_death = (rtx *) alloca (nregs * sizeof (rtx));
227: reg_last_set = (rtx *) alloca (nregs * sizeof (rtx));
228: bzero (reg_last_death, nregs * sizeof (rtx));
229: bzero (reg_last_set, nregs * sizeof (rtx));
230:
231: init_recog ();
232:
233: /* Compute maximum uid value so uid_cuid can be allocated. */
234:
235: for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
236: if (INSN_UID (insn) > i)
237: i = INSN_UID (insn);
238:
1.1.1.16! root 239: uid_cuid = (int *) alloca ((i + 1) * sizeof (int));
1.1 root 240:
241: /* Compute the mapping from uids to cuids.
242: Cuids are numbers assigned to insns, like uids,
243: except that cuids increase monotonically through the code. */
244:
245: for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
246: INSN_CUID (insn) = ++i;
247:
248: /* Now scan all the insns in forward order. */
249:
250: last_call_cuid = 0;
251: mem_last_set = 0;
252: prev = 0;
253:
254: for (insn = f; insn; insn = NEXT_INSN (insn))
255: {
256: if (GET_CODE (insn) == INSN
257: || GET_CODE (insn) == CALL_INSN
258: || GET_CODE (insn) == JUMP_INSN)
259: {
260: retry:
261: /* Try this insn with each insn it links back to. */
262:
263: for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
264: if (try_combine (insn, XEXP (links, 0), 0))
265: goto retry;
266:
267: /* Try each sequence of three linked insns ending with this one. */
268:
269: for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
270: if (GET_CODE (XEXP (links, 0)) != NOTE)
271: for (nextlinks = LOG_LINKS (XEXP (links, 0)); nextlinks;
272: nextlinks = XEXP (nextlinks, 1))
273: if (try_combine (insn, XEXP (links, 0), XEXP (nextlinks, 0)))
274: goto retry;
275:
276: /* Try to combine a jump insn that uses CC0
277: with a preceding insn that sets CC0, and maybe with its
278: logical predecessor as well.
279: This is how we make decrement-and-branch insns.
280: We need this special code because data flow connections
281: via CC0 do not get entered in LOG_LINKS. */
282:
283: if (GET_CODE (insn) == JUMP_INSN
284: && prev != 0
285: && GET_CODE (prev) == INSN
286: && GET_CODE (PATTERN (prev)) == SET
287: && GET_CODE (SET_DEST (PATTERN (prev))) == CC0)
288: {
289: if (try_combine (insn, prev, 0))
1.1.1.11 root 290: goto retry;
1.1 root 291:
292: if (GET_CODE (prev) != NOTE)
293: for (nextlinks = LOG_LINKS (prev); nextlinks;
294: nextlinks = XEXP (nextlinks, 1))
295: if (try_combine (insn, prev, XEXP (nextlinks, 0)))
296: goto retry;
297: }
1.1.1.7 root 298:
299: /* Try to apply the distributive law to this insn
300: and two insns that compute the operands of this one. */
301: for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
302: if (GET_CODE (XEXP (links, 0)) != NOTE)
303: for (nextlinks = XEXP (links, 1); nextlinks; nextlinks = XEXP (nextlinks, 1))
304: if (GET_CODE (XEXP (nextlinks, 0)) != NOTE)
305: {
306: rtx try_from = 0;
307:
308: if (GET_CODE (PATTERN (XEXP (links, 0))) == SET
309: && find_reg_note (insn, REG_DEAD, SET_DEST (PATTERN (XEXP (links, 0))))
310: && GET_CODE (PATTERN (XEXP (nextlinks, 0))) == SET
311: && find_reg_note (insn, REG_DEAD, SET_DEST (PATTERN (XEXP (nextlinks, 0)))))
312: try_from = try_distrib (insn, XEXP (links, 0), XEXP (nextlinks, 0));
313: if (try_from != 0)
314: {
315: insn = try_from;
316: goto retry;
317: }
318: }
1.1 root 319: #if 0
320: /* Turned off because on 68020 it takes four insns to make
321: something like (a[b / 32] & (1 << (31 - (b % 32)))) != 0
322: that could actually be optimized, and that's an unlikely piece of code. */
323: /* If an insn gets or sets a bit field, try combining it
324: with two different insns whose results it uses. */
325: if (GET_CODE (insn) == INSN
326: && GET_CODE (PATTERN (insn)) == SET
327: && (GET_CODE (SET_DEST (PATTERN (insn))) == ZERO_EXTRACT
328: || GET_CODE (SET_DEST (PATTERN (insn))) == SIGN_EXTRACT
329: || GET_CODE (SET_SRC (PATTERN (insn))) == ZERO_EXTRACT
330: || GET_CODE (SET_SRC (PATTERN (insn))) == SIGN_EXTRACT))
331: {
332: for (links = LOG_LINKS (insn); links; links = XEXP (links, 1))
333: if (GET_CODE (XEXP (links, 0)) != NOTE)
334: for (nextlinks = XEXP (links, 1); nextlinks;
335: nextlinks = XEXP (nextlinks, 1))
336: if (try_combine (insn, XEXP (links, 0), XEXP (nextlinks, 0)))
337: goto retry;
338: }
339: #endif
1.1.1.15 root 340: if (GET_CODE (insn) != NOTE)
341: record_dead_and_set_regs (insn);
1.1 root 342: prev = insn;
343: }
344: else if (GET_CODE (insn) != NOTE)
345: prev = 0;
346: }
347: total_attempts += combine_attempts;
348: total_merges += combine_merges;
349: total_extras += combine_extras;
350: total_successes += combine_successes;
351: }
352:
353: /* Try to combine the insns I1 and I2 into I3.
354: Here I1 appears earlier than I2, which is earlier than I3.
355: I1 can be zero; then we combine just I2 into I3.
356:
357: Return 1 if successful; if that happens, I1 and I2 are pseudo-deleted
358: by turning them into NOTEs, and I3 is modified.
359: Return 0 if the combination does not work. Then nothing is changed. */
360:
361: static int
362: try_combine (i3, i2, i1)
363: register rtx i3, i2, i1;
364: {
365: register rtx newpat;
366: int added_sets_1 = 0;
367: int added_sets_2 = 0;
368: int total_sets;
369: int i2_is_used;
370: register rtx link;
371: int insn_code_number;
372: rtx i2dest, i2src;
373: rtx i1dest, i1src;
1.1.1.2 root 374: int maxreg;
1.1.1.11 root 375: rtx temp;
1.1.1.15 root 376: int i;
1.1 root 377:
378: combine_attempts++;
379:
380: /* Don't combine with something already used up by combination. */
381:
382: if (GET_CODE (i2) == NOTE
383: || (i1 && GET_CODE (i1) == NOTE))
384: return 0;
385:
386: /* Don't combine across a CALL_INSN, because that would possibly
387: change whether the life span of some REGs crosses calls or not,
388: and it is a pain to update that information. */
389:
390: if (INSN_CUID (i2) < last_call_cuid
391: || (i1 && INSN_CUID (i1) < last_call_cuid))
392: return 0;
393:
394: /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0.
395: That REG must be either set or dead by the final instruction
396: (so that we can safely forget about setting it).
397: Also test use_crosses_set_p to make sure that the value
398: that is to be substituted for the register
399: does not use any registers whose values alter in between.
400: Do not try combining with moves from one register to another
401: since it is better to let them be tied by register allocation.
1.1.1.2 root 402: (There is a switch to permit such combination; except the insns
403: that copy a function value into another register are never combined
404: because moving that too far away from the function call could cause
405: something else to be stored in that register in the interim.)
1.1 root 406:
407: A set of a SUBREG is considered as if it were a set from
408: SUBREG. Thus, (SET (SUBREG:X (REG:Y...)) (something:X...))
409: is handled by substituting (SUBREG:Y (something:X...)) for (REG:Y...). */
410:
411: if (GET_CODE (PATTERN (i2)) != SET)
412: return 0;
413: i2dest = SET_DEST (PATTERN (i2));
414: i2src = SET_SRC (PATTERN (i2));
415: if (GET_CODE (i2dest) == SUBREG)
416: {
417: i2dest = SUBREG_REG (i2dest);
418: i2src = gen_rtx (SUBREG, GET_MODE (i2dest), i2src, 0);
419: }
1.1.1.4 root 420: /* Don't eliminate a store in the stack pointer. */
421: if (i2dest == stack_pointer_rtx)
422: return 0;
1.1.1.16! root 423: /* Don't install a subreg involving two modes not tieable.
! 424: It can worsen register allocation, and can even make invalid reload insns,
! 425: since the reg inside may need to be copied from in the outside mode,
! 426: and that may be invalid if it is an fp reg copied in integer mode. */
! 427: if (GET_CODE (i2src) == SUBREG
! 428: && ! MODES_TIEABLE_P (GET_MODE (i2src), GET_MODE (SUBREG_REG (i2src))))
! 429: return 0;
1.1 root 430: if (GET_CODE (i2dest) != CC0
431: && (GET_CODE (i2dest) != REG
1.1.1.2 root 432: || (GET_CODE (i2src) == REG
1.1.1.16! root 433: /* Do allow the combination of y = x; x = y; (with x dead)
! 434: because the result will turn into nothing. */
! 435: && !(GET_CODE (PATTERN (i3)) == SET
! 436: && i2src == SET_DEST (PATTERN (i3)))
1.1.1.2 root 437: && (!flag_combine_regs
1.1.1.5 root 438: /* Don't substitute a function value reg for any other. */
1.1.1.9 root 439: || FUNCTION_VALUE_REGNO_P (REGNO (i2src))))
1.1.1.2 root 440: || GET_CODE (i2src) == CALL
1.1.1.9 root 441: /* Don't substitute into an incremented register. */
442: || find_reg_note (i3, REG_INC, i2dest)
1.1 root 443: || use_crosses_set_p (i2src, INSN_CUID (i2))))
444: return 0;
1.1.1.16! root 445: if (GET_CODE (i2src) == ASM_OPERANDS && MEM_VOLATILE_P (i2src))
! 446: return 0;
1.1.1.15 root 447: /* Don't substitute for a register intended as a clobberable operand. */
448: if (GET_CODE (PATTERN (i3)) == PARALLEL)
449: for (i = 0; i < XVECLEN (PATTERN (i3), 0); i++)
450: if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER
451: && XEXP (XVECEXP (PATTERN (i3), 0, i), 0) == i2dest)
452: return 0;
1.1 root 453:
454: if (i1 != 0)
455: {
456: if (GET_CODE (PATTERN (i1)) != SET)
457: return 0;
458: i1dest = SET_DEST (PATTERN (i1));
459: i1src = SET_SRC (PATTERN (i1));
460: if (GET_CODE (i1dest) == SUBREG)
461: {
462: i1dest = SUBREG_REG (i1dest);
463: i1src = gen_rtx (SUBREG, GET_MODE (i1dest), i1src, 0);
464: }
1.1.1.4 root 465: if (i1dest == stack_pointer_rtx)
466: return 0;
1.1.1.16! root 467: if (GET_CODE (i1src) == SUBREG
! 468: && ! MODES_TIEABLE_P (GET_MODE (i1src),
! 469: GET_MODE (SUBREG_REG (i1src))))
! 470: return 0;
1.1 root 471: if (GET_CODE (i1dest) != CC0
472: && (GET_CODE (i1dest) != REG
1.1.1.2 root 473: || (GET_CODE (i1src) == REG
474: && (!flag_combine_regs
1.1.1.9 root 475: || FUNCTION_VALUE_REGNO_P (REGNO (i1src))))
1.1.1.2 root 476: || GET_CODE (i1src) == CALL
1.1.1.9 root 477: || find_reg_note (i3, REG_INC, i1dest)
478: || find_reg_note (i2, REG_INC, i1dest)
1.1 root 479: || use_crosses_set_p (i1src, INSN_CUID (i1))))
480: return 0;
1.1.1.16! root 481: if (GET_CODE (i1src) == ASM_OPERANDS && MEM_VOLATILE_P (i1src))
! 482: return 0;
1.1.1.15 root 483: /* Don't substitute for a register intended as a clobberable operand. */
484: if (GET_CODE (PATTERN (i3)) == PARALLEL)
485: for (i = 0; i < XVECLEN (PATTERN (i3), 0); i++)
486: if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER
487: && XEXP (XVECEXP (PATTERN (i3), 0, i), 0) == i1dest)
488: return 0;
489: }
490:
491: /* If it is better that two different modes keep two different pseudos,
492: avoid combining them. */
493: if (GET_CODE (PATTERN (i3)) == SET)
494: {
495: rtx i3dest = SET_DEST (PATTERN (i3));
496: while (GET_CODE (i3dest) == SUBREG
497: || GET_CODE (i3dest) == STRICT_LOW_PART
498: || GET_CODE (i3dest) == SIGN_EXTRACT
499: || GET_CODE (i3dest) == ZERO_EXTRACT)
500: i3dest = SUBREG_REG (i3dest);
501:
502: if (SET_SRC (PATTERN (i3)) == i2dest
503: && GET_CODE (i3dest) == REG
504: && ! MODES_TIEABLE_P (GET_MODE (i2dest), GET_MODE (i3dest)))
505: return 0;
1.1 root 506: }
507:
1.1.1.14 root 508: /* If I2 contains anything volatile, reject, unless nothing
509: volatile comes between it and I3. */
510: if (volatile_refs_p (PATTERN (i2)))
511: {
512: rtx insn;
513: for (insn = NEXT_INSN (i2); insn != i3; insn = NEXT_INSN (insn))
514: if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
515: || GET_CODE (insn) == JUMP_INSN)
516: if (volatile_refs_p (PATTERN (insn)))
517: return 0;
518: }
519: /* Likewise for I1; nothing volatile can come between it and I3,
520: except optionally I2. */
521: if (i1 && volatile_refs_p (PATTERN (i1)))
522: {
523: rtx insn;
524: rtx end = (volatile_refs_p (PATTERN (i2)) ? i2 : i3);
525: for (insn = NEXT_INSN (i1); insn != end; insn = NEXT_INSN (insn))
526: if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
527: || GET_CODE (insn) == JUMP_INSN)
528: if (volatile_refs_p (PATTERN (insn)))
529: return 0;
530: }
531:
1.1 root 532: /* If I1 or I2 contains an autoincrement or autodecrement,
1.1.1.13 root 533: make sure that register is not used between there and I3,
534: and not already used in I3 either.
1.1 root 535: Also insist that I3 not be a jump; if it were one
536: and the incremented register were spilled, we would lose. */
1.1.1.5 root 537: for (link = REG_NOTES (i2); link; link = XEXP (link, 1))
538: if (REG_NOTE_KIND (link) == REG_INC
539: && (GET_CODE (i3) == JUMP_INSN
540: || reg_used_between_p (XEXP (link, 0), i2, i3)
1.1.1.13 root 541: || reg_mentioned_p (XEXP (link, 0), PATTERN (i3))))
1.1.1.5 root 542: return 0;
1.1 root 543:
1.1.1.5 root 544: if (i1)
545: for (link = REG_NOTES (i1); link; link = XEXP (link, 1))
546: if (REG_NOTE_KIND (link) == REG_INC
547: && (GET_CODE (i3) == JUMP_INSN
548: || reg_used_between_p (XEXP (link, 0), i1, i3)
1.1.1.13 root 549: || reg_mentioned_p (XEXP (link, 0), PATTERN (i3))))
550: return 0;
551:
552: /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd,
553: EXCEPT in one case: I3 has a post-inc in an output operand. */
554: if (!(GET_CODE (PATTERN (i3)) == SET
555: && GET_CODE (SET_SRC (PATTERN (i3))) == REG
556: && GET_CODE (SET_DEST (PATTERN (i3))) == MEM
557: && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC
558: || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC)))
559: /* It's not the exception. */
560: for (link = REG_NOTES (i3); link; link = XEXP (link, 1))
561: if (REG_NOTE_KIND (link) == REG_INC
562: && (reg_mentioned_p (XEXP (link, 0), PATTERN (i2))
563: || (i1 != 0
564: && reg_mentioned_p (XEXP (link, 0), PATTERN (i1)))))
1.1.1.5 root 565: return 0;
1.1 root 566:
1.1.1.11 root 567: /* Don't combine an insn I1 or I2 that follows a CC0-setting insn.
568: An insn that uses CC0 must not be separated from the one that sets it.
569: It would be more logical to test whether CC0 occurs inside I1 or I2,
570: but that would be much slower, and this ought to be equivalent. */
571: temp = PREV_INSN (i2);
572: while (temp && GET_CODE (temp) == NOTE)
573: temp = PREV_INSN (temp);
574: if (temp && GET_CODE (temp) == INSN && sets_cc0_p (PATTERN (temp)))
575: return 0;
576: if (i1)
577: {
578: temp = PREV_INSN (i2);
579: while (temp && GET_CODE (temp) == NOTE)
580: temp = PREV_INSN (temp);
581: if (temp && GET_CODE (temp) == INSN && sets_cc0_p (PATTERN (temp)))
582: return 0;
583: }
584:
1.1 root 585: /* See if the SETs in i1 or i2 need to be kept around in the merged
586: instruction: whenever the value set there is still needed past i3. */
587: added_sets_2 = (GET_CODE (i2dest) != CC0
588: && ! dead_or_set_p (i3, i2dest));
589: if (i1)
590: added_sets_1 = ! (dead_or_set_p (i3, i1dest)
591: || dead_or_set_p (i2, i1dest));
592:
593: combine_merges++;
594:
595: undobuf.num_undo = 0;
596: undobuf.storage = 0;
597:
598: /* Substitute in the latest insn for the regs set by the earlier ones. */
599:
1.1.1.2 root 600: maxreg = max_reg_num ();
601:
1.1 root 602: subst_insn = i3;
1.1.1.2 root 603: n_occurrences = 0; /* `subst' counts here */
604:
1.1 root 605: newpat = subst (PATTERN (i3), i2dest, i2src);
606: /* Record whether i2's body now appears within i3's body. */
1.1.1.2 root 607: i2_is_used = n_occurrences;
1.1 root 608:
609: if (i1)
1.1.1.2 root 610: {
611: n_occurrences = 0;
612: newpat = subst (newpat, i1dest, i1src);
613: }
1.1 root 614:
615: if (GET_CODE (PATTERN (i3)) == SET
616: && SET_DEST (PATTERN (i3)) == cc0_rtx
1.1.1.2 root 617: && (GET_CODE (SET_SRC (PATTERN (i3))) == AND
618: || GET_CODE (SET_SRC (PATTERN (i3))) == LSHIFTRT)
1.1 root 619: && next_insn_tests_no_inequality (i3))
620: simplify_set_cc0_and (i3);
621:
1.1.1.2 root 622: if (max_reg_num () != maxreg)
623: abort ();
624:
1.1 root 625: /* If the actions of the earler insns must be kept
626: in addition to substituting them into the latest one,
627: we must make a new PARALLEL for the latest insn
628: to hold additional the SETs. */
629:
630: if (added_sets_1 || added_sets_2)
631: {
632: combine_extras++;
633:
634: /* Arrange to free later what we allocate now
635: if we don't accept this combination. */
636: if (!undobuf.storage)
637: undobuf.storage = (char *) oballoc (0);
638:
639: if (GET_CODE (newpat) == PARALLEL)
640: {
1.1.1.2 root 641: rtvec old = XVEC (newpat, 0);
1.1 root 642: total_sets = XVECLEN (newpat, 0) + added_sets_1 + added_sets_2;
1.1.1.2 root 643: newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
644: bcopy (&old->elem[0], &XVECEXP (newpat, 0, 0),
645: sizeof (old->elem[0]) * old->num_elem);
1.1 root 646: }
647: else
648: {
1.1.1.2 root 649: rtx old = newpat;
1.1 root 650: total_sets = 1 + added_sets_1 + added_sets_2;
1.1.1.2 root 651: newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets));
652: XVECEXP (newpat, 0, 0) = old;
1.1 root 653: }
654: if (added_sets_1)
655: {
656: XVECEXP (newpat, 0, --total_sets) = PATTERN (i1);
657: }
658: if (added_sets_2)
659: {
660: /* If there is no I1, use I2's body as is. */
661: if (i1 == 0
662: /* If I2 was stuck into I3, then anything within it has
663: already had I1 substituted into it when that was done to I3. */
664: || i2_is_used)
665: {
666: XVECEXP (newpat, 0, --total_sets) = PATTERN (i2);
667: }
668: else
669: XVECEXP (newpat, 0, --total_sets)
670: = subst (PATTERN (i2), i1dest, i1src);
671: }
672: }
673:
1.1.1.2 root 674: /* Fail if an autoincrement side-effect has been duplicated. */
675: if ((i2_is_used > 1 && find_reg_note (i2, REG_INC, 0) != 0)
676: || (i1 != 0 && n_occurrences > 1 && find_reg_note (i1, REG_INC, 0) != 0))
677: {
678: undo_all ();
679: return 0;
680: }
681:
1.1 root 682: /* Is the result of combination a valid instruction? */
683: insn_code_number = recog (newpat, i3);
684:
1.1.1.11 root 685: if (insn_code_number >= 0
686: /* Is the result a reasonable ASM_OPERANDS? */
1.1.1.13 root 687: || (check_asm_operands (newpat) && ! added_sets_1 && ! added_sets_2))
1.1 root 688: {
689: /* Yes. Install it. */
690: register int regno;
691: INSN_CODE (i3) = insn_code_number;
692: PATTERN (i3) = newpat;
1.1.1.2 root 693: /* If anything was substituted more than once,
694: copy it to avoid invalid shared rtl structure. */
695: copy_substitutions ();
696: /* The data flowing into I2 now flows into I3.
697: But we cannot always move all of I2's LOG_LINKS into I3,
698: since they must go to a setting of a REG from the
699: first use following. If I2 was the first use following a set,
700: I3 is now a use, but it is not the first use
701: if some instruction between I2 and I3 is also a use.
702: Here, for simplicity, we move all the links only if
703: there are no real insns between I2 and I3.
704: Otherwise, we move only links that correspond to regs
705: that used to die in I2. They are always safe to move. */
706: add_links (i3, i2, adjacent_insns_p (i2, i3));
1.1 root 707: /* Most REGs that previously died in I2 now die in I3. */
708: move_deaths (i2src, INSN_CUID (i2), i3);
709: if (GET_CODE (i2dest) == REG)
710: {
711: /* If the reg formerly set in I2 died only once and that was in I3,
712: zero its use count so it won't make `reload' do any work. */
713: regno = REGNO (i2dest);
714: if (! added_sets_2)
1.1.1.2 root 715: {
716: reg_n_sets[regno]--;
717: /* Used to check && regno_dead_p (regno, i3) also here. */
718: if (reg_n_sets[regno] == 0
719: && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
720: & (1 << (regno % HOST_BITS_PER_INT))))
721: reg_n_refs[regno] = 0;
722: }
1.1 root 723: /* If a ref to REGNO was substituted into I3 from I2,
724: then it still dies there if it previously did.
725: Otherwise either REGNO never did die in I3 so remove_death is safe
726: or this entire life of REGNO is gone so remove its death. */
727: if (!added_sets_2
728: && ! reg_mentioned_p (i2dest, PATTERN (i3)))
729: remove_death (regno, i3);
730: }
731: /* Any registers previously autoincremented in I2
732: are now incremented in I3. */
733: add_incs (i3, REG_NOTES (i2));
734: if (i1)
735: {
736: /* Likewise, merge the info from I1 and get rid of it. */
1.1.1.2 root 737: add_links (i3, i1,
738: adjacent_insns_p (i1, i2) && adjacent_insns_p (i2, i3));
1.1 root 739: move_deaths (i1src, INSN_CUID (i1), i3);
740: if (GET_CODE (i1dest) == REG)
741: {
742: regno = REGNO (i1dest);
743: if (! added_sets_1)
1.1.1.2 root 744: {
745: reg_n_sets[regno]--;
746: /* Used to also check && regno_dead_p (regno, i3) here. */
747:
748: if (reg_n_sets[regno] == 0
749: && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
750: & (1 << (regno % HOST_BITS_PER_INT))))
751:
752: reg_n_refs[regno] = 0;
753: }
1.1 root 754: /* If a ref to REGNO was substituted into I3 from I1,
755: then it still dies there if it previously did.
756: Else either REGNO never did die in I3 so remove_death is safe
757: or this entire life of REGNO is gone so remove its death. */
758: if (! added_sets_1
759: && ! reg_mentioned_p (i1dest, PATTERN (i3)))
760: remove_death (regno, i3);
761: }
762: add_incs (i3, REG_NOTES (i1));
763: LOG_LINKS (i1) = 0;
764: PUT_CODE (i1, NOTE);
765: NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED;
766: NOTE_SOURCE_FILE (i1) = 0;
767: }
1.1.1.2 root 768: /* Get rid of I2. */
769: LOG_LINKS (i2) = 0;
770: PUT_CODE (i2, NOTE);
771: NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED;
772: NOTE_SOURCE_FILE (i2) = 0;
1.1 root 773:
774: combine_successes++;
775: return 1;
776: }
777:
778: /* Failure: change I3 back the way it was. */
779: undo_all ();
780:
781: return 0;
782: }
783:
784: /* Undo all the modifications recorded in undobuf. */
785:
786: static void
787: undo_all ()
788: {
789: register int i;
790: if (undobuf.num_undo > MAX_UNDO)
791: undobuf.num_undo = MAX_UNDO;
792: for (i = undobuf.num_undo - 1; i >= 0; i--)
793: *undobuf.undo[i].where = undobuf.undo[i].old_contents;
794: if (undobuf.storage)
795: obfree (undobuf.storage);
796: undobuf.num_undo = 0;
797: undobuf.storage = 0;
798: }
799:
1.1.1.2 root 800: /* If this insn had more than one substitution,
801: copy all but one, so that no invalid shared substructure is introduced. */
802:
803: static void
804: copy_substitutions ()
805: {
806: register int i;
807: if (undobuf.num_undo > 1)
808: {
809: for (i = undobuf.num_undo - 1; i >= 1; i--)
1.1.1.12 root 810: if (! undobuf.undo[i].is_int)
811: *undobuf.undo[i].where = copy_rtx (*undobuf.undo[i].where);
1.1.1.2 root 812: }
813: }
814:
1.1 root 815: /* Throughout X, replace FROM with TO, and return the result.
816: The result is TO if X is FROM;
817: otherwise the result is X, but its contents may have been modified.
818: If they were modified, a record was made in undobuf so that
819: undo_all will (among other things) return X to its original state.
820:
821: If the number of changes necessary is too much to record to undo,
822: the excess changes are not made, so the result is invalid.
823: The changes already made can still be undone.
824: undobuf.num_undo is incremented for such changes, so by testing that
1.1.1.2 root 825: the caller can tell whether the result is valid.
826:
827: `n_occurrences' is incremented each time FROM is replaced. */
1.1 root 828:
829: static rtx
830: subst (x, from, to)
831: register rtx x, from, to;
832: {
833: register char *fmt;
834: register int len, i;
835: register enum rtx_code code;
1.1.1.2 root 836: char was_replaced[2];
1.1 root 837:
1.1.1.2 root 838: #define SUBST(INTO, NEWVAL) \
839: do { if (undobuf.num_undo < MAX_UNDO) \
840: { \
841: undobuf.undo[undobuf.num_undo].where = &INTO; \
842: undobuf.undo[undobuf.num_undo].old_contents = INTO; \
1.1.1.12 root 843: undobuf.undo[undobuf.num_undo].is_int = 0; \
1.1.1.2 root 844: INTO = NEWVAL; \
845: } \
846: undobuf.num_undo++; } while (0)
847:
1.1.1.11 root 848: #define SUBST_INT(INTO, NEWVAL) \
849: do { if (undobuf.num_undo < MAX_UNDO) \
850: { \
851: struct undo_int *u = (struct undo_int *)&undobuf.undo[undobuf.num_undo];\
852: u->where = &INTO; \
853: u->old_contents = INTO; \
1.1.1.12 root 854: u->is_int = 1; \
1.1.1.11 root 855: INTO = NEWVAL; \
856: } \
857: undobuf.num_undo++; } while (0)
858:
1.1.1.2 root 859: /* FAKE_EXTEND_SAFE_P (MODE, FROM) is 1 if (subreg:MODE FROM 0) is a safe
860: replacement for (zero_extend:MODE FROM) or (sign_extend:MODE FROM).
1.1.1.6 root 861: If it is 0, that cannot be done. We can now do this for any MEM
862: because (SUBREG (MEM...)) is guaranteed to cause the MEM to be reloaded.
863: If not for that, MEM's would very rarely be safe. */
1.1.1.2 root 864:
1.1.1.9 root 865: /* Reject MODEs bigger than a word, because we might not be able
866: to reference a two-register group starting with an arbitrary register
867: (and currently gen_lowpart might crash for a SUBREG). */
868:
1.1.1.7 root 869: #define FAKE_EXTEND_SAFE_P(MODE, FROM) \
1.1.1.9 root 870: (GET_MODE_SIZE (MODE) <= UNITS_PER_WORD \
871: && (GET_CODE (FROM) == REG || GET_CODE (FROM) == SUBREG \
872: || GET_CODE (FROM) == MEM))
1.1 root 873:
874: if (x == from)
875: return to;
876:
1.1.1.2 root 877: /* It is possible to have a subexpression appear twice in the insn.
878: Suppose that FROM is a register that appears within TO.
879: Then, after that subexpression has been scanned once by `subst',
880: the second time it is scanned, TO may be found. If we were
881: to scan TO here, we would find FROM within it and create a
882: self-referent rtl structure which is completely wrong. */
883: if (x == to)
884: return to;
885:
1.1 root 886: code = GET_CODE (x);
887:
888: /* A little bit of algebraic simplification here. */
889: switch (code)
890: {
891: /* This case has no effect except to speed things up. */
892: case REG:
893: case CONST_INT:
894: case CONST:
895: case SYMBOL_REF:
896: case LABEL_REF:
897: case PC:
898: case CC0:
899: return x;
1.1.1.2 root 900: }
901:
902: was_replaced[0] = 0;
903: was_replaced[1] = 0;
904:
905: len = GET_RTX_LENGTH (code);
906: fmt = GET_RTX_FORMAT (code);
907:
908: /* Don't replace FROM where it is being stored in rather than used. */
909: if (code == SET && SET_DEST (x) == from)
910: fmt = "ie";
911: if (code == SET && GET_CODE (SET_DEST (x)) == SUBREG
912: && SUBREG_REG (SET_DEST (x)) == from)
913: fmt = "ie";
914:
915: for (i = 0; i < len; i++)
916: {
917: if (fmt[i] == 'E')
918: {
919: register int j;
920: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
921: {
922: register rtx new;
923: if (XVECEXP (x, i, j) == from)
924: new = to, n_occurrences++;
925: else
926: new = subst (XVECEXP (x, i, j), from, to);
927: if (new != XVECEXP (x, i, j))
928: SUBST (XVECEXP (x, i, j), new);
929: }
930: }
931: else if (fmt[i] == 'e')
932: {
933: register rtx new;
934:
935: if (XEXP (x, i) == from)
936: {
937: new = to;
938: n_occurrences++;
939: if (i < 2)
940: was_replaced[i] = 1;
941: }
942: else
943: new = subst (XEXP (x, i), from, to);
944:
945: if (new != XEXP (x, i))
946: SUBST (XEXP (x, i), new);
947: }
948: }
949:
950: /* A little bit of algebraic simplification here. */
951: switch (code)
952: {
953: case SUBREG:
954: /* Changing mode twice with SUBREG => just change it once,
955: or not at all if changing back to starting mode. */
956: if (SUBREG_REG (x) == to
1.1.1.11 root 957: && GET_CODE (to) == SUBREG)
1.1.1.2 root 958: {
959: if (GET_MODE (x) == GET_MODE (SUBREG_REG (to)))
1.1.1.11 root 960: if (SUBREG_WORD (x) == 0 && SUBREG_WORD (to) == 0)
961: return SUBREG_REG (to);
1.1.1.2 root 962: SUBST (SUBREG_REG (x), SUBREG_REG (to));
1.1.1.11 root 963: if (SUBREG_WORD (to) != 0)
964: SUBST_INT (SUBREG_WORD (x), SUBREG_WORD (x) + SUBREG_WORD (to));
1.1.1.2 root 965: }
1.1.1.4 root 966: if (SUBREG_REG (x) == to
967: && (GET_CODE (to) == SIGN_EXTEND || GET_CODE (to) == ZERO_EXTEND)
1.1.1.14 root 968: && subreg_lowpart_p (x))
969: {
970: /* (subreg (sign_extend X)) is X, if it has same mode as X. */
971: if (GET_MODE (x) == GET_MODE (XEXP (to, 0)))
972: return XEXP (to, 0);
973: /* (subreg (sign_extend X)), if it has a mode wider than X,
974: can be done with (sign_extend X). */
975: if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (XEXP (to, 0))))
976: {
977: if (!undobuf.storage)
978: undobuf.storage = (char *) oballoc (0);
979: return gen_rtx (GET_CODE (to), GET_MODE (x), XEXP (to, 0));
980: }
981: /* Extend and then truncate smaller than it was to start with:
982: no need to extend. */
983: if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (GET_MODE (XEXP (to, 0))))
984: {
985: SUBST (XEXP (x, 0), XEXP (to, 0));
986: }
987: }
1.1.1.11 root 988: /* (subreg:A (mem:B X) N) becomes a modified MEM.
1.1.1.15 root 989: If we can't do that safely, then it becomes something nonsensical
990: so that this combination won't take place.
1.1.1.11 root 991: This avoids producing any (subreg (mem))s except in the special
992: paradoxical case where gen_lowpart_for_combine makes them. */
993: if (SUBREG_REG (x) == to
994: && GET_CODE (to) == MEM)
995: {
1.1.1.12 root 996: int endian_offset = 0;
1.1.1.15 root 997: /* Don't combine this if mode A is wider than B. */
998: if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (to)))
999: return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
1000: /* Don't change the mode of the MEM
1001: if that would change the meaning of the address. */
1002: if (mode_dependent_address_p (XEXP (to, 0)))
1003: return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
1.1.1.12 root 1004: #ifdef BYTES_BIG_ENDIAN
1005: if (GET_MODE_SIZE (GET_MODE (x)) < UNITS_PER_WORD)
1006: endian_offset += UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (x));
1007: if (GET_MODE_SIZE (GET_MODE (to)) < UNITS_PER_WORD)
1008: endian_offset -= UNITS_PER_WORD - GET_MODE_SIZE (GET_MODE (to));
1009: #endif
1.1.1.11 root 1010: if (!undobuf.storage)
1011: undobuf.storage = (char *) oballoc (0);
1012: /* Note if the plus_constant doesn't make a valid address
1013: then this combination won't be accepted. */
1014: return gen_rtx (MEM, GET_MODE (x),
1015: plus_constant (XEXP (to, 0),
1.1.1.12 root 1016: (SUBREG_WORD (x) * UNITS_PER_WORD
1017: + endian_offset)));
1.1.1.11 root 1018: }
1.1.1.2 root 1019: break;
1.1 root 1020:
1021: case NOT:
1.1.1.4 root 1022: /* (not (minus X 1)) can become (neg X). */
1023: if (was_replaced[0]
1024: && ((GET_CODE (to) == PLUS && INTVAL (XEXP (to, 1)) == -1)
1025: || (GET_CODE (to) == MINUS && XEXP (to, 1) == const1_rtx)))
1.1.1.11 root 1026: {
1027: if (!undobuf.storage)
1028: undobuf.storage = (char *) oballoc (0);
1029: return gen_rtx (NEG, GET_MODE (to), XEXP (to, 0));
1030: }
1.1.1.4 root 1031: /* Don't let substitution introduce double-negatives. */
1032: if (was_replaced[0]
1.1.1.14 root 1033: && GET_CODE (to) == code)
1034: return XEXP (to, 0);
1.1.1.4 root 1035: break;
1036:
1.1 root 1037: case NEG:
1.1.1.4 root 1038: /* (neg (minus X Y)) can become (minus Y X). */
1039: if (was_replaced[0] && GET_CODE (to) == MINUS)
1.1.1.11 root 1040: {
1041: if (!undobuf.storage)
1042: undobuf.storage = (char *) oballoc (0);
1.1.1.14 root 1043: return gen_rtx (MINUS, GET_MODE (to),
1044: XEXP (to, 1), XEXP (to, 0));
1.1.1.11 root 1045: }
1.1 root 1046: /* Don't let substitution introduce double-negatives. */
1.1.1.2 root 1047: if (was_replaced[0]
1.1 root 1048: && GET_CODE (to) == code)
1049: return XEXP (to, 0);
1050: break;
1051:
1.1.1.2 root 1052: case FLOAT_TRUNCATE:
1053: /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF. */
1054: if (was_replaced[0]
1055: && GET_CODE (to) == FLOAT_EXTEND
1056: && GET_MODE (XEXP (to, 0)) == GET_MODE (x))
1057: return XEXP (to, 0);
1058: break;
1059:
1.1.1.15 root 1060: #if 0
1061: case COMPARE:
1062: /* -x>0 if 0>x. */
1063: if (GET_CODE (XEXP (x, 0)) == NEG && XEXP (x, 1) == const0_rtx)
1064: {
1065: SUBST (XEXP (x, 1), XEXP (XEXP (x, 0), 0));
1066: SUBST (XEXP (x, 0), const0_rtx);
1067: }
1068: if (GET_CODE (XEXP (x, 1)) == NEG && XEXP (x, 0) == const0_rtx)
1069: {
1070: SUBST (XEXP (x, 0), XEXP (XEXP (x, 1), 0));
1071: SUBST (XEXP (x, 1), const0_rtx);
1072: }
1073: break;
1074: #endif
1075:
1.1 root 1076: case PLUS:
1.1.1.15 root 1077: #if 0 /* Turned off for caution: turn it on after 1.36. */
1078: /* Identify constant sums as such. */
1079: if ((was_replaced[0] || was_replaced[1])
1080: && CONSTANT_P (XEXP (x, 0))
1081: && CONSTANT_P (XEXP (x, 1)))
1082: {
1083: if (!undobuf.storage)
1084: undobuf.storage = (char *) oballoc (0);
1085: return gen_rtx (CONST, GET_MODE (x), x);
1086: }
1087: #endif
1.1 root 1088: /* In (plus <foo> (ashift <bar> <n>))
1089: change the shift to a multiply so we can recognize
1090: scaled indexed addresses. */
1.1.1.2 root 1091: if ((was_replaced[0]
1092: || was_replaced[1])
1.1 root 1093: && GET_CODE (to) == ASHIFT
1.1.1.2 root 1094: && GET_CODE (XEXP (to, 1)) == CONST_INT
1095: && INTVAL (XEXP (to, 1)) < HOST_BITS_PER_INT)
1096: {
1097: rtx temp;
1098: if (!undobuf.storage)
1099: undobuf.storage = (char *) oballoc (0);
1100: temp = gen_rtx (MULT, GET_MODE (to),
1101: XEXP (to, 0),
1102: gen_rtx (CONST_INT, VOIDmode,
1103: 1 << INTVAL (XEXP (to, 1))));
1104: if (was_replaced[0])
1105: SUBST (XEXP (x, 0), temp);
1106: else
1107: SUBST (XEXP (x, 1), temp);
1108: }
1109: /* (plus X (neg Y)) becomes (minus X Y). */
1110: if (GET_CODE (XEXP (x, 1)) == NEG)
1111: {
1112: if (!undobuf.storage)
1113: undobuf.storage = (char *) oballoc (0);
1114: return gen_rtx (MINUS, GET_MODE (x),
1115: XEXP (x, 0), XEXP (XEXP (x, 1), 0));
1116: }
1117: /* (plus (neg X) Y) becomes (minus Y X). */
1118: if (GET_CODE (XEXP (x, 0)) == NEG)
1.1 root 1119: {
1120: if (!undobuf.storage)
1121: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1122: return gen_rtx (MINUS, GET_MODE (x),
1123: XEXP (x, 1), XEXP (XEXP (x, 0), 0));
1124: }
1125: /* (plus (plus x c1) c2) => (plus x c1+c2) */
1126: if (GET_CODE (XEXP (x, 1)) == CONST_INT
1127: && GET_CODE (XEXP (x, 0)) == PLUS
1128: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1129: {
1130: int sum = (INTVAL (XEXP (x, 1))
1131: + INTVAL (XEXP (XEXP (x, 0), 1)));
1132: if (sum == 0)
1133: return XEXP (XEXP (x, 0), 0);
1134: if (!undobuf.storage)
1135: undobuf.storage = (char *) oballoc (0);
1136: SUBST (XEXP (x, 1), gen_rtx (CONST_INT, VOIDmode, sum));
1137: SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
1138: break;
1.1 root 1139: }
1140: /* If we have something (putative index) being added to a sum,
1141: associate it so that any constant term is outermost.
1142: That's because that's the way indexed addresses are
1143: now supposed to appear. */
1.1.1.2 root 1144: if (((was_replaced[0] && GET_CODE (XEXP (x, 1)) == PLUS)
1145: || (was_replaced[1] && GET_CODE (XEXP (x, 0)) == PLUS))
1.1 root 1146: ||
1.1.1.2 root 1147: ((was_replaced[0] || was_replaced[1])
1148: && GET_CODE (to) == PLUS))
1.1 root 1149: {
1150: rtx offset = 0, base, index;
1.1.1.2 root 1151: if (GET_CODE (to) != PLUS)
1.1 root 1152: {
1.1.1.2 root 1153: index = to;
1154: base = was_replaced[0] ? XEXP (x, 1) : XEXP (x, 0);
1.1 root 1155: }
1156: else
1157: {
1.1.1.2 root 1158: index = was_replaced[0] ? XEXP (x, 1) : XEXP (x, 0);
1159: base = to;
1.1 root 1160: }
1161: if (CONSTANT_ADDRESS_P (XEXP (base, 0)))
1162: {
1163: offset = XEXP (base, 0);
1164: base = XEXP (base, 1);
1165: }
1166: else if (CONSTANT_ADDRESS_P (XEXP (base, 1)))
1167: {
1168: offset = XEXP (base, 1);
1169: base = XEXP (base, 0);
1170: }
1171: if (offset != 0)
1172: {
1173: if (!undobuf.storage)
1174: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1175: if (GET_CODE (offset) == CONST_INT)
1176: return plus_constant (gen_rtx (PLUS, GET_MODE (index),
1177: base, index),
1178: INTVAL (offset));
1179: if (GET_CODE (index) == CONST_INT)
1180: return plus_constant (gen_rtx (PLUS, GET_MODE (offset),
1181: base, offset),
1182: INTVAL (index));
1183: return gen_rtx (PLUS, GET_MODE (index),
1.1 root 1184: gen_rtx (PLUS, GET_MODE (index),
1.1.1.2 root 1185: base, index),
1186: offset);
1.1 root 1187: }
1188: }
1189: break;
1190:
1191: case EQ:
1192: case NE:
1193: /* If comparing a subreg against zero, discard the subreg. */
1.1.1.2 root 1194: if (was_replaced[0]
1.1 root 1195: && GET_CODE (to) == SUBREG
1196: && SUBREG_WORD (to) == 0
1197: && XEXP (x, 1) == const0_rtx)
1.1.1.2 root 1198: SUBST (XEXP (x, 0), SUBREG_REG (to));
1.1 root 1199:
1200: /* If comparing a ZERO_EXTRACT against zero,
1201: canonicalize to a SIGN_EXTRACT,
1202: since the two are equivalent here. */
1.1.1.2 root 1203: if (was_replaced[0]
1204: && GET_CODE (to) == ZERO_EXTRACT
1.1 root 1205: && XEXP (x, 1) == const0_rtx)
1206: {
1207: if (!undobuf.storage)
1208: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1209: SUBST (XEXP (x, 0),
1210: gen_rtx (SIGN_EXTRACT, GET_MODE (to),
1211: XEXP (to, 0), XEXP (to, 1),
1212: XEXP (to, 2)));
1.1 root 1213: }
1214: /* If we are putting (ASHIFT 1 x) into (EQ (AND ... y) 0),
1215: arrange to return (EQ (SIGN_EXTRACT y 1 x) 0),
1216: which is what jump-on-bit instructions are written with. */
1217: else if (XEXP (x, 1) == const0_rtx
1218: && GET_CODE (XEXP (x, 0)) == AND
1.1.1.2 root 1219: && (XEXP (XEXP (x, 0), 0) == to
1220: || XEXP (XEXP (x, 0), 1) == to)
1221: && GET_CODE (to) == ASHIFT
1222: && XEXP (to, 0) == const1_rtx)
1.1 root 1223: {
1224: register rtx y = XEXP (XEXP (x, 0),
1.1.1.2 root 1225: XEXP (XEXP (x, 0), 0) == to);
1.1 root 1226: if (!undobuf.storage)
1227: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1228: SUBST (XEXP (x, 0),
1229: gen_rtx (SIGN_EXTRACT, GET_MODE (to),
1230: y,
1231: const1_rtx, XEXP (to, 1)));
1.1 root 1232: }
1.1.1.15 root 1233: /* Negation is a no-op before equality test against zero. */
1234: if (GET_CODE (XEXP (x, 0)) == NEG && XEXP (x, 1) == const0_rtx)
1235: {
1236: SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
1237: }
1238: if (GET_CODE (XEXP (x, 1)) == NEG && XEXP (x, 0) == const0_rtx)
1239: {
1240: SUBST (XEXP (x, 1), XEXP (XEXP (x, 1), 0));
1241: }
1.1 root 1242: break;
1243:
1244: case ZERO_EXTEND:
1.1.1.7 root 1245: /* Nested zero-extends are equivalent to just one. */
1.1.1.2 root 1246: if (was_replaced[0]
1.1 root 1247: && GET_CODE (to) == ZERO_EXTEND)
1.1.1.2 root 1248: SUBST (XEXP (x, 0), XEXP (to, 0));
1.1.1.7 root 1249: /* Zero extending a constant int can be replaced
1250: by a zero-extended constant. */
1251: if (was_replaced[0]
1252: && HOST_BITS_PER_INT >= GET_MODE_BITSIZE (GET_MODE (from))
1253: && GET_CODE (to) == CONST_INT)
1254: {
1255: int intval = INTVAL (to) & GET_MODE_MASK (GET_MODE (from));
1256: if (!undobuf.storage)
1257: undobuf.storage = (char *) oballoc (0);
1258: return gen_rtx (CONST_INT, VOIDmode, intval);
1259: }
1.1 root 1260: /* Zero-extending the result of an and with a constant can be done
1261: with a wider and. */
1.1.1.2 root 1262: if (was_replaced[0]
1.1 root 1263: && GET_CODE (to) == AND
1264: && GET_CODE (XEXP (to, 1)) == CONST_INT
1.1.1.2 root 1265: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
1.1 root 1266: /* Avoid getting wrong result if the constant has high bits set
1267: that are irrelevant in the narrow mode where it is being used. */
1.1.1.2 root 1268: && 0 == (INTVAL (XEXP (to, 1))
1269: & ~ GET_MODE_MASK (GET_MODE (to))))
1.1 root 1270: {
1271: if (!undobuf.storage)
1272: undobuf.storage = (char *) oballoc (0);
1273: return gen_rtx (AND, GET_MODE (x),
1.1.1.2 root 1274: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1.1 root 1275: XEXP (to, 1));
1.1.1.2 root 1276: }
1277: /* Change (zero_extend:M (subreg:N (zero_extract:M ...) 0))
1278: to (zero_extract:M ...) if the field extracted fits in mode N. */
1279: if (GET_CODE (XEXP (x, 0)) == SUBREG
1280: && GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTRACT
1281: && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT
1282: && (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1))
1283: <= GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))))
1284: {
1285: return XEXP (XEXP (x, 0), 0);
1286: }
1.1.1.7 root 1287: /* Change (zero_extend:M (subreg:N (and:M ... <const>) 0))
1288: to (and:M ...) if the significant bits fit in mode N. */
1289: if (GET_CODE (XEXP (x, 0)) == SUBREG
1290: && SUBREG_REG (XEXP (x, 0)) == to
1291: && SUBREG_WORD (XEXP (x, 0)) == 0
1292: && GET_CODE (to) == AND
1293: && GET_CODE (XEXP (to, 1)) == CONST_INT
1294: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
1295: /* Avoid getting wrong result if the constant has high bits set
1296: that are irrelevant in the narrow mode where it is being used. */
1297: && 0 == (INTVAL (XEXP (to, 1))
1298: & ~ GET_MODE_MASK (GET_MODE (to))))
1299: {
1300: if (!undobuf.storage)
1301: undobuf.storage = (char *) oballoc (0);
1302: return gen_rtx (AND, GET_MODE (x),
1303: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1304: XEXP (to, 1));
1305: }
1.1.1.15 root 1306: /* In (zero_extend:M (subreg:N (lshiftrt:M REG))),
1307: where REG was assigned from (zero_extend:M (any:N ...)),
1.1.1.7 root 1308: remove the outer zero extension. */
1309: if (GET_CODE (XEXP (x, 0)) == SUBREG
1310: && SUBREG_REG (XEXP (x, 0)) == to
1311: && SUBREG_WORD (XEXP (x, 0)) == 0
1312: && GET_CODE (to) == LSHIFTRT)
1313: {
1314: rtx tmp = XEXP (to, 0);
1315:
1.1.1.15 root 1316: /* See if arg of LSHIFTRT is a register whose value we can find. */
1.1.1.7 root 1317: if (GET_CODE (tmp) == REG)
1.1.1.15 root 1318: if (reg_n_sets[REGNO (tmp)] == 1
1319: && SET_DEST (PATTERN (reg_last_set[REGNO (tmp)])) == tmp)
1.1.1.7 root 1320: tmp = SET_SRC (PATTERN (reg_last_set[REGNO (tmp)]));
1321: else
1322: break;
1323:
1324: if (GET_CODE (tmp) == ZERO_EXTEND
1325: && GET_MODE (tmp) == GET_MODE (x)
1326: && GET_MODE (XEXP (tmp, 0)) == GET_MODE (XEXP (x, 0)))
1327: return SUBREG_REG (XEXP (x, 0));
1328: }
1.1 root 1329: break;
1330:
1331: case SIGN_EXTEND:
1.1.1.7 root 1332: /* Nested sign-extends are equivalent to just one. */
1.1.1.2 root 1333: if (was_replaced[0]
1.1 root 1334: && GET_CODE (to) == SIGN_EXTEND)
1.1.1.2 root 1335: SUBST (XEXP (x, 0), XEXP (to, 0));
1.1.1.7 root 1336: /* Sign extending a constant int can be replaced
1337: by a sign-extended constant. */
1338: if (was_replaced[0]
1339: && HOST_BITS_PER_INT >= GET_MODE_BITSIZE (GET_MODE (from))
1340: && GET_CODE (to) == CONST_INT)
1341: {
1342: int intval = INTVAL (to);
1343: if (!undobuf.storage)
1344: undobuf.storage = (char *) oballoc (0);
1345: if (intval > 0
1346: && (intval & (1 << (GET_MODE_BITSIZE (GET_MODE (from)) - 1))))
1347: intval |= ~ GET_MODE_MASK (GET_MODE (from));
1348: return gen_rtx (CONST_INT, VOIDmode, intval);
1349: }
1.1 root 1350: /* Sign-extending the result of an and with a constant can be done
1351: with a wider and, provided the high bit of the constant is 0. */
1.1.1.2 root 1352: if (was_replaced[0]
1.1 root 1353: && GET_CODE (to) == AND
1354: && GET_CODE (XEXP (to, 1)) == CONST_INT
1.1.1.2 root 1355: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
1.1 root 1356: && ((INTVAL (XEXP (to, 1))
1.1.1.2 root 1357: & (-1 << (GET_MODE_BITSIZE (GET_MODE (to)) - 1)))
1.1 root 1358: == 0))
1359: {
1360: if (!undobuf.storage)
1361: undobuf.storage = (char *) oballoc (0);
1362: return gen_rtx (AND, GET_MODE (x),
1.1.1.2 root 1363: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1.1 root 1364: XEXP (to, 1));
1365: }
1.1.1.7 root 1366: /* hacks added by tiemann. */
1367: /* Change (sign_extend:M (subreg:N (and:M ... <const>) 0))
1368: to (and:M ...), provided the result fits in mode N,
1.1.1.16! root 1369: and the high bit of the constant is 0 in mode N. */
1.1.1.7 root 1370: if (GET_CODE (XEXP (x, 0)) == SUBREG
1371: && SUBREG_REG (XEXP (x, 0)) == to
1372: && SUBREG_WORD (XEXP (x, 0)) == 0
1373: && GET_CODE (to) == AND
1374: && GET_CODE (XEXP (to, 1)) == CONST_INT
1375: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0))
1376: && ((INTVAL (XEXP (to, 1))
1.1.1.16! root 1377: & (-1 << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1)))
1.1.1.7 root 1378: == 0))
1379: {
1380: if (!undobuf.storage)
1381: undobuf.storage = (char *) oballoc (0);
1382: return gen_rtx (AND, GET_MODE (x),
1383: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1384: XEXP (to, 1));
1385: }
1.1.1.15 root 1386: /* In (sign_extend:M (subreg:N (ashiftrt:M REG))),
1387: where REG was assigned from (sign_extend:M (any:N ...)),
1.1.1.7 root 1388: remove the outer sign extension. */
1389: if (GET_CODE (XEXP (x, 0)) == SUBREG
1390: && SUBREG_REG (XEXP (x, 0)) == to
1391: && SUBREG_WORD (XEXP (x, 0)) == 0
1392: && GET_CODE (to) == ASHIFTRT)
1393: {
1394: rtx tmp = XEXP (to, 0);
1395:
1.1.1.15 root 1396: /* See if arg of LSHIFTRT is a register whose value we can find. */
1.1.1.7 root 1397: if (GET_CODE (tmp) == REG)
1.1.1.15 root 1398: if (reg_n_sets[REGNO (tmp)] == 1
1399: && SET_DEST (PATTERN (reg_last_set[REGNO (tmp)])) == tmp)
1.1.1.7 root 1400: tmp = SET_SRC (PATTERN (reg_last_set[REGNO (tmp)]));
1401: else
1402: break;
1403:
1404: if (GET_CODE (tmp) == SIGN_EXTEND
1405: && GET_MODE (tmp) == GET_MODE (x)
1406: && GET_MODE (XEXP (tmp, 0)) == GET_MODE (XEXP (x, 0)))
1407: return SUBREG_REG (XEXP (x, 0));
1408: }
1.1 root 1409: break;
1410:
1411: case SET:
1.1.1.2 root 1412: /* In (set (zero-extract <x> <n> <y>) (and <foo> <(2**n-1) | anything>))
1.1 root 1413: the `and' can be deleted. This can happen when storing a bit
1.1.1.2 root 1414: that came from a set-flag insn followed by masking to one bit. */
1.1 root 1415: if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
1.1.1.2 root 1416: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1417: && was_replaced[1]
1.1 root 1418: && GET_CODE (to) == AND
1.1.1.2 root 1419: && GET_CODE (XEXP (to, 1)) == CONST_INT
1420: && 0 == (((1 << INTVAL (XEXP (XEXP (x, 0), 1))) - 1)
1421: & ~ INTVAL (XEXP (to, 1))))
1.1 root 1422: {
1.1.1.2 root 1423: SUBST (XEXP (x, 1), XEXP (to, 0));
1424: }
1425: /* In (set (zero-extract <x> <n> <y>)
1.1.1.14 root 1426: (subreg (and <foo> <(2**n-1) | anything>)))
1.1.1.2 root 1427: the `and' can be deleted. */
1428: if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
1429: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1430: && GET_CODE (XEXP (x, 1)) == SUBREG
1431: && SUBREG_WORD (XEXP (x, 1)) == 0
1432: && GET_CODE (SUBREG_REG (XEXP (x, 1))) == AND
1433: && GET_CODE (XEXP (SUBREG_REG (XEXP (x, 1)), 1)) == CONST_INT
1434: && 0 == (((1 << INTVAL (XEXP (XEXP (x, 0), 1))) - 1)
1435: & ~ INTVAL (XEXP (SUBREG_REG (XEXP (x, 1)), 1))))
1436: {
1437: SUBST (SUBREG_REG (XEXP (x, 1)), XEXP (SUBREG_REG (XEXP (x, 1)), 0));
1438: }
1439: /* (set (zero_extract ...) (and/or/xor (zero_extract ...) const)),
1.1.1.5 root 1440: if both zero_extracts have the same location, size and position,
1.1.1.2 root 1441: can be changed to avoid the byte extracts. */
1442: if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
1443: || GET_CODE (XEXP (x, 0)) == SIGN_EXTRACT)
1444: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1445: && (GET_CODE (XEXP (x, 1)) == AND
1446: || GET_CODE (XEXP (x, 1)) == IOR
1447: || GET_CODE (XEXP (x, 1)) == XOR)
1.1.1.5 root 1448: && rtx_equal_p (XEXP (x, 0), XEXP (XEXP (x, 1), 0))
1.1.1.2 root 1449: && GET_CODE (XEXP (XEXP (x, 1), 0)) == GET_CODE (XEXP (x, 0))
1.1.1.14 root 1450: && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
1451: /* zero_extract can apply to a QImode even if the bits extracted
1452: don't fit inside that byte. In such a case, we may not do this
1453: optimization, since the OR or AND insn really would need
1454: to fit in a byte. */
1455: && (INTVAL (XEXP (XEXP (x, 0), 1)) + INTVAL (XEXP (XEXP (x, 0), 2))
1456: < GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))))
1.1.1.2 root 1457: {
1.1.1.14 root 1458: int shiftcount;
1.1.1.15 root 1459: int newmask;
1.1.1.2 root 1460: #ifdef BITS_BIG_ENDIAN
1.1.1.14 root 1461: shiftcount
1.1.1.2 root 1462: = GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))
1463: - INTVAL (XEXP (XEXP (x, 0), 1)) - INTVAL (XEXP (XEXP (x, 0), 2));
1464: #else
1.1.1.14 root 1465: shiftcount
1.1.1.2 root 1466: = INTVAL (XEXP (XEXP (x, 0), 2));
1467: #endif
1.1.1.15 root 1468: newmask = ((INTVAL (XEXP (XEXP (x, 1), 1)) << shiftcount)
1469: + (GET_CODE (XEXP (x, 1)) == AND
1470: ? (1 << shiftcount) - 1
1471: : 0));
1472: if (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))
1473: < HOST_BITS_PER_INT)
1474: newmask &= (1 << GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (x, 0), 0)))) - 1;
1.1.1.2 root 1475: if (!undobuf.storage)
1476: undobuf.storage = (char *) oballoc (0);
1477: return
1478: gen_rtx (SET, VOIDmode,
1479: XEXP (XEXP (x, 0), 0),
1480: gen_rtx (GET_CODE (XEXP (x, 1)),
1481: GET_MODE (XEXP (XEXP (x, 0), 0)),
1482: XEXP (XEXP (XEXP (x, 1), 0), 0),
1.1.1.15 root 1483: gen_rtx (CONST_INT, VOIDmode, newmask)));
1.1.1.2 root 1484: }
1.1.1.13 root 1485: /* Can simplify (set (cc0) (compare (zero/sign_extend FOO) CONST))
1486: to (set (cc0) (compare FOO CONST)) if CONST fits in FOO's mode
1.1.1.12 root 1487: and we are only testing equality.
1488: In fact, this is valid for zero_extend if what follows is an
1489: unsigned comparison, and for sign_extend with a signed comparison. */
1490: if (SET_DEST (x) == cc0_rtx
1.1.1.13 root 1491: && GET_CODE (SET_SRC (x)) == COMPARE
1.1.1.12 root 1492: && (GET_CODE (XEXP (SET_SRC (x), 0)) == ZERO_EXTEND
1493: || GET_CODE (XEXP (SET_SRC (x), 0)) == SIGN_EXTEND)
1494: && next_insn_tests_no_inequality (subst_insn)
1495: && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
1496: /* This is overly cautious by one bit, but saves worrying about
1497: whether it is zero-extension or sign extension. */
1498: && ((unsigned) INTVAL (XEXP (SET_SRC (x), 1))
1499: < (1 << (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (SET_SRC (x), 0), 0))) - 1))))
1500: SUBST (XEXP (SET_SRC (x), 0), XEXP (XEXP (SET_SRC (x), 0), 0));
1.1 root 1501: break;
1502:
1503: case AND:
1504: if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1505: {
1.1.1.2 root 1506: rtx tem = simplify_and_const_int (x, to);
1.1 root 1507: if (tem)
1508: return tem;
1509: }
1510: break;
1511:
1.1.1.14 root 1512: case IOR:
1513: case XOR:
1514: /* (ior (ior x c1) c2) => (ior x c1|c2); likewise for xor. */
1515: if (GET_CODE (XEXP (x, 1)) == CONST_INT
1516: && GET_CODE (XEXP (x, 0)) == code
1517: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1518: {
1519: int c0 = INTVAL (XEXP (x, 1));
1520: int c1 = INTVAL (XEXP (XEXP (x, 0), 1));
1521: int combined = (code == IOR ? c0 | c1 : c0 ^ c1);
1522:
1523: if (combined == 0)
1524: return XEXP (XEXP (x, 0), 0);
1525: if (!undobuf.storage)
1526: undobuf.storage = (char *) oballoc (0);
1527: SUBST (XEXP (x, 1), gen_rtx (CONST_INT, VOIDmode, combined));
1528: SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0));
1529: break;
1530: }
1531:
1.1 root 1532: case FLOAT:
1533: /* (float (sign_extend <X>)) = (float <X>). */
1.1.1.2 root 1534: if (was_replaced[0]
1.1 root 1535: && GET_CODE (to) == SIGN_EXTEND)
1.1.1.2 root 1536: SUBST (XEXP (x, 0), XEXP (to, 0));
1.1 root 1537: break;
1538:
1539: case ZERO_EXTRACT:
1.1.1.2 root 1540: /* (ZERO_EXTRACT (TRUNCATE x)...)
1541: can become (ZERO_EXTRACT x ...). */
1542: if (was_replaced[0]
1543: && GET_CODE (to) == TRUNCATE)
1544: {
1545: #ifdef BITS_BIG_ENDIAN
1546: if (GET_CODE (XEXP (x, 2)) == CONST_INT)
1547: {
1548: if (!undobuf.storage)
1549: undobuf.storage = (char *) oballoc (0);
1550: /* On a big-endian machine, must increment the bit-number
1551: since sign bit is farther away in the pre-truncated value. */
1552: return gen_rtx (ZERO_EXTRACT, GET_MODE (x),
1553: XEXP (to, 0),
1554: XEXP (x, 1),
1555: gen_rtx (CONST_INT, VOIDmode,
1556: (INTVAL (XEXP (x, 2))
1557: + GET_MODE_BITSIZE (GET_MODE (XEXP (to, 0)))
1558: - GET_MODE_BITSIZE (GET_MODE (to)))));
1559: }
1560: #else
1561: SUBST (XEXP (x, 0), XEXP (to, 0));
1562: #endif
1563: }
1.1 root 1564: /* Extracting a single bit from the result of a shift:
1565: see which bit it was before the shift and extract that directly. */
1.1.1.2 root 1566: if (was_replaced[0]
1.1 root 1567: && (GET_CODE (to) == ASHIFTRT || GET_CODE (to) == LSHIFTRT
1568: || GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
1569: && GET_CODE (XEXP (to, 1)) == CONST_INT
1570: && XEXP (x, 1) == const1_rtx
1571: && GET_CODE (XEXP (x, 2)) == CONST_INT)
1572: {
1573: int shift = INTVAL (XEXP (to, 1));
1574: int newpos;
1575: if (GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
1576: shift = - shift;
1577: #ifdef BITS_BIG_ENDIAN
1578: shift = - shift;
1579: #endif
1580: newpos = INTVAL (XEXP (x, 2)) + shift;
1581: if (newpos >= 0 &&
1.1.1.2 root 1582: newpos < GET_MODE_BITSIZE (GET_MODE (to)))
1.1 root 1583: {
1584: if (!undobuf.storage)
1585: undobuf.storage = (char *) oballoc (0);
1586: return gen_rtx (ZERO_EXTRACT, GET_MODE (x),
1587: XEXP (to, 0), const1_rtx,
1588: gen_rtx (CONST_INT, VOIDmode, newpos));
1589: }
1590: }
1591: break;
1592:
1593: case LSHIFTRT:
1594: case ASHIFTRT:
1595: case ROTATE:
1596: case ROTATERT:
1597: #ifdef SHIFT_COUNT_TRUNCATED
1598: /* (lshift <X> (sign_extend <Y>)) = (lshift <X> <Y>) (most machines).
1599: True for all kinds of shifts and also for zero_extend. */
1.1.1.2 root 1600: if (was_replaced[1]
1.1 root 1601: && (GET_CODE (to) == SIGN_EXTEND
1.1.1.2 root 1602: || GET_CODE (to) == ZERO_EXTEND)
1603: && FAKE_EXTEND_SAFE_P (GET_MODE (to), XEXP (to, 0)))
1.1 root 1604: {
1605: if (!undobuf.storage)
1606: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1607: SUBST (XEXP (x, 1),
1608: /* This is a perverse SUBREG, wider than its base. */
1609: gen_lowpart_for_combine (GET_MODE (to), XEXP (to, 0)));
1.1 root 1610: }
1611: #endif
1612: /* Two shifts in a row of same kind
1613: in same direction with constant counts
1614: may be combined. */
1.1.1.2 root 1615: if (was_replaced[0]
1.1 root 1616: && GET_CODE (to) == GET_CODE (x)
1617: && GET_CODE (XEXP (x, 1)) == CONST_INT
1618: && GET_CODE (XEXP (to, 1)) == CONST_INT
1619: && INTVAL (XEXP (to, 1)) > 0
1620: && INTVAL (XEXP (x, 1)) > 0
1621: && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (to, 1))
1.1.1.2 root 1622: < GET_MODE_BITSIZE (GET_MODE (x))))
1.1 root 1623: {
1624: if (!undobuf.storage)
1625: undobuf.storage = (char *) oballoc (0);
1626: return gen_rtx (GET_CODE (x), GET_MODE (x),
1627: XEXP (to, 0),
1628: gen_rtx (CONST_INT, VOIDmode,
1629: INTVAL (XEXP (x, 1))
1630: + INTVAL (XEXP (to, 1))));
1631: }
1632: break;
1633:
1634: case LSHIFT:
1635: case ASHIFT:
1636: #ifdef SHIFT_COUNT_TRUNCATED
1637: /* (lshift <X> (sign_extend <Y>)) = (lshift <X> <Y>) (most machines).
1638: True for all kinds of shifts and also for zero_extend. */
1.1.1.2 root 1639: if (was_replaced[1]
1.1 root 1640: && (GET_CODE (to) == SIGN_EXTEND
1.1.1.4 root 1641: || GET_CODE (to) == ZERO_EXTEND)
1642: && GET_CODE (to) == REG)
1.1 root 1643: {
1644: if (!undobuf.storage)
1645: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1646: SUBST (XEXP (x, 1), gen_rtx (SUBREG, GET_MODE (to), XEXP (to, 0), 0));
1.1 root 1647: }
1648: #endif
1649: /* (lshift (and (lshiftrt <foo> <X>) <Y>) <X>)
1650: happens copying between bit fields in similar structures.
1651: It can be replaced by one and instruction.
1652: It does not matter whether the shifts are logical or arithmetic. */
1653: if (GET_CODE (XEXP (x, 0)) == AND
1654: && GET_CODE (XEXP (x, 1)) == CONST_INT
1655: && INTVAL (XEXP (x, 1)) > 0
1656: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1.1.1.2 root 1657: && XEXP (XEXP (x, 0), 0) == to
1.1 root 1658: && (GET_CODE (to) == LSHIFTRT
1659: || GET_CODE (to) == ASHIFTRT)
1660: #if 0
1661: /* I now believe this restriction is unnecessary.
1662: The outer shift will discard those bits in any case, right? */
1663:
1664: /* If inner shift is arithmetic, either it shifts left or
1665: the bits it shifts the sign into are zeroed by the and. */
1666: && (INTVAL (XEXP (x, 1)) < 0
1667: || ((unsigned) INTVAL (XEXP (XEXP (x, 0), 1))
1668: < 1 << (GET_MODE_BITSIZE (GET_MODE (x))
1669: - INTVAL (XEXP (x, 0)))))
1670: #endif
1671: && GET_CODE (XEXP (to, 1)) == CONST_INT
1672: && INTVAL (XEXP (x, 1)) == INTVAL (XEXP (to, 1)))
1673: {
1674: if (!undobuf.storage)
1675: undobuf.storage = (char *) oballoc (0);
1676: /* The constant in the new `and' is <Y> << <X>
1677: but clear out all bits that don't belong in our mode. */
1678: return gen_rtx (AND, GET_MODE (x), XEXP (to, 0),
1679: gen_rtx (CONST_INT, VOIDmode,
1680: (GET_MODE_MASK (GET_MODE (x))
1681: & ((GET_MODE_MASK (GET_MODE (x))
1682: & INTVAL (XEXP (XEXP (x, 0), 1)))
1683: << INTVAL (XEXP (x, 1))))));
1684: }
1685: /* Two shifts in a row in same direction with constant counts
1686: may be combined. */
1.1.1.2 root 1687: if (was_replaced[0]
1.1 root 1688: && (GET_CODE (to) == ASHIFT || GET_CODE (to) == LSHIFT)
1689: && GET_CODE (XEXP (x, 1)) == CONST_INT
1690: && GET_CODE (XEXP (to, 1)) == CONST_INT
1691: && INTVAL (XEXP (to, 1)) > 0
1692: && INTVAL (XEXP (x, 1)) > 0
1693: && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (to, 1))
1.1.1.2 root 1694: < GET_MODE_BITSIZE (GET_MODE (x))))
1.1 root 1695: {
1696: if (!undobuf.storage)
1697: undobuf.storage = (char *) oballoc (0);
1698: return gen_rtx (GET_CODE (x), GET_MODE (x),
1699: XEXP (to, 0),
1700: gen_rtx (CONST_INT, VOIDmode,
1701: INTVAL (XEXP (x, 1))
1702: + INTVAL (XEXP (to, 1))));
1703: }
1704: /* (ashift (ashiftrt <foo> <X>) <X>)
1705: (or, on some machines, (ashift (ashift <foo> <-X>) <X>) instead)
1706: happens if you divide by 2**N and then multiply by 2**N.
1707: It can be replaced by one `and' instruction.
1708: It does not matter whether the shifts are logical or arithmetic. */
1709: if (GET_CODE (XEXP (x, 1)) == CONST_INT
1710: && INTVAL (XEXP (x, 1)) > 0
1.1.1.2 root 1711: && was_replaced[0]
1.1 root 1712: && (((GET_CODE (to) == LSHIFTRT || GET_CODE (to) == ASHIFTRT)
1713: && GET_CODE (XEXP (to, 1)) == CONST_INT
1714: && INTVAL (XEXP (x, 1)) == INTVAL (XEXP (to, 1)))
1715: ||
1716: ((GET_CODE (to) == LSHIFT || GET_CODE (to) == ASHIFT)
1717: && GET_CODE (XEXP (to, 1)) == CONST_INT
1718: && INTVAL (XEXP (x, 1)) == - INTVAL (XEXP (to, 1)))))
1719: {
1720: if (!undobuf.storage)
1721: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1722: /* The constant in the new `and' is -1 << <X>
1.1 root 1723: but clear out all bits that don't belong in our mode. */
1724: return gen_rtx (AND, GET_MODE (x), XEXP (to, 0),
1725: gen_rtx (CONST_INT, VOIDmode,
1726: (GET_MODE_MASK (GET_MODE (x))
1727: & (GET_MODE_MASK (GET_MODE (x))
1728: << INTVAL (XEXP (x, 1))))));
1729: }
1730:
1731: }
1732:
1733: return x;
1734: }
1735:
1736: /* This is the AND case of the function subst. */
1737:
1738: static rtx
1.1.1.2 root 1739: simplify_and_const_int (x, to)
1740: rtx x, to;
1.1 root 1741: {
1742: register rtx varop = XEXP (x, 0);
1743: register int constop = INTVAL (XEXP (x, 1));
1744:
1745: /* (and (subreg (and <foo> <constant>) 0) <constant>)
1746: results from an andsi followed by an andqi,
1747: which happens frequently when storing bit-fields
1748: on something whose result comes from an andsi. */
1749: if (GET_CODE (varop) == SUBREG
1.1.1.2 root 1750: && XEXP (varop, 0) == to
1.1 root 1751: && subreg_lowpart_p (varop)
1752: && GET_CODE (to) == AND
1753: && GET_CODE (XEXP (to, 1)) == CONST_INT
1754: /* Verify that the result of the outer `and'
1755: is not affected by any bits not defined in the inner `and'.
1756: True if the outer mode is narrower, or if the outer constant
1757: masks to zero all the bits that the inner mode doesn't have. */
1.1.1.2 root 1758: && (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (GET_MODE (to))
1759: || (constop & ~ GET_MODE_MASK (GET_MODE (to))) == 0))
1.1 root 1760: {
1761: if (!undobuf.storage)
1762: undobuf.storage = (char *) oballoc (0);
1763: return gen_rtx (AND, GET_MODE (x),
1.1.1.2 root 1764: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1.1 root 1765: gen_rtx (CONST_INT, VOIDmode,
1766: constop
1767: /* Remember that the bits outside that mode
1768: are not being changed, so the effect
1769: is as if they were all 1. */
1770: & INTVAL (XEXP (to, 1))));
1771: }
1.1.1.2 root 1772: /* (and:SI (zero_extract:SI ...) <constant>)
1773: results from an andsi following a byte-fetch on risc machines.
1774: When the constant includes all bits extracted, eliminate the `and'. */
1775: if (GET_CODE (varop) == ZERO_EXTRACT
1776: && GET_CODE (XEXP (varop, 1)) == CONST_INT
1777: /* The `and' must not clear any bits that the extract can give. */
1778: && (~ constop & ((1 << INTVAL (XEXP (varop, 1))) - 1)) == 0)
1779: return varop;
1.1 root 1780: /* (and (zero_extend <foo>) <constant>)
1781: often results from storing in a bit-field something
1782: that was calculated as a short. Replace with a single `and'
1783: in whose constant all bits not in <foo>'s mode are zero. */
1.1.1.2 root 1784: if (varop == to
1785: && GET_CODE (to) == ZERO_EXTEND
1786: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0)))
1.1 root 1787: {
1788: if (!undobuf.storage)
1789: undobuf.storage = (char *) oballoc (0);
1790: return gen_rtx (AND, GET_MODE (x),
1.1.1.2 root 1791: /* This is a perverse SUBREG, wider than its base. */
1792: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1.1 root 1793: gen_rtx (CONST_INT, VOIDmode,
1.1.1.2 root 1794: constop & GET_MODE_MASK (GET_MODE (XEXP (to, 0)))));
1.1 root 1795: }
1796: /* (and (sign_extend <foo>) <constant>)
1797: can be replaced with (and (subreg <foo>) <constant>)
1798: if <constant> is narrower than <foo>'s mode,
1799: or with (zero_extend <foo>) if <constant> is a mask for that mode. */
1.1.1.2 root 1800: if (varop == to
1.1 root 1801: && GET_CODE (to) == SIGN_EXTEND
1.1.1.2 root 1802: && ((unsigned) constop <= GET_MODE_MASK (GET_MODE (XEXP (to, 0))))
1803: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0)))
1.1 root 1804: {
1805: if (!undobuf.storage)
1806: undobuf.storage = (char *) oballoc (0);
1.1.1.2 root 1807: if (constop == GET_MODE_MASK (GET_MODE (XEXP (to, 0))))
1.1 root 1808: return gen_rtx (ZERO_EXTEND, GET_MODE (x), XEXP (to, 0));
1809: return gen_rtx (AND, GET_MODE (x),
1.1.1.2 root 1810: /* This is a perverse SUBREG, wider than its base. */
1811: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)),
1.1 root 1812: XEXP (x, 1));
1813: }
1814: /* (and (and <foo> <constant>) <constant>)
1815: comes from two and instructions in a row. */
1.1.1.2 root 1816: if (varop == to
1.1 root 1817: && GET_CODE (to) == AND
1818: && GET_CODE (XEXP (to, 1)) == CONST_INT)
1819: {
1820: if (!undobuf.storage)
1821: undobuf.storage = (char *) oballoc (0);
1822: return gen_rtx (AND, GET_MODE (x),
1823: XEXP (to, 0),
1824: gen_rtx (CONST_INT, VOIDmode,
1825: constop
1826: & INTVAL (XEXP (to, 1))));
1827: }
1828: /* (and (ashiftrt (ashift FOO N) N) CONST)
1829: may be simplified to (and FOO CONST) if CONST masks off the bits
1830: changed by the two shifts. */
1831: if (GET_CODE (varop) == ASHIFTRT
1832: && GET_CODE (XEXP (varop, 1)) == CONST_INT
1.1.1.2 root 1833: && XEXP (varop, 0) == to
1.1 root 1834: && GET_CODE (to) == ASHIFT
1835: && GET_CODE (XEXP (to, 1)) == CONST_INT
1836: && INTVAL (XEXP (varop, 1)) == INTVAL (XEXP (to, 1))
1837: && ((unsigned) constop >> INTVAL (XEXP (varop, 1))) == 0)
1838: {
1839: if (!undobuf.storage)
1840: undobuf.storage = (char *) oballoc (0);
1841: /* If CONST is a mask for the low byte,
1842: change this into a zero-extend instruction
1843: from just the low byte of FOO. */
1.1.1.2 root 1844: if (constop == GET_MODE_MASK (QImode))
1.1 root 1845: {
1846: rtx temp = gen_lowpart_for_combine (QImode, XEXP (to, 0));
1.1.1.2 root 1847: if (GET_CODE (temp) != CLOBBER)
1.1 root 1848: return gen_rtx (ZERO_EXTEND, GET_MODE (x), temp);
1849: }
1850: return gen_rtx (AND, GET_MODE (x),
1851: XEXP (to, 0), XEXP (x, 1));
1852: }
1.1.1.15 root 1853: /* (and (ashiftrt (zero_extend FOO) N) CONST)
1854: may be simplified to (and (ashiftrt (subreg FOO) N) CONST)
1855: if CONST masks off the bits changed by extension. */
1856: if ((GET_CODE (varop) == ASHIFTRT || GET_CODE (varop) == LSHIFTRT)
1857: && GET_CODE (XEXP (varop, 1)) == CONST_INT
1858: && XEXP (varop, 0) == to
1859: && (GET_CODE (to) == ZERO_EXTEND || GET_CODE (to) == SIGN_EXTEND)
1860: /* Verify the and discards all the extended bits. */
1861: && (((unsigned) constop << INTVAL (XEXP (varop, 1)))
1862: >> GET_MODE_BITSIZE (GET_MODE (XEXP (to, 0)))) == 0
1863: && FAKE_EXTEND_SAFE_P (GET_MODE (x), XEXP (to, 0)))
1864: {
1865: if (!undobuf.storage)
1866: undobuf.storage = (char *) oballoc (0);
1867: SUBST (XEXP (varop, 0),
1868: gen_lowpart_for_combine (GET_MODE (x), XEXP (to, 0)));
1869: return x;
1870: }
1.1.1.2 root 1871: /* (and x const) may be converted to (zero_extend (subreg x 0)). */
1.1.1.4 root 1872: if (constop == GET_MODE_MASK (QImode)
1873: && GET_CODE (varop) == REG)
1.1.1.2 root 1874: {
1875: if (!undobuf.storage)
1876: undobuf.storage = (char *) oballoc (0);
1877: return gen_rtx (ZERO_EXTEND, GET_MODE (x),
1878: gen_rtx (SUBREG, QImode, varop, 0));
1879: }
1.1.1.4 root 1880: if (constop == GET_MODE_MASK (HImode)
1881: && GET_CODE (varop) == REG)
1.1.1.2 root 1882: {
1883: if (!undobuf.storage)
1884: undobuf.storage = (char *) oballoc (0);
1885: return gen_rtx (ZERO_EXTEND, GET_MODE (x),
1886: gen_rtx (SUBREG, HImode, varop, 0));
1887: }
1.1 root 1888: /* No simplification applies. */
1889: return 0;
1890: }
1891:
1892: /* Like gen_lowpart but for use by combine. In combine it is not possible
1893: to create any new pseudoregs. However, it is safe to create
1894: invalid memory addresses, because combine will try to recognize
1895: them and all they will do is make the combine attempt fail.
1896:
1.1.1.2 root 1897: If for some reason this cannot do its job, an rtx
1898: (clobber (const_int 0)) is returned.
1899: An insn containing that will not be recognized. */
1900:
1901: #undef gen_lowpart
1.1 root 1902:
1903: static rtx
1904: gen_lowpart_for_combine (mode, x)
1905: enum machine_mode mode;
1906: register rtx x;
1907: {
1908: if (GET_CODE (x) == SUBREG || GET_CODE (x) == REG)
1909: return gen_lowpart (mode, x);
1.1.1.9 root 1910: if (GET_MODE (x) == mode)
1.1.1.2 root 1911: return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
1.1 root 1912: if (GET_CODE (x) == MEM)
1913: {
1914: register int offset = 0;
1.1.1.7 root 1915:
1.1.1.9 root 1916: /* Refuse to work on a volatile memory ref. */
1917: if (MEM_VOLATILE_P (x))
1918: return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
1919:
1.1.1.7 root 1920: /* If we want to refer to something bigger than the original memref,
1921: generate a perverse subreg instead. That will force a reload
1922: of the original memref X. */
1923: if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
1924: return gen_rtx (SUBREG, mode, x, 0);
1925:
1.1 root 1926: #ifdef WORDS_BIG_ENDIAN
1927: offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1928: - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1929: #endif
1930: #ifdef BYTES_BIG_ENDIAN
1.1.1.2 root 1931: /* Adjust the address so that the address-after-the-data
1932: is unchanged. */
1933: offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1934: - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1.1 root 1935: #endif
1936: return gen_rtx (MEM, mode, plus_constant (XEXP (x, 0),
1937: offset));
1938: }
1939: else
1.1.1.2 root 1940: return gen_rtx (CLOBBER, VOIDmode, const0_rtx);
1.1 root 1941: }
1942:
1943: /* After substitution, if the resulting pattern looks like
1.1.1.2 root 1944: (set (cc0) (and ...)) or (set (cc0) (lshiftrt ...)),
1945: this function is called to simplify the
1.1 root 1946: pattern into a bit-field operation if possible. */
1947:
1948: static void
1949: simplify_set_cc0_and (insn)
1950: rtx insn;
1951: {
1952: register rtx value = XEXP (PATTERN (insn), 1);
1953: register rtx op0 = XEXP (value, 0);
1954: register rtx op1 = XEXP (value, 1);
1955: int offset = 0;
1956: rtx var = 0;
1957: rtx bitnum = 0;
1958: int temp;
1959: int unit;
1.1.1.2 root 1960: rtx newpat;
1961:
1962: if (GET_CODE (value) == AND)
1963: {
1964: op0 = XEXP (value, 0);
1965: op1 = XEXP (value, 1);
1966: }
1967: else if (GET_CODE (value) == LSHIFTRT)
1968: {
1969: /* If there is no AND, but there is a shift that discards
1970: all but the sign bit, we can pretend that the shift result
1971: is ANDed with 1. Otherwise we cannot handle just a shift. */
1972: if (GET_CODE (XEXP (value, 1)) == CONST_INT
1973: && (INTVAL (XEXP (value, 1))
1974: == GET_MODE_BITSIZE (GET_MODE (value)) - 1))
1975: {
1976: op0 = value;
1977: op1 = const1_rtx;
1978: }
1979: else
1980: return;
1981: }
1982: else
1983: abort ();
1.1 root 1984:
1985: /* Look for a constant power of 2 or a shifted 1
1986: on either side of the AND. Set VAR to the other side.
1987: Set BITNUM to the shift count of the 1 (as an rtx).
1988: Or, if bit number is constant, set OFFSET to the bit number. */
1989:
1990: switch (GET_CODE (op0))
1991: {
1992: case CONST_INT:
1993: temp = exact_log2 (INTVAL (op0));
1994: if (temp < 0)
1995: return;
1996: offset = temp;
1997: var = op1;
1998: break;
1999:
2000: case ASHIFT:
2001: case LSHIFT:
2002: if (XEXP (op0, 0) == const1_rtx)
2003: {
2004: bitnum = XEXP (op0, 1);
2005: var = op1;
2006: }
2007: }
2008: if (var == 0)
2009: switch (GET_CODE (op1))
2010: {
2011: case CONST_INT:
2012: temp = exact_log2 (INTVAL (op1));
2013: if (temp < 0)
2014: return;
2015: offset = temp;
2016: var = op0;
2017: break;
2018:
2019: case ASHIFT:
2020: case LSHIFT:
2021: if (XEXP (op1, 0) == const1_rtx)
2022: {
2023: bitnum = XEXP (op1, 1);
2024: var = op0;
2025: }
2026: }
2027:
2028: /* If VAR is 0, we didn't find something recognizable. */
2029: if (var == 0)
2030: return;
2031:
2032: if (!undobuf.storage)
2033: undobuf.storage = (char *) oballoc (0);
2034:
2035: /* If the bit position is currently exactly 0,
2036: extract a right-shift from the variable portion. */
2037: if (offset == 0
2038: && (GET_CODE (var) == ASHIFTRT || GET_CODE (var) == LSHIFTRT))
2039: {
2040: bitnum = XEXP (var, 1);
2041: var = XEXP (var, 0);
2042: }
2043:
1.1.1.2 root 2044: if (GET_CODE (var) == SUBREG && SUBREG_WORD (var) == 0)
2045: var = SUBREG_REG (var);
2046:
2047: /* Note that BITNUM and OFFSET are always little-endian thru here
2048: even on a big-endian machine. */
2049:
1.1 root 2050: #ifdef BITS_BIG_ENDIAN
1.1.1.2 root 2051: unit = GET_MODE_BITSIZE (GET_MODE (var)) - 1;
1.1 root 2052:
2053: if (bitnum != 0)
2054: bitnum = gen_rtx (MINUS, SImode,
2055: gen_rtx (CONST_INT, VOIDmode, unit), bitnum);
2056: else
2057: offset = unit - offset;
2058: #endif
2059:
2060: if (bitnum == 0)
2061: bitnum = gen_rtx (CONST_INT, VOIDmode, offset);
2062:
1.1.1.2 root 2063: newpat = gen_rtx (SET, VOIDmode, cc0_rtx,
2064: gen_rtx (ZERO_EXTRACT, VOIDmode, var, const1_rtx, bitnum));
2065: if (recog (newpat, insn) >= 0)
1.1 root 2066: {
1.1.1.2 root 2067: if (undobuf.num_undo < MAX_UNDO)
2068: {
2069: undobuf.undo[undobuf.num_undo].where = &XEXP (PATTERN (insn), 1);
2070: undobuf.undo[undobuf.num_undo].old_contents = value;
2071: XEXP (PATTERN (insn), 1) = XEXP (newpat, 1);
2072: }
2073: undobuf.num_undo++;
1.1 root 2074: }
2075: }
2076:
2077: /* Update the records of when each REG was most recently set or killed
2078: for the things done by INSN. This is the last thing done in processing
2079: INSN in the combiner loop.
2080:
2081: We update reg_last_set, reg_last_death, and also the similar information
2082: mem_last_set (which insn most recently modified memory)
2083: and last_call_cuid (which insn was the most recent subroutine call). */
2084:
2085: static void
2086: record_dead_and_set_regs (insn)
2087: rtx insn;
2088: {
2089: register rtx link;
2090: for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
2091: {
1.1.1.2 root 2092: if (REG_NOTE_KIND (link) == REG_DEAD)
1.1 root 2093: reg_last_death[REGNO (XEXP (link, 0))] = insn;
1.1.1.2 root 2094: else if (REG_NOTE_KIND (link) == REG_INC)
1.1 root 2095: reg_last_set[REGNO (XEXP (link, 0))] = insn;
2096: }
2097:
2098: if (GET_CODE (insn) == CALL_INSN)
2099: last_call_cuid = mem_last_set = INSN_CUID (insn);
2100:
2101: if (GET_CODE (PATTERN (insn)) == PARALLEL)
2102: {
2103: register int i;
2104: for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
2105: {
2106: register rtx elt = XVECEXP (PATTERN (insn), 0, i);
2107: register enum rtx_code code = GET_CODE (elt);
2108: if (code == SET || code == CLOBBER)
2109: {
1.1.1.15 root 2110: rtx dest = XEXP (elt, 0);
2111: while (GET_CODE (dest) == SUBREG
2112: || GET_CODE (dest) == STRICT_LOW_PART
2113: || GET_CODE (dest) == SIGN_EXTRACT
2114: || GET_CODE (dest) == ZERO_EXTRACT)
2115: dest = XEXP (dest, 0);
2116:
2117: if (GET_CODE (dest) == REG)
2118: reg_last_set[REGNO (dest)] = insn;
2119: else if (GET_CODE (dest) == MEM)
1.1 root 2120: mem_last_set = INSN_CUID (insn);
2121: }
2122: }
2123: }
2124: else if (GET_CODE (PATTERN (insn)) == SET
2125: || GET_CODE (PATTERN (insn)) == CLOBBER)
2126: {
1.1.1.15 root 2127: register rtx dest = XEXP (PATTERN (insn), 0);
2128:
2129: while (GET_CODE (dest) == SUBREG
2130: || GET_CODE (dest) == STRICT_LOW_PART
2131: || GET_CODE (dest) == SIGN_EXTRACT
2132: || GET_CODE (dest) == ZERO_EXTRACT)
2133: dest = XEXP (dest, 0);
2134:
2135: if (GET_CODE (dest) == REG)
2136: reg_last_set[REGNO (dest)] = insn;
2137: else if (GET_CODE (dest) == MEM)
1.1 root 2138: mem_last_set = INSN_CUID (insn);
2139: }
2140: }
2141:
2142: /* Return nonzero if expression X refers to a REG or to memory
2143: that is set in an instruction more recent than FROM_CUID. */
2144:
2145: static int
2146: use_crosses_set_p (x, from_cuid)
2147: register rtx x;
2148: int from_cuid;
2149: {
2150: register char *fmt;
2151: register int i;
2152: register enum rtx_code code = GET_CODE (x);
2153:
2154: if (code == REG)
2155: {
2156: register int regno = REGNO (x);
1.1.1.10 root 2157: #ifdef PUSH_ROUNDING
2158: /* Don't allow uses of the stack pointer to be moved,
2159: because we don't know whether the move crosses a push insn. */
2160: if (regno == STACK_POINTER_REGNUM)
2161: return 1;
2162: #endif
1.1 root 2163: return (reg_last_set[regno]
2164: && INSN_CUID (reg_last_set[regno]) > from_cuid);
2165: }
2166:
2167: if (code == MEM && mem_last_set > from_cuid)
2168: return 1;
2169:
2170: fmt = GET_RTX_FORMAT (code);
2171:
1.1.1.9 root 2172: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1.1 root 2173: {
2174: if (fmt[i] == 'E')
2175: {
2176: register int j;
2177: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2178: if (use_crosses_set_p (XVECEXP (x, i, j), from_cuid))
2179: return 1;
2180: }
2181: else if (fmt[i] == 'e'
2182: && use_crosses_set_p (XEXP (x, i), from_cuid))
2183: return 1;
2184: }
2185: return 0;
2186: }
2187:
2188: /* Return nonzero if reg REGNO is marked as dying in INSN. */
2189:
2190: int
2191: regno_dead_p (regno, insn)
2192: int regno;
2193: rtx insn;
2194: {
2195: register rtx link;
2196:
2197: for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1.1.1.2 root 2198: if ((REG_NOTE_KIND (link) == REG_DEAD
2199: || REG_NOTE_KIND (link) == REG_INC)
2200: && REGNO (XEXP (link, 0)) == regno)
1.1 root 2201: return 1;
2202:
2203: return 0;
2204: }
2205:
2206: /* Return nonzero if J is the first insn following I,
2207: not counting labels, line numbers, etc.
2208: We assume that J follows I. */
2209:
2210: static int
2211: adjacent_insns_p (i, j)
2212: rtx i, j;
2213: {
2214: register rtx insn;
2215: for (insn = NEXT_INSN (i); insn != j; insn = NEXT_INSN (insn))
2216: if (GET_CODE (insn) == INSN
2217: || GET_CODE (insn) == CALL_INSN
2218: || GET_CODE (insn) == JUMP_INSN)
2219: return 0;
2220: return 1;
2221: }
2222:
1.1.1.11 root 2223: /* Check that X is an insn-body for an `asm' with operands
2224: and that the operands mentioned in it are legitimate. */
2225:
2226: static int
2227: check_asm_operands (x)
2228: rtx x;
2229: {
2230: int noperands = asm_noperands (x);
2231: rtx *operands;
2232: int i;
2233:
2234: if (noperands < 0)
2235: return 0;
2236: if (noperands == 0)
2237: return 1;
2238:
2239: operands = (rtx *) alloca (noperands * sizeof (rtx));
2240: decode_asm_operands (x, operands, 0, 0, 0);
2241:
2242: for (i = 0; i < noperands; i++)
2243: if (!general_operand (operands[i], VOIDmode))
2244: return 0;
2245:
2246: return 1;
2247: }
2248:
1.1.1.2 root 2249: /* Concatenate the list of logical links of OINSN
1.1 root 2250: into INSN's list of logical links.
1.1.1.2 root 2251: Modifies OINSN destructively.
2252:
2253: If ALL_LINKS is nonzero, move all the links that OINSN has.
2254: Otherwise, move only those that point to insns that set regs
2255: that die in the insn OINSN.
2256: Other links are clobbered so that they are no longer effective. */
1.1 root 2257:
2258: static void
1.1.1.2 root 2259: add_links (insn, oinsn, all_links)
2260: rtx insn, oinsn;
2261: int all_links;
1.1 root 2262: {
1.1.1.2 root 2263: register rtx links = LOG_LINKS (oinsn);
2264: if (! all_links)
2265: {
2266: rtx tail;
2267: for (tail = links; tail; tail = XEXP (tail, 1))
2268: {
2269: rtx target = XEXP (tail, 0);
2270: if (GET_CODE (target) != INSN
2271: || GET_CODE (PATTERN (target)) != SET
2272: || GET_CODE (SET_DEST (PATTERN (target))) != REG
2273: || ! dead_or_set_p (oinsn, SET_DEST (PATTERN (target))))
2274: /* OINSN is going to become a NOTE
2275: so a link pointing there will have no effect. */
2276: XEXP (tail, 0) = oinsn;
2277: }
2278: }
1.1 root 2279: if (LOG_LINKS (insn) == 0)
2280: LOG_LINKS (insn) = links;
2281: else
2282: {
2283: register rtx next, prev = LOG_LINKS (insn);
2284: while (next = XEXP (prev, 1))
2285: prev = next;
2286: XEXP (prev, 1) = links;
2287: }
2288: }
1.1.1.7 root 2289:
2290: /* Delete any LOG_LINKS of INSN which point at OINSN. */
2291:
2292: static void
2293: remove_links (insn, oinsn)
2294: rtx insn, oinsn;
2295: {
2296: register rtx next = LOG_LINKS (insn), prev = 0;
2297: while (next)
2298: {
2299: if (XEXP (next, 0) == oinsn)
2300: {
2301: if (prev)
2302: XEXP (prev, 1) = XEXP (next, 1);
2303: else
2304: LOG_LINKS (insn) = XEXP (next, 1);
2305: }
2306: else
2307: prev = next;
2308: next = XEXP (next, 1);
2309: }
2310: }
1.1 root 2311:
2312: /* Concatenate the any elements of the list of reg-notes INCS
2313: which are of type REG_INC
2314: into INSN's list of reg-notes. */
2315:
2316: static void
2317: add_incs (insn, incs)
2318: rtx insn, incs;
2319: {
2320: register rtx tail;
2321:
2322: for (tail = incs; tail; tail = XEXP (tail, 1))
1.1.1.2 root 2323: if (REG_NOTE_KIND (tail) == REG_INC)
1.1 root 2324: REG_NOTES (insn)
2325: = gen_rtx (EXPR_LIST, REG_INC, XEXP (tail, 0), REG_NOTES (insn));
2326: }
1.1.1.7 root 2327:
2328: /* Remove register number REGNO from the dead registers list of INSN. */
2329:
2330: void
2331: remove_death (regno, insn)
2332: int regno;
2333: rtx insn;
2334: {
2335: register rtx link, next;
2336: while ((link = REG_NOTES (insn))
2337: && REG_NOTE_KIND (link) == REG_DEAD
2338: && REGNO (XEXP (link, 0)) == regno)
2339: REG_NOTES (insn) = XEXP (link, 1);
2340:
2341: if (link)
2342: while (next = XEXP (link, 1))
2343: {
2344: if (REG_NOTE_KIND (next) == REG_DEAD
2345: && REGNO (XEXP (next, 0)) == regno)
2346: XEXP (link, 1) = XEXP (next, 1);
2347: else
2348: link = next;
2349: }
2350: }
1.1 root 2351:
2352: /* For each register (hardware or pseudo) used within expression X,
2353: if its death is in an instruction with cuid
2354: between FROM_CUID (inclusive) and TO_INSN (exclusive),
2355: mark it as dead in TO_INSN instead.
2356:
2357: This is done when X is being merged by combination into TO_INSN. */
2358:
2359: static void
2360: move_deaths (x, from_cuid, to_insn)
2361: rtx x;
2362: int from_cuid;
2363: rtx to_insn;
2364: {
2365: register char *fmt;
2366: register int len, i;
2367: register enum rtx_code code = GET_CODE (x);
2368:
2369: if (code == REG)
2370: {
2371: register rtx where_dead = reg_last_death[REGNO (x)];
2372:
2373: if (where_dead && INSN_CUID (where_dead) >= from_cuid
2374: && INSN_CUID (where_dead) < INSN_CUID (to_insn))
2375: {
2376: remove_death (REGNO (x), reg_last_death[REGNO (x)]);
2377: if (! dead_or_set_p (to_insn, x))
2378: REG_NOTES (to_insn)
2379: = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
2380: }
2381: return;
2382: }
2383:
2384: len = GET_RTX_LENGTH (code);
2385: fmt = GET_RTX_FORMAT (code);
2386:
2387: for (i = 0; i < len; i++)
2388: {
2389: if (fmt[i] == 'E')
2390: {
2391: register int j;
2392: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2393: move_deaths (XVECEXP (x, i, j), from_cuid, to_insn);
2394: }
2395: else if (fmt[i] == 'e')
2396: move_deaths (XEXP (x, i), from_cuid, to_insn);
2397: }
2398: }
2399:
1.1.1.7 root 2400: /* Like move_deaths, but deaths are moving both forward
2401: (from FROM_CUID to TO_INSN), and backwards
2402: (from FROM_INSN to TO_INSN). This is what happens
2403: when an insn is removed after applying the distributive law. */
2404:
2405: static void
2406: move_deaths_2 (x, from_cuid, from_insn, to_insn)
2407: rtx x;
2408: int from_cuid;
2409: rtx from_insn, to_insn;
2410: {
2411: register char *fmt;
2412: register int len, i;
2413: register enum rtx_code code = GET_CODE (x);
2414:
2415: if (code == REG)
2416: {
2417: register rtx where_dead = reg_last_death[REGNO (x)];
2418:
2419: if (where_dead && INSN_CUID (where_dead) >= from_cuid
2420: && INSN_CUID (where_dead) < INSN_CUID (to_insn))
2421: {
2422: remove_death (REGNO (x), reg_last_death[REGNO (x)]);
2423: if (! dead_or_set_p (to_insn, x))
2424: REG_NOTES (to_insn)
2425: = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
2426: }
2427: /* Can't use where_dead for from_insn because it has
2428: not been computed yet. */
2429: else if (dead_or_set_p (from_insn, x))
2430: {
2431: remove_death (REGNO (x), from_insn);
2432: if (! dead_or_set_p (to_insn, x))
2433: REG_NOTES (to_insn)
2434: = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (to_insn));
2435: }
2436: return;
2437: }
2438:
2439: len = GET_RTX_LENGTH (code);
2440: fmt = GET_RTX_FORMAT (code);
2441:
2442: for (i = 0; i < len; i++)
2443: {
2444: if (fmt[i] == 'E')
2445: {
2446: register int j;
2447: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2448: move_deaths_2 (XVECEXP (x, i, j), from_cuid, from_insn, to_insn);
2449: }
2450: else if (fmt[i] == 'e')
2451: move_deaths_2 (XEXP (x, i), from_cuid, from_insn, to_insn);
2452: }
2453: }
2454:
2455: /* The distrib combiner rewrites groups of insns so that optimizations
2456: can be more easily recognized. The front-end does not know how to
2457: group certain kinds of operations for efficient execution, and the
2458: resulting code can be quite poor. For example, on a machine without
2459: bitfield instructions, bitfield references look like
2460:
2461: (and (lshiftrt ... n) m)
2462:
2463: When combining two bitfield operations, such as with ||, this can
2464: yield code like
2465:
2466: (set z
2467: (or (and (lshiftrt x n) 1)
2468: (and (lshiftrt y n) 1)))
2469:
2470: which can be more efficiently executed as
2471:
2472: (set z
2473: (lshiftrt (and (or x y)
2474: (1 << m)) n))
2475:
2476: From there, the combiner attempts to rewrite the insns,
2477: keeping flow information accurate for later passes,
2478: and reducing the total number of insns executed.
2479:
2480: This function returns the point at which we should try
2481: looking for more simplifications. This will be before
2482: INSN if the call succeeds. We do not need to fear
2483: infinite loops, since this function is guaranteed to
2484: eliminate at least one (non-note) instruction if it returns
2485: successfully. */
2486:
2487: static rtx
2488: try_distrib (insn, xprev1, xprev2)
2489: rtx insn, xprev1, xprev2;
2490: {
2491: rtx pat = PATTERN (insn);
2492: rtx prev1, prev2, pat1, pat2, src1, src2;
2493: rtx to_prev, to_insn;
2494: enum rtx_code code;
1.1.1.9 root 2495: int insn_code_number, prev_code_number, regno;
1.1.1.7 root 2496: rtx new_insn_pat, new_prev_pat;
2497:
2498: distrib_attempts++;
2499:
2500: /* ??? Need to implement a test that PREV2 and PREV1
2501: are completely independent. Right now their
2502: recognition ability is sufficiently limited that
2503: it should not be necessary, but better safe than sorry. */
2504:
2505: /* Let PREV1 be the later of the two insns, and PREV2 the earlier. */
2506: if (INSN_CUID (xprev1) > INSN_CUID (xprev2))
2507: {
2508: prev1 = xprev1;
2509: prev2 = xprev2;
2510: }
2511: else
2512: {
2513: prev1 = xprev2;
2514: prev2 = xprev1;
2515: }
2516:
2517: pat1 = PATTERN (prev1);
2518: pat2 = PATTERN (prev2);
2519:
2520: /* First, see if INSN, PREV1, and PREV2 have patterns we can expect
2521: to simplify. */
2522:
2523: if (GET_CODE (pat) != SET
2524: || GET_CODE (pat1) != SET
2525: || GET_CODE (pat2) != SET)
2526: return 0;
2527:
2528: code = GET_CODE (SET_SRC (pat));
2529: src1 = SET_SRC (pat1);
2530: src2 = SET_SRC (pat2);
2531:
1.1.1.8 root 2532: if (GET_CODE (SET_DEST (pat1)) != REG
2533: || GET_CODE (SET_DEST (pat2)) != REG)
2534: return 0;
2535:
1.1.1.7 root 2536: switch (code)
2537: {
2538: default:
2539: return 0;
2540:
2541: case IOR:
2542: case AND:
2543: case XOR:
2544: case PLUS:
2545: ;
2546: }
2547:
1.1.1.8 root 2548: /* Insns PREV1 and PREV2 must provide the two operands of the arithmetic
2549: that is done in INSN. */
2550: if (! ((XEXP (SET_SRC (pat), 0) == SET_DEST (pat1)
2551: && XEXP (SET_SRC (pat), 1) == SET_DEST (pat2))
2552: ||
2553: (XEXP (SET_SRC (pat), 0) == SET_DEST (pat2)
2554: && XEXP (SET_SRC (pat), 1) == SET_DEST (pat1))))
2555: return 0;
2556:
2557: /* They must not be used in any other way in INSN.
2558: In particular, they must not be used in a result memory address. */
2559: if (reg_mentioned_p (SET_DEST (pat1), SET_DEST (pat))
2560: || reg_mentioned_p (SET_DEST (pat2), SET_DEST (pat)))
2561: return 0;
2562:
2563: /* Give up if the two operands' modes don't match. */
1.1.1.7 root 2564: if (GET_MODE (src1) != GET_MODE (src2))
2565: return 0;
2566:
2567: /* PREV1 and PREV2 must compute the same operation.
2568: Actually, there are other cases that could be handled,
2569: but are not implemented. For example:
2570:
2571: (set (reg:SI 94)
2572: (and:SI (reg:SI 73)
2573: (const_int 223)))
2574:
2575: (set (reg:SI 95)
2576: (zero_extend:SI (subreg:QI (reg:SI 91) 0)))
2577:
2578: (set (reg:SI 96)
2579: (ior:SI (reg:SI 94)
2580: (reg:SI 95)))
2581:
2582: In this case, we know that because (reg:SI 94) has
2583: been anded with 223, there is no need to zero_extend
2584: (reg:SI 91), and we could eliminate (reg:SI 95). */
2585:
2586: if (GET_CODE (src1) != GET_CODE (src2))
2587: return 0;
2588:
2589: /* The SETs in PREV1 and PREV2 do not need to be kept around. */
2590:
2591: undobuf.num_undo = 0;
2592: undobuf.storage = 0;
2593:
2594: /* Substitute in the latest insn for the regs set by the earlier ones. */
2595: subst_insn = insn;
2596: n_occurrences = 0; /* `subst' counts here */
2597:
2598: switch (GET_CODE (src1))
2599: {
1.1.1.14 root 2600: /* case XOR: Does not distribute through anything! */
1.1.1.7 root 2601: case LSHIFTRT:
2602: case ASHIFTRT:
1.1.1.9 root 2603: /* Right-shift can't distribute through addition
2604: since the round-off would happen differently. */
2605: case AND:
2606: case IOR:
2607: /* Boolean ops don't distribute through addition. */
1.1.1.7 root 2608: if (code == PLUS)
2609: return 0;
2610:
2611: case LSHIFT:
2612: case ASHIFT:
1.1.1.9 root 2613: /* Left shifts are multiplication; they distribute through
2614: addition. Also, since they work bitwise, they
2615: distribute through boolean operations. */
2616: goto do_distrib;
2617:
2618: case MULT:
2619: /* Multiplication distributes through addition only. */
2620: if (code != PLUS)
2621: return 0;
2622:
2623: do_distrib:
1.1.1.7 root 2624: if (GET_CODE (XEXP (src1, 1)) != CONST_INT
2625: || GET_CODE (XEXP (src2, 1)) != CONST_INT
2626: || INTVAL (XEXP (src1, 1)) != INTVAL (XEXP (src2, 1)))
2627: return 0;
1.1.1.16! root 2628:
! 2629: /* Give up if we would move a use of a reg across an alteration.
! 2630: Note this is unnecessarily conservative, since a problem really
! 2631: happens only if this reg is set *between* PREV2 and PREV1
! 2632: But this test is easier. */
! 2633: if (use_crosses_set_p (XEXP (src2, 0), INSN_CUID (prev2)))
! 2634: return 0;
! 2635:
! 2636: /* Try changing (+ (* x c) (* y c)) to (* (+ x y) c). */
1.1.1.7 root 2637: to_prev = gen_rtx (code, GET_MODE (src1),
2638: XEXP (src1, 0), XEXP (src2, 0));
2639: to_insn = gen_rtx (GET_CODE (src1), GET_MODE (src1), SET_DEST (pat1), XEXP (src1, 1));
2640: break;
2641:
2642: case ZERO_EXTEND:
2643: case SIGN_EXTEND:
1.1.1.9 root 2644: /* Extension can't distribute through addition;
2645: the carries could be changed. */
2646: if (code == PLUS)
2647: return 0;
1.1.1.7 root 2648: {
2649: rtx inner1 = XEXP (src1, 0), inner2 = XEXP (src2, 0);
2650: int subreg_needed = 0;
2651:
1.1.1.16! root 2652: /* Try changing (& (extend x) (extend y)) to (extend (& x y)). */
1.1.1.7 root 2653: /* But keep extend insns together with their subregs. */
2654: if (GET_CODE (inner1) == SUBREG)
1.1.1.16! root 2655: {
! 2656: if (SUBREG_WORD (inner1) != 0)
! 2657: return 0;
! 2658: else
! 2659: {
! 2660: subreg_needed = 1;
! 2661: inner1 = SUBREG_REG (inner1);
! 2662: }
! 2663: }
1.1.1.7 root 2664:
2665: if (GET_CODE (inner2) == SUBREG)
1.1.1.16! root 2666: {
! 2667: if (SUBREG_WORD (inner2) != 0)
! 2668: return 0;
! 2669: else
! 2670: {
! 2671: subreg_needed = 1;
! 2672: inner2 = SUBREG_REG (inner2);
! 2673: }
! 2674: }
! 2675:
! 2676: /* Give up if we would move a use of a reg across an alteration.
! 2677: Note this is unnecessarily conservative, since a problem really
! 2678: happens only if this reg is set *between* PREV2 and PREV1
! 2679: But this test is easier. */
! 2680: if (use_crosses_set_p (inner2, INSN_CUID (prev2)))
! 2681: return 0;
1.1.1.7 root 2682:
2683: to_prev = gen_rtx (code, GET_MODE (src1), inner1, inner2);
2684: to_insn = gen_rtx (GET_CODE (src1), GET_MODE (src1),
2685: subreg_needed
2686: ? gen_rtx (SUBREG, GET_MODE (XEXP (src1, 0)),
2687: SET_DEST (pat1), 0)
2688: : SET_DEST (pat1));
2689: }
2690: break;
2691:
2692: default:
2693: return 0;
2694: }
2695:
2696: /* Are the results of this "substitution" a valid instruction? */
2697:
2698: new_insn_pat = subst (PATTERN (insn), SET_SRC (PATTERN (insn)), to_insn);
2699: distrib_merges_1++;
2700:
2701: insn_code_number = recog (new_insn_pat, insn);
2702: if (insn_code_number < 0)
2703: {
2704: undo_all ();
2705: return 0;
2706: }
2707:
2708: subst_insn = prev1;
2709: new_prev_pat = subst (pat1, src1, to_prev);
2710: distrib_merges_2++;
2711:
2712: prev_code_number = recog (new_prev_pat, prev1);
2713: if (prev_code_number < 0)
2714: {
2715: undo_all ();
2716: return 0;
2717: }
2718:
2719: /* Everything worked; install the new patterns. */
2720: INSN_CODE (insn) = insn_code_number;
2721: PATTERN (insn) = new_insn_pat;
2722:
2723: INSN_CODE (prev1) = prev_code_number;
2724: PATTERN (prev1) = new_prev_pat;
2725:
2726: /* Need to change LOG_LINKS around...PREV1 now gets
2727: whatever flowed into PREV2. PREV2 is going to
2728: become a NOTE, so we clear out its LOG_LINKS. */
2729: remove_links (insn, prev2);
2730: add_links (prev1, prev2, adjacent_insns_p (prev2, prev1));
2731:
2732: /* Registers which died in PREV2 now die in PREV1.
2733: Also, registers born in PREV2 dying in INSN now die in PREV1. */
2734: move_deaths_2 (src2, INSN_CUID (prev2), insn, prev1);
2735:
2736: regno = REGNO (SET_DEST (pat2));
2737:
2738: reg_n_sets[regno]--;
2739: if (reg_n_sets[regno] == 0
2740: && ! (basic_block_live_at_start[0][regno / HOST_BITS_PER_INT]
2741: & (1 << (regno % HOST_BITS_PER_INT))))
2742: reg_n_refs[regno] = 0;
2743: remove_death (regno, insn);
2744:
2745: PUT_CODE (prev2, NOTE);
2746: NOTE_LINE_NUMBER (prev2) = NOTE_INSN_DELETED;
2747: NOTE_SOURCE_FILE (prev2) = 0;
2748:
2749: distrib_successes++;
2750: return prev1;
2751: }
2752:
1.1.1.2 root 2753: void
1.1 root 2754: dump_combine_stats (file)
1.1.1.15 root 2755: FILE *file;
1.1 root 2756: {
2757: fprintf
2758: (file,
1.1.1.7 root 2759: ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n",
2760: combine_attempts, combine_merges, combine_extras, combine_successes);
2761: fprintf
2762: (file,
2763: ";; Distributer statistics: %d attempts, %d:%d substitutions,\n;; %d successes.\n\n",
2764: distrib_attempts, distrib_merges_1,
2765: distrib_merges_2, distrib_successes);
1.1 root 2766: }
2767:
1.1.1.2 root 2768: void
1.1 root 2769: dump_combine_total_stats (file)
1.1.1.15 root 2770: FILE *file;
1.1 root 2771: {
2772: fprintf
2773: (file,
2774: "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n",
2775: total_attempts, total_merges, total_extras, total_successes);
1.1.1.7 root 2776: fprintf
2777: (file,
2778: "\n;; Distributer totals: %d attempts, %d:%d substitutions,\n;; %d successes.\n",
2779: total_distrib_attempts, total_distrib_merges_1,
2780: total_distrib_merges_2, total_distrib_successes);
1.1 root 2781: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.