jump.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  1. /* Optimize jump instructions, for GNU compiler.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This is the pathetic reminder of old fame of the jump-optimization pass
  16. of the compiler. Now it contains basically a set of utility functions to
  17. operate with jumps.
  18. Each CODE_LABEL has a count of the times it is used
  19. stored in the LABEL_NUSES internal field, and each JUMP_INSN
  20. has one label that it refers to stored in the
  21. JUMP_LABEL internal field. With this we can detect labels that
  22. become unused because of the deletion of all the jumps that
  23. formerly used them. The JUMP_LABEL info is sometimes looked
  24. at by later passes. For return insns, it contains either a
  25. RETURN or a SIMPLE_RETURN rtx.
  26. The subroutines redirect_jump and invert_jump are used
  27. from other passes as well. */
  28. #include "config.h"
  29. #include "system.h"
  30. #include "coretypes.h"
  31. #include "tm.h"
  32. #include "rtl.h"
  33. #include "tm_p.h"
  34. #include "flags.h"
  35. #include "hard-reg-set.h"
  36. #include "regs.h"
  37. #include "insn-config.h"
  38. #include "insn-attr.h"
  39. #include "recog.h"
  40. #include "hashtab.h"
  41. #include "hash-set.h"
  42. #include "vec.h"
  43. #include "machmode.h"
  44. #include "input.h"
  45. #include "function.h"
  46. #include "predict.h"
  47. #include "dominance.h"
  48. #include "cfg.h"
  49. #include "cfgrtl.h"
  50. #include "basic-block.h"
  51. #include "symtab.h"
  52. #include "statistics.h"
  53. #include "double-int.h"
  54. #include "real.h"
  55. #include "fixed-value.h"
  56. #include "alias.h"
  57. #include "wide-int.h"
  58. #include "inchash.h"
  59. #include "tree.h"
  60. #include "expmed.h"
  61. #include "dojump.h"
  62. #include "explow.h"
  63. #include "calls.h"
  64. #include "emit-rtl.h"
  65. #include "varasm.h"
  66. #include "stmt.h"
  67. #include "expr.h"
  68. #include "except.h"
  69. #include "diagnostic-core.h"
  70. #include "reload.h"
  71. #include "tree-pass.h"
  72. #include "target.h"
  73. #include "rtl-iter.h"
  74. /* Optimize jump y; x: ... y: jumpif... x?
  75. Don't know if it is worth bothering with. */
  76. /* Optimize two cases of conditional jump to conditional jump?
  77. This can never delete any instruction or make anything dead,
  78. or even change what is live at any point.
  79. So perhaps let combiner do it. */
  80. static void init_label_info (rtx_insn *);
  81. static void mark_all_labels (rtx_insn *);
  82. static void mark_jump_label_1 (rtx, rtx_insn *, bool, bool);
  83. static void mark_jump_label_asm (rtx, rtx_insn *);
  84. static void redirect_exp_1 (rtx *, rtx, rtx, rtx);
  85. static int invert_exp_1 (rtx, rtx);
  86. /* Worker for rebuild_jump_labels and rebuild_jump_labels_chain. */
  87. static void
  88. rebuild_jump_labels_1 (rtx_insn *f, bool count_forced)
  89. {
  90. rtx_insn_list *insn;
  91. timevar_push (TV_REBUILD_JUMP);
  92. init_label_info (f);
  93. mark_all_labels (f);
  94. /* Keep track of labels used from static data; we don't track them
  95. closely enough to delete them here, so make sure their reference
  96. count doesn't drop to zero. */
  97. if (count_forced)
  98. for (insn = forced_labels; insn; insn = insn->next ())
  99. if (LABEL_P (insn->insn ()))
  100. LABEL_NUSES (insn->insn ())++;
  101. timevar_pop (TV_REBUILD_JUMP);
  102. }
  103. /* This function rebuilds the JUMP_LABEL field and REG_LABEL_TARGET
  104. notes in jumping insns and REG_LABEL_OPERAND notes in non-jumping
  105. instructions and jumping insns that have labels as operands
  106. (e.g. cbranchsi4). */
  107. void
  108. rebuild_jump_labels (rtx_insn *f)
  109. {
  110. rebuild_jump_labels_1 (f, true);
  111. }
  112. /* This function is like rebuild_jump_labels, but doesn't run over
  113. forced_labels. It can be used on insn chains that aren't the
  114. main function chain. */
  115. void
  116. rebuild_jump_labels_chain (rtx_insn *chain)
  117. {
  118. rebuild_jump_labels_1 (chain, false);
  119. }
  120. /* Some old code expects exactly one BARRIER as the NEXT_INSN of a
  121. non-fallthru insn. This is not generally true, as multiple barriers
  122. may have crept in, or the BARRIER may be separated from the last
  123. real insn by one or more NOTEs.
  124. This simple pass moves barriers and removes duplicates so that the
  125. old code is happy.
  126. */
  127. static unsigned int
  128. cleanup_barriers (void)
  129. {
  130. rtx_insn *insn;
  131. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  132. {
  133. if (BARRIER_P (insn))
  134. {
  135. rtx_insn *prev = prev_nonnote_insn (insn);
  136. if (!prev)
  137. continue;
  138. if (CALL_P (prev))
  139. {
  140. /* Make sure we do not split a call and its corresponding
  141. CALL_ARG_LOCATION note. */
  142. rtx_insn *next = NEXT_INSN (prev);
  143. if (NOTE_P (next)
  144. && NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION)
  145. prev = next;
  146. }
  147. if (BARRIER_P (prev))
  148. delete_insn (insn);
  149. else if (prev != PREV_INSN (insn))
  150. {
  151. basic_block bb = BLOCK_FOR_INSN (prev);
  152. rtx_insn *end = PREV_INSN (insn);
  153. reorder_insns_nobb (insn, insn, prev);
  154. if (bb)
  155. {
  156. /* If the backend called in machine reorg compute_bb_for_insn
  157. and didn't free_bb_for_insn again, preserve basic block
  158. boundaries. Move the end of basic block to PREV since
  159. it is followed by a barrier now, and clear BLOCK_FOR_INSN
  160. on the following notes.
  161. ??? Maybe the proper solution for the targets that have
  162. cfg around after machine reorg is not to run cleanup_barriers
  163. pass at all. */
  164. BB_END (bb) = prev;
  165. do
  166. {
  167. prev = NEXT_INSN (prev);
  168. if (prev != insn && BLOCK_FOR_INSN (prev) == bb)
  169. BLOCK_FOR_INSN (prev) = NULL;
  170. }
  171. while (prev != end);
  172. }
  173. }
  174. }
  175. }
  176. return 0;
  177. }
  178. namespace {
  179. const pass_data pass_data_cleanup_barriers =
  180. {
  181. RTL_PASS, /* type */
  182. "barriers", /* name */
  183. OPTGROUP_NONE, /* optinfo_flags */
  184. TV_NONE, /* tv_id */
  185. 0, /* properties_required */
  186. 0, /* properties_provided */
  187. 0, /* properties_destroyed */
  188. 0, /* todo_flags_start */
  189. 0, /* todo_flags_finish */
  190. };
  191. class pass_cleanup_barriers : public rtl_opt_pass
  192. {
  193. public:
  194. pass_cleanup_barriers (gcc::context *ctxt)
  195. : rtl_opt_pass (pass_data_cleanup_barriers, ctxt)
  196. {}
  197. /* opt_pass methods: */
  198. virtual unsigned int execute (function *) { return cleanup_barriers (); }
  199. }; // class pass_cleanup_barriers
  200. } // anon namespace
  201. rtl_opt_pass *
  202. make_pass_cleanup_barriers (gcc::context *ctxt)
  203. {
  204. return new pass_cleanup_barriers (ctxt);
  205. }
  206. /* Initialize LABEL_NUSES and JUMP_LABEL fields, add REG_LABEL_TARGET
  207. for remaining targets for JUMP_P. Delete any REG_LABEL_OPERAND
  208. notes whose labels don't occur in the insn any more. */
  209. static void
  210. init_label_info (rtx_insn *f)
  211. {
  212. rtx_insn *insn;
  213. for (insn = f; insn; insn = NEXT_INSN (insn))
  214. {
  215. if (LABEL_P (insn))
  216. LABEL_NUSES (insn) = (LABEL_PRESERVE_P (insn) != 0);
  217. /* REG_LABEL_TARGET notes (including the JUMP_LABEL field) are
  218. sticky and not reset here; that way we won't lose association
  219. with a label when e.g. the source for a target register
  220. disappears out of reach for targets that may use jump-target
  221. registers. Jump transformations are supposed to transform
  222. any REG_LABEL_TARGET notes. The target label reference in a
  223. branch may disappear from the branch (and from the
  224. instruction before it) for other reasons, like register
  225. allocation. */
  226. if (INSN_P (insn))
  227. {
  228. rtx note, next;
  229. for (note = REG_NOTES (insn); note; note = next)
  230. {
  231. next = XEXP (note, 1);
  232. if (REG_NOTE_KIND (note) == REG_LABEL_OPERAND
  233. && ! reg_mentioned_p (XEXP (note, 0), PATTERN (insn)))
  234. remove_note (insn, note);
  235. }
  236. }
  237. }
  238. }
  239. /* A subroutine of mark_all_labels. Trivially propagate a simple label
  240. load into a jump_insn that uses it. */
  241. static void
  242. maybe_propagate_label_ref (rtx_insn *jump_insn, rtx_insn *prev_nonjump_insn)
  243. {
  244. rtx label_note, pc, pc_src;
  245. pc = pc_set (jump_insn);
  246. pc_src = pc != NULL ? SET_SRC (pc) : NULL;
  247. label_note = find_reg_note (prev_nonjump_insn, REG_LABEL_OPERAND, NULL);
  248. /* If the previous non-jump insn sets something to a label,
  249. something that this jump insn uses, make that label the primary
  250. target of this insn if we don't yet have any. That previous
  251. insn must be a single_set and not refer to more than one label.
  252. The jump insn must not refer to other labels as jump targets
  253. and must be a plain (set (pc) ...), maybe in a parallel, and
  254. may refer to the item being set only directly or as one of the
  255. arms in an IF_THEN_ELSE. */
  256. if (label_note != NULL && pc_src != NULL)
  257. {
  258. rtx label_set = single_set (prev_nonjump_insn);
  259. rtx label_dest = label_set != NULL ? SET_DEST (label_set) : NULL;
  260. if (label_set != NULL
  261. /* The source must be the direct LABEL_REF, not a
  262. PLUS, UNSPEC, IF_THEN_ELSE etc. */
  263. && GET_CODE (SET_SRC (label_set)) == LABEL_REF
  264. && (rtx_equal_p (label_dest, pc_src)
  265. || (GET_CODE (pc_src) == IF_THEN_ELSE
  266. && (rtx_equal_p (label_dest, XEXP (pc_src, 1))
  267. || rtx_equal_p (label_dest, XEXP (pc_src, 2))))))
  268. {
  269. /* The CODE_LABEL referred to in the note must be the
  270. CODE_LABEL in the LABEL_REF of the "set". We can
  271. conveniently use it for the marker function, which
  272. requires a LABEL_REF wrapping. */
  273. gcc_assert (XEXP (label_note, 0) == LABEL_REF_LABEL (SET_SRC (label_set)));
  274. mark_jump_label_1 (label_set, jump_insn, false, true);
  275. gcc_assert (JUMP_LABEL (jump_insn) == XEXP (label_note, 0));
  276. }
  277. }
  278. }
  279. /* Mark the label each jump jumps to.
  280. Combine consecutive labels, and count uses of labels. */
  281. static void
  282. mark_all_labels (rtx_insn *f)
  283. {
  284. rtx_insn *insn;
  285. if (current_ir_type () == IR_RTL_CFGLAYOUT)
  286. {
  287. basic_block bb;
  288. FOR_EACH_BB_FN (bb, cfun)
  289. {
  290. /* In cfglayout mode, we don't bother with trivial next-insn
  291. propagation of LABEL_REFs into JUMP_LABEL. This will be
  292. handled by other optimizers using better algorithms. */
  293. FOR_BB_INSNS (bb, insn)
  294. {
  295. gcc_assert (! insn->deleted ());
  296. if (NONDEBUG_INSN_P (insn))
  297. mark_jump_label (PATTERN (insn), insn, 0);
  298. }
  299. /* In cfglayout mode, there may be non-insns between the
  300. basic blocks. If those non-insns represent tablejump data,
  301. they contain label references that we must record. */
  302. for (insn = BB_HEADER (bb); insn; insn = NEXT_INSN (insn))
  303. if (JUMP_TABLE_DATA_P (insn))
  304. mark_jump_label (PATTERN (insn), insn, 0);
  305. for (insn = BB_FOOTER (bb); insn; insn = NEXT_INSN (insn))
  306. if (JUMP_TABLE_DATA_P (insn))
  307. mark_jump_label (PATTERN (insn), insn, 0);
  308. }
  309. }
  310. else
  311. {
  312. rtx_insn *prev_nonjump_insn = NULL;
  313. for (insn = f; insn; insn = NEXT_INSN (insn))
  314. {
  315. if (insn->deleted ())
  316. ;
  317. else if (LABEL_P (insn))
  318. prev_nonjump_insn = NULL;
  319. else if (JUMP_TABLE_DATA_P (insn))
  320. mark_jump_label (PATTERN (insn), insn, 0);
  321. else if (NONDEBUG_INSN_P (insn))
  322. {
  323. mark_jump_label (PATTERN (insn), insn, 0);
  324. if (JUMP_P (insn))
  325. {
  326. if (JUMP_LABEL (insn) == NULL && prev_nonjump_insn != NULL)
  327. maybe_propagate_label_ref (insn, prev_nonjump_insn);
  328. }
  329. else
  330. prev_nonjump_insn = insn;
  331. }
  332. }
  333. }
  334. }
  335. /* Given a comparison (CODE ARG0 ARG1), inside an insn, INSN, return a code
  336. of reversed comparison if it is possible to do so. Otherwise return UNKNOWN.
  337. UNKNOWN may be returned in case we are having CC_MODE compare and we don't
  338. know whether it's source is floating point or integer comparison. Machine
  339. description should define REVERSIBLE_CC_MODE and REVERSE_CONDITION macros
  340. to help this function avoid overhead in these cases. */
  341. enum rtx_code
  342. reversed_comparison_code_parts (enum rtx_code code, const_rtx arg0,
  343. const_rtx arg1, const_rtx insn)
  344. {
  345. machine_mode mode;
  346. /* If this is not actually a comparison, we can't reverse it. */
  347. if (GET_RTX_CLASS (code) != RTX_COMPARE
  348. && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
  349. return UNKNOWN;
  350. mode = GET_MODE (arg0);
  351. if (mode == VOIDmode)
  352. mode = GET_MODE (arg1);
  353. /* First see if machine description supplies us way to reverse the
  354. comparison. Give it priority over everything else to allow
  355. machine description to do tricks. */
  356. if (GET_MODE_CLASS (mode) == MODE_CC
  357. && REVERSIBLE_CC_MODE (mode))
  358. {
  359. #ifdef REVERSE_CONDITION
  360. return REVERSE_CONDITION (code, mode);
  361. #else
  362. return reverse_condition (code);
  363. #endif
  364. }
  365. /* Try a few special cases based on the comparison code. */
  366. switch (code)
  367. {
  368. case GEU:
  369. case GTU:
  370. case LEU:
  371. case LTU:
  372. case NE:
  373. case EQ:
  374. /* It is always safe to reverse EQ and NE, even for the floating
  375. point. Similarly the unsigned comparisons are never used for
  376. floating point so we can reverse them in the default way. */
  377. return reverse_condition (code);
  378. case ORDERED:
  379. case UNORDERED:
  380. case LTGT:
  381. case UNEQ:
  382. /* In case we already see unordered comparison, we can be sure to
  383. be dealing with floating point so we don't need any more tests. */
  384. return reverse_condition_maybe_unordered (code);
  385. case UNLT:
  386. case UNLE:
  387. case UNGT:
  388. case UNGE:
  389. /* We don't have safe way to reverse these yet. */
  390. return UNKNOWN;
  391. default:
  392. break;
  393. }
  394. if (GET_MODE_CLASS (mode) == MODE_CC || CC0_P (arg0))
  395. {
  396. const_rtx prev;
  397. /* Try to search for the comparison to determine the real mode.
  398. This code is expensive, but with sane machine description it
  399. will be never used, since REVERSIBLE_CC_MODE will return true
  400. in all cases. */
  401. if (! insn)
  402. return UNKNOWN;
  403. /* These CONST_CAST's are okay because prev_nonnote_insn just
  404. returns its argument and we assign it to a const_rtx
  405. variable. */
  406. for (prev = prev_nonnote_insn (CONST_CAST_RTX (insn));
  407. prev != 0 && !LABEL_P (prev);
  408. prev = prev_nonnote_insn (CONST_CAST_RTX (prev)))
  409. {
  410. const_rtx set = set_of (arg0, prev);
  411. if (set && GET_CODE (set) == SET
  412. && rtx_equal_p (SET_DEST (set), arg0))
  413. {
  414. rtx src = SET_SRC (set);
  415. if (GET_CODE (src) == COMPARE)
  416. {
  417. rtx comparison = src;
  418. arg0 = XEXP (src, 0);
  419. mode = GET_MODE (arg0);
  420. if (mode == VOIDmode)
  421. mode = GET_MODE (XEXP (comparison, 1));
  422. break;
  423. }
  424. /* We can get past reg-reg moves. This may be useful for model
  425. of i387 comparisons that first move flag registers around. */
  426. if (REG_P (src))
  427. {
  428. arg0 = src;
  429. continue;
  430. }
  431. }
  432. /* If register is clobbered in some ununderstandable way,
  433. give up. */
  434. if (set)
  435. return UNKNOWN;
  436. }
  437. }
  438. /* Test for an integer condition, or a floating-point comparison
  439. in which NaNs can be ignored. */
  440. if (CONST_INT_P (arg0)
  441. || (GET_MODE (arg0) != VOIDmode
  442. && GET_MODE_CLASS (mode) != MODE_CC
  443. && !HONOR_NANS (mode)))
  444. return reverse_condition (code);
  445. return UNKNOWN;
  446. }
  447. /* A wrapper around the previous function to take COMPARISON as rtx
  448. expression. This simplifies many callers. */
  449. enum rtx_code
  450. reversed_comparison_code (const_rtx comparison, const_rtx insn)
  451. {
  452. if (!COMPARISON_P (comparison))
  453. return UNKNOWN;
  454. return reversed_comparison_code_parts (GET_CODE (comparison),
  455. XEXP (comparison, 0),
  456. XEXP (comparison, 1), insn);
  457. }
  458. /* Return comparison with reversed code of EXP.
  459. Return NULL_RTX in case we fail to do the reversal. */
  460. rtx
  461. reversed_comparison (const_rtx exp, machine_mode mode)
  462. {
  463. enum rtx_code reversed_code = reversed_comparison_code (exp, NULL_RTX);
  464. if (reversed_code == UNKNOWN)
  465. return NULL_RTX;
  466. else
  467. return simplify_gen_relational (reversed_code, mode, VOIDmode,
  468. XEXP (exp, 0), XEXP (exp, 1));
  469. }
  470. /* Given an rtx-code for a comparison, return the code for the negated
  471. comparison. If no such code exists, return UNKNOWN.
  472. WATCH OUT! reverse_condition is not safe to use on a jump that might
  473. be acting on the results of an IEEE floating point comparison, because
  474. of the special treatment of non-signaling nans in comparisons.
  475. Use reversed_comparison_code instead. */
  476. enum rtx_code
  477. reverse_condition (enum rtx_code code)
  478. {
  479. switch (code)
  480. {
  481. case EQ:
  482. return NE;
  483. case NE:
  484. return EQ;
  485. case GT:
  486. return LE;
  487. case GE:
  488. return LT;
  489. case LT:
  490. return GE;
  491. case LE:
  492. return GT;
  493. case GTU:
  494. return LEU;
  495. case GEU:
  496. return LTU;
  497. case LTU:
  498. return GEU;
  499. case LEU:
  500. return GTU;
  501. case UNORDERED:
  502. return ORDERED;
  503. case ORDERED:
  504. return UNORDERED;
  505. case UNLT:
  506. case UNLE:
  507. case UNGT:
  508. case UNGE:
  509. case UNEQ:
  510. case LTGT:
  511. return UNKNOWN;
  512. default:
  513. gcc_unreachable ();
  514. }
  515. }
  516. /* Similar, but we're allowed to generate unordered comparisons, which
  517. makes it safe for IEEE floating-point. Of course, we have to recognize
  518. that the target will support them too... */
  519. enum rtx_code
  520. reverse_condition_maybe_unordered (enum rtx_code code)
  521. {
  522. switch (code)
  523. {
  524. case EQ:
  525. return NE;
  526. case NE:
  527. return EQ;
  528. case GT:
  529. return UNLE;
  530. case GE:
  531. return UNLT;
  532. case LT:
  533. return UNGE;
  534. case LE:
  535. return UNGT;
  536. case LTGT:
  537. return UNEQ;
  538. case UNORDERED:
  539. return ORDERED;
  540. case ORDERED:
  541. return UNORDERED;
  542. case UNLT:
  543. return GE;
  544. case UNLE:
  545. return GT;
  546. case UNGT:
  547. return LE;
  548. case UNGE:
  549. return LT;
  550. case UNEQ:
  551. return LTGT;
  552. default:
  553. gcc_unreachable ();
  554. }
  555. }
  556. /* Similar, but return the code when two operands of a comparison are swapped.
  557. This IS safe for IEEE floating-point. */
  558. enum rtx_code
  559. swap_condition (enum rtx_code code)
  560. {
  561. switch (code)
  562. {
  563. case EQ:
  564. case NE:
  565. case UNORDERED:
  566. case ORDERED:
  567. case UNEQ:
  568. case LTGT:
  569. return code;
  570. case GT:
  571. return LT;
  572. case GE:
  573. return LE;
  574. case LT:
  575. return GT;
  576. case LE:
  577. return GE;
  578. case GTU:
  579. return LTU;
  580. case GEU:
  581. return LEU;
  582. case LTU:
  583. return GTU;
  584. case LEU:
  585. return GEU;
  586. case UNLT:
  587. return UNGT;
  588. case UNLE:
  589. return UNGE;
  590. case UNGT:
  591. return UNLT;
  592. case UNGE:
  593. return UNLE;
  594. default:
  595. gcc_unreachable ();
  596. }
  597. }
  598. /* Given a comparison CODE, return the corresponding unsigned comparison.
  599. If CODE is an equality comparison or already an unsigned comparison,
  600. CODE is returned. */
  601. enum rtx_code
  602. unsigned_condition (enum rtx_code code)
  603. {
  604. switch (code)
  605. {
  606. case EQ:
  607. case NE:
  608. case GTU:
  609. case GEU:
  610. case LTU:
  611. case LEU:
  612. return code;
  613. case GT:
  614. return GTU;
  615. case GE:
  616. return GEU;
  617. case LT:
  618. return LTU;
  619. case LE:
  620. return LEU;
  621. default:
  622. gcc_unreachable ();
  623. }
  624. }
  625. /* Similarly, return the signed version of a comparison. */
  626. enum rtx_code
  627. signed_condition (enum rtx_code code)
  628. {
  629. switch (code)
  630. {
  631. case EQ:
  632. case NE:
  633. case GT:
  634. case GE:
  635. case LT:
  636. case LE:
  637. return code;
  638. case GTU:
  639. return GT;
  640. case GEU:
  641. return GE;
  642. case LTU:
  643. return LT;
  644. case LEU:
  645. return LE;
  646. default:
  647. gcc_unreachable ();
  648. }
  649. }
  650. /* Return nonzero if CODE1 is more strict than CODE2, i.e., if the
  651. truth of CODE1 implies the truth of CODE2. */
  652. int
  653. comparison_dominates_p (enum rtx_code code1, enum rtx_code code2)
  654. {
  655. /* UNKNOWN comparison codes can happen as a result of trying to revert
  656. comparison codes.
  657. They can't match anything, so we have to reject them here. */
  658. if (code1 == UNKNOWN || code2 == UNKNOWN)
  659. return 0;
  660. if (code1 == code2)
  661. return 1;
  662. switch (code1)
  663. {
  664. case UNEQ:
  665. if (code2 == UNLE || code2 == UNGE)
  666. return 1;
  667. break;
  668. case EQ:
  669. if (code2 == LE || code2 == LEU || code2 == GE || code2 == GEU
  670. || code2 == ORDERED)
  671. return 1;
  672. break;
  673. case UNLT:
  674. if (code2 == UNLE || code2 == NE)
  675. return 1;
  676. break;
  677. case LT:
  678. if (code2 == LE || code2 == NE || code2 == ORDERED || code2 == LTGT)
  679. return 1;
  680. break;
  681. case UNGT:
  682. if (code2 == UNGE || code2 == NE)
  683. return 1;
  684. break;
  685. case GT:
  686. if (code2 == GE || code2 == NE || code2 == ORDERED || code2 == LTGT)
  687. return 1;
  688. break;
  689. case GE:
  690. case LE:
  691. if (code2 == ORDERED)
  692. return 1;
  693. break;
  694. case LTGT:
  695. if (code2 == NE || code2 == ORDERED)
  696. return 1;
  697. break;
  698. case LTU:
  699. if (code2 == LEU || code2 == NE)
  700. return 1;
  701. break;
  702. case GTU:
  703. if (code2 == GEU || code2 == NE)
  704. return 1;
  705. break;
  706. case UNORDERED:
  707. if (code2 == NE || code2 == UNEQ || code2 == UNLE || code2 == UNLT
  708. || code2 == UNGE || code2 == UNGT)
  709. return 1;
  710. break;
  711. default:
  712. break;
  713. }
  714. return 0;
  715. }
  716. /* Return 1 if INSN is an unconditional jump and nothing else. */
  717. int
  718. simplejump_p (const rtx_insn *insn)
  719. {
  720. return (JUMP_P (insn)
  721. && GET_CODE (PATTERN (insn)) == SET
  722. && GET_CODE (SET_DEST (PATTERN (insn))) == PC
  723. && GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF);
  724. }
  725. /* Return nonzero if INSN is a (possibly) conditional jump
  726. and nothing more.
  727. Use of this function is deprecated, since we need to support combined
  728. branch and compare insns. Use any_condjump_p instead whenever possible. */
  729. int
  730. condjump_p (const rtx_insn *insn)
  731. {
  732. const_rtx x = PATTERN (insn);
  733. if (GET_CODE (x) != SET
  734. || GET_CODE (SET_DEST (x)) != PC)
  735. return 0;
  736. x = SET_SRC (x);
  737. if (GET_CODE (x) == LABEL_REF)
  738. return 1;
  739. else
  740. return (GET_CODE (x) == IF_THEN_ELSE
  741. && ((GET_CODE (XEXP (x, 2)) == PC
  742. && (GET_CODE (XEXP (x, 1)) == LABEL_REF
  743. || ANY_RETURN_P (XEXP (x, 1))))
  744. || (GET_CODE (XEXP (x, 1)) == PC
  745. && (GET_CODE (XEXP (x, 2)) == LABEL_REF
  746. || ANY_RETURN_P (XEXP (x, 2))))));
  747. }
  748. /* Return nonzero if INSN is a (possibly) conditional jump inside a
  749. PARALLEL.
  750. Use this function is deprecated, since we need to support combined
  751. branch and compare insns. Use any_condjump_p instead whenever possible. */
  752. int
  753. condjump_in_parallel_p (const rtx_insn *insn)
  754. {
  755. const_rtx x = PATTERN (insn);
  756. if (GET_CODE (x) != PARALLEL)
  757. return 0;
  758. else
  759. x = XVECEXP (x, 0, 0);
  760. if (GET_CODE (x) != SET)
  761. return 0;
  762. if (GET_CODE (SET_DEST (x)) != PC)
  763. return 0;
  764. if (GET_CODE (SET_SRC (x)) == LABEL_REF)
  765. return 1;
  766. if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
  767. return 0;
  768. if (XEXP (SET_SRC (x), 2) == pc_rtx
  769. && (GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF
  770. || ANY_RETURN_P (XEXP (SET_SRC (x), 1))))
  771. return 1;
  772. if (XEXP (SET_SRC (x), 1) == pc_rtx
  773. && (GET_CODE (XEXP (SET_SRC (x), 2)) == LABEL_REF
  774. || ANY_RETURN_P (XEXP (SET_SRC (x), 2))))
  775. return 1;
  776. return 0;
  777. }
  778. /* Return set of PC, otherwise NULL. */
  779. rtx
  780. pc_set (const rtx_insn *insn)
  781. {
  782. rtx pat;
  783. if (!JUMP_P (insn))
  784. return NULL_RTX;
  785. pat = PATTERN (insn);
  786. /* The set is allowed to appear either as the insn pattern or
  787. the first set in a PARALLEL. */
  788. if (GET_CODE (pat) == PARALLEL)
  789. pat = XVECEXP (pat, 0, 0);
  790. if (GET_CODE (pat) == SET && GET_CODE (SET_DEST (pat)) == PC)
  791. return pat;
  792. return NULL_RTX;
  793. }
  794. /* Return true when insn is an unconditional direct jump,
  795. possibly bundled inside a PARALLEL. */
  796. int
  797. any_uncondjump_p (const rtx_insn *insn)
  798. {
  799. const_rtx x = pc_set (insn);
  800. if (!x)
  801. return 0;
  802. if (GET_CODE (SET_SRC (x)) != LABEL_REF)
  803. return 0;
  804. if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
  805. return 0;
  806. return 1;
  807. }
  808. /* Return true when insn is a conditional jump. This function works for
  809. instructions containing PC sets in PARALLELs. The instruction may have
  810. various other effects so before removing the jump you must verify
  811. onlyjump_p.
  812. Note that unlike condjump_p it returns false for unconditional jumps. */
  813. int
  814. any_condjump_p (const rtx_insn *insn)
  815. {
  816. const_rtx x = pc_set (insn);
  817. enum rtx_code a, b;
  818. if (!x)
  819. return 0;
  820. if (GET_CODE (SET_SRC (x)) != IF_THEN_ELSE)
  821. return 0;
  822. a = GET_CODE (XEXP (SET_SRC (x), 1));
  823. b = GET_CODE (XEXP (SET_SRC (x), 2));
  824. return ((b == PC && (a == LABEL_REF || a == RETURN || a == SIMPLE_RETURN))
  825. || (a == PC
  826. && (b == LABEL_REF || b == RETURN || b == SIMPLE_RETURN)));
  827. }
  828. /* Return the label of a conditional jump. */
  829. rtx
  830. condjump_label (const rtx_insn *insn)
  831. {
  832. rtx x = pc_set (insn);
  833. if (!x)
  834. return NULL_RTX;
  835. x = SET_SRC (x);
  836. if (GET_CODE (x) == LABEL_REF)
  837. return x;
  838. if (GET_CODE (x) != IF_THEN_ELSE)
  839. return NULL_RTX;
  840. if (XEXP (x, 2) == pc_rtx && GET_CODE (XEXP (x, 1)) == LABEL_REF)
  841. return XEXP (x, 1);
  842. if (XEXP (x, 1) == pc_rtx && GET_CODE (XEXP (x, 2)) == LABEL_REF)
  843. return XEXP (x, 2);
  844. return NULL_RTX;
  845. }
  846. /* Return TRUE if INSN is a return jump. */
  847. int
  848. returnjump_p (const rtx_insn *insn)
  849. {
  850. if (JUMP_P (insn))
  851. {
  852. subrtx_iterator::array_type array;
  853. FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
  854. {
  855. const_rtx x = *iter;
  856. switch (GET_CODE (x))
  857. {
  858. case RETURN:
  859. case SIMPLE_RETURN:
  860. case EH_RETURN:
  861. return true;
  862. case SET:
  863. if (SET_IS_RETURN_P (x))
  864. return true;
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. }
  871. return false;
  872. }
  873. /* Return true if INSN is a (possibly conditional) return insn. */
  874. int
  875. eh_returnjump_p (rtx_insn *insn)
  876. {
  877. if (JUMP_P (insn))
  878. {
  879. subrtx_iterator::array_type array;
  880. FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
  881. if (GET_CODE (*iter) == EH_RETURN)
  882. return true;
  883. }
  884. return false;
  885. }
  886. /* Return true if INSN is a jump that only transfers control and
  887. nothing more. */
  888. int
  889. onlyjump_p (const rtx_insn *insn)
  890. {
  891. rtx set;
  892. if (!JUMP_P (insn))
  893. return 0;
  894. set = single_set (insn);
  895. if (set == NULL)
  896. return 0;
  897. if (GET_CODE (SET_DEST (set)) != PC)
  898. return 0;
  899. if (side_effects_p (SET_SRC (set)))
  900. return 0;
  901. return 1;
  902. }
  903. /* Return true iff INSN is a jump and its JUMP_LABEL is a label, not
  904. NULL or a return. */
  905. bool
  906. jump_to_label_p (const rtx_insn *insn)
  907. {
  908. return (JUMP_P (insn)
  909. && JUMP_LABEL (insn) != NULL && !ANY_RETURN_P (JUMP_LABEL (insn)));
  910. }
  911. #ifdef HAVE_cc0
  912. /* Return nonzero if X is an RTX that only sets the condition codes
  913. and has no side effects. */
  914. int
  915. only_sets_cc0_p (const_rtx x)
  916. {
  917. if (! x)
  918. return 0;
  919. if (INSN_P (x))
  920. x = PATTERN (x);
  921. return sets_cc0_p (x) == 1 && ! side_effects_p (x);
  922. }
  923. /* Return 1 if X is an RTX that does nothing but set the condition codes
  924. and CLOBBER or USE registers.
  925. Return -1 if X does explicitly set the condition codes,
  926. but also does other things. */
  927. int
  928. sets_cc0_p (const_rtx x)
  929. {
  930. if (! x)
  931. return 0;
  932. if (INSN_P (x))
  933. x = PATTERN (x);
  934. if (GET_CODE (x) == SET && SET_DEST (x) == cc0_rtx)
  935. return 1;
  936. if (GET_CODE (x) == PARALLEL)
  937. {
  938. int i;
  939. int sets_cc0 = 0;
  940. int other_things = 0;
  941. for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  942. {
  943. if (GET_CODE (XVECEXP (x, 0, i)) == SET
  944. && SET_DEST (XVECEXP (x, 0, i)) == cc0_rtx)
  945. sets_cc0 = 1;
  946. else if (GET_CODE (XVECEXP (x, 0, i)) == SET)
  947. other_things = 1;
  948. }
  949. return ! sets_cc0 ? 0 : other_things ? -1 : 1;
  950. }
  951. return 0;
  952. }
  953. #endif
  954. /* Find all CODE_LABELs referred to in X, and increment their use
  955. counts. If INSN is a JUMP_INSN and there is at least one
  956. CODE_LABEL referenced in INSN as a jump target, then store the last
  957. one in JUMP_LABEL (INSN). For a tablejump, this must be the label
  958. for the ADDR_VEC. Store any other jump targets as REG_LABEL_TARGET
  959. notes. If INSN is an INSN or a CALL_INSN or non-target operands of
  960. a JUMP_INSN, and there is at least one CODE_LABEL referenced in
  961. INSN, add a REG_LABEL_OPERAND note containing that label to INSN.
  962. For returnjumps, the JUMP_LABEL will also be set as appropriate.
  963. Note that two labels separated by a loop-beginning note
  964. must be kept distinct if we have not yet done loop-optimization,
  965. because the gap between them is where loop-optimize
  966. will want to move invariant code to. CROSS_JUMP tells us
  967. that loop-optimization is done with. */
  968. void
  969. mark_jump_label (rtx x, rtx_insn *insn, int in_mem)
  970. {
  971. rtx asmop = extract_asm_operands (x);
  972. if (asmop)
  973. mark_jump_label_asm (asmop, insn);
  974. else
  975. mark_jump_label_1 (x, insn, in_mem != 0,
  976. (insn != NULL && x == PATTERN (insn) && JUMP_P (insn)));
  977. }
  978. /* Worker function for mark_jump_label. IN_MEM is TRUE when X occurs
  979. within a (MEM ...). IS_TARGET is TRUE when X is to be treated as a
  980. jump-target; when the JUMP_LABEL field of INSN should be set or a
  981. REG_LABEL_TARGET note should be added, not a REG_LABEL_OPERAND
  982. note. */
  983. static void
  984. mark_jump_label_1 (rtx x, rtx_insn *insn, bool in_mem, bool is_target)
  985. {
  986. RTX_CODE code = GET_CODE (x);
  987. int i;
  988. const char *fmt;
  989. switch (code)
  990. {
  991. case PC:
  992. case CC0:
  993. case REG:
  994. case CLOBBER:
  995. case CALL:
  996. return;
  997. case RETURN:
  998. case SIMPLE_RETURN:
  999. if (is_target)
  1000. {
  1001. gcc_assert (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == x);
  1002. JUMP_LABEL (insn) = x;
  1003. }
  1004. return;
  1005. case MEM:
  1006. in_mem = true;
  1007. break;
  1008. case SEQUENCE:
  1009. {
  1010. rtx_sequence *seq = as_a <rtx_sequence *> (x);
  1011. for (i = 0; i < seq->len (); i++)
  1012. mark_jump_label (PATTERN (seq->insn (i)),
  1013. seq->insn (i), 0);
  1014. }
  1015. return;
  1016. case SYMBOL_REF:
  1017. if (!in_mem)
  1018. return;
  1019. /* If this is a constant-pool reference, see if it is a label. */
  1020. if (CONSTANT_POOL_ADDRESS_P (x))
  1021. mark_jump_label_1 (get_pool_constant (x), insn, in_mem, is_target);
  1022. break;
  1023. /* Handle operands in the condition of an if-then-else as for a
  1024. non-jump insn. */
  1025. case IF_THEN_ELSE:
  1026. if (!is_target)
  1027. break;
  1028. mark_jump_label_1 (XEXP (x, 0), insn, in_mem, false);
  1029. mark_jump_label_1 (XEXP (x, 1), insn, in_mem, true);
  1030. mark_jump_label_1 (XEXP (x, 2), insn, in_mem, true);
  1031. return;
  1032. case LABEL_REF:
  1033. {
  1034. rtx label = LABEL_REF_LABEL (x);
  1035. /* Ignore remaining references to unreachable labels that
  1036. have been deleted. */
  1037. if (NOTE_P (label)
  1038. && NOTE_KIND (label) == NOTE_INSN_DELETED_LABEL)
  1039. break;
  1040. gcc_assert (LABEL_P (label));
  1041. /* Ignore references to labels of containing functions. */
  1042. if (LABEL_REF_NONLOCAL_P (x))
  1043. break;
  1044. LABEL_REF_LABEL (x) = label;
  1045. if (! insn || ! insn->deleted ())
  1046. ++LABEL_NUSES (label);
  1047. if (insn)
  1048. {
  1049. if (is_target
  1050. /* Do not change a previous setting of JUMP_LABEL. If the
  1051. JUMP_LABEL slot is occupied by a different label,
  1052. create a note for this label. */
  1053. && (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == label))
  1054. JUMP_LABEL (insn) = label;
  1055. else
  1056. {
  1057. enum reg_note kind
  1058. = is_target ? REG_LABEL_TARGET : REG_LABEL_OPERAND;
  1059. /* Add a REG_LABEL_OPERAND or REG_LABEL_TARGET note
  1060. for LABEL unless there already is one. All uses of
  1061. a label, except for the primary target of a jump,
  1062. must have such a note. */
  1063. if (! find_reg_note (insn, kind, label))
  1064. add_reg_note (insn, kind, label);
  1065. }
  1066. }
  1067. return;
  1068. }
  1069. /* Do walk the labels in a vector, but not the first operand of an
  1070. ADDR_DIFF_VEC. Don't set the JUMP_LABEL of a vector. */
  1071. case ADDR_VEC:
  1072. case ADDR_DIFF_VEC:
  1073. if (! insn->deleted ())
  1074. {
  1075. int eltnum = code == ADDR_DIFF_VEC ? 1 : 0;
  1076. for (i = 0; i < XVECLEN (x, eltnum); i++)
  1077. mark_jump_label_1 (XVECEXP (x, eltnum, i), NULL, in_mem,
  1078. is_target);
  1079. }
  1080. return;
  1081. default:
  1082. break;
  1083. }
  1084. fmt = GET_RTX_FORMAT (code);
  1085. /* The primary target of a tablejump is the label of the ADDR_VEC,
  1086. which is canonically mentioned *last* in the insn. To get it
  1087. marked as JUMP_LABEL, we iterate over items in reverse order. */
  1088. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1089. {
  1090. if (fmt[i] == 'e')
  1091. mark_jump_label_1 (XEXP (x, i), insn, in_mem, is_target);
  1092. else if (fmt[i] == 'E')
  1093. {
  1094. int j;
  1095. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1096. mark_jump_label_1 (XVECEXP (x, i, j), insn, in_mem,
  1097. is_target);
  1098. }
  1099. }
  1100. }
  1101. /* Worker function for mark_jump_label. Handle asm insns specially.
  1102. In particular, output operands need not be considered so we can
  1103. avoid re-scanning the replicated asm_operand. Also, the asm_labels
  1104. need to be considered targets. */
  1105. static void
  1106. mark_jump_label_asm (rtx asmop, rtx_insn *insn)
  1107. {
  1108. int i;
  1109. for (i = ASM_OPERANDS_INPUT_LENGTH (asmop) - 1; i >= 0; --i)
  1110. mark_jump_label_1 (ASM_OPERANDS_INPUT (asmop, i), insn, false, false);
  1111. for (i = ASM_OPERANDS_LABEL_LENGTH (asmop) - 1; i >= 0; --i)
  1112. mark_jump_label_1 (ASM_OPERANDS_LABEL (asmop, i), insn, false, true);
  1113. }
  1114. /* Delete insn INSN from the chain of insns and update label ref counts
  1115. and delete insns now unreachable.
  1116. Returns the first insn after INSN that was not deleted.
  1117. Usage of this instruction is deprecated. Use delete_insn instead and
  1118. subsequent cfg_cleanup pass to delete unreachable code if needed. */
  1119. rtx_insn *
  1120. delete_related_insns (rtx uncast_insn)
  1121. {
  1122. rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
  1123. int was_code_label = (LABEL_P (insn));
  1124. rtx note;
  1125. rtx_insn *next = NEXT_INSN (insn), *prev = PREV_INSN (insn);
  1126. while (next && next->deleted ())
  1127. next = NEXT_INSN (next);
  1128. /* This insn is already deleted => return first following nondeleted. */
  1129. if (insn->deleted ())
  1130. return next;
  1131. delete_insn (insn);
  1132. /* If instruction is followed by a barrier,
  1133. delete the barrier too. */
  1134. if (next != 0 && BARRIER_P (next))
  1135. delete_insn (next);
  1136. /* If this is a call, then we have to remove the var tracking note
  1137. for the call arguments. */
  1138. if (CALL_P (insn)
  1139. || (NONJUMP_INSN_P (insn)
  1140. && GET_CODE (PATTERN (insn)) == SEQUENCE
  1141. && CALL_P (XVECEXP (PATTERN (insn), 0, 0))))
  1142. {
  1143. rtx_insn *p;
  1144. for (p = next && next->deleted () ? NEXT_INSN (next) : next;
  1145. p && NOTE_P (p);
  1146. p = NEXT_INSN (p))
  1147. if (NOTE_KIND (p) == NOTE_INSN_CALL_ARG_LOCATION)
  1148. {
  1149. remove_insn (p);
  1150. break;
  1151. }
  1152. }
  1153. /* If deleting a jump, decrement the count of the label,
  1154. and delete the label if it is now unused. */
  1155. if (jump_to_label_p (insn))
  1156. {
  1157. rtx lab = JUMP_LABEL (insn);
  1158. rtx_jump_table_data *lab_next;
  1159. if (LABEL_NUSES (lab) == 0)
  1160. /* This can delete NEXT or PREV,
  1161. either directly if NEXT is JUMP_LABEL (INSN),
  1162. or indirectly through more levels of jumps. */
  1163. delete_related_insns (lab);
  1164. else if (tablejump_p (insn, NULL, &lab_next))
  1165. {
  1166. /* If we're deleting the tablejump, delete the dispatch table.
  1167. We may not be able to kill the label immediately preceding
  1168. just yet, as it might be referenced in code leading up to
  1169. the tablejump. */
  1170. delete_related_insns (lab_next);
  1171. }
  1172. }
  1173. /* Likewise if we're deleting a dispatch table. */
  1174. if (rtx_jump_table_data *table = dyn_cast <rtx_jump_table_data *> (insn))
  1175. {
  1176. rtvec labels = table->get_labels ();
  1177. int i;
  1178. int len = GET_NUM_ELEM (labels);
  1179. for (i = 0; i < len; i++)
  1180. if (LABEL_NUSES (XEXP (RTVEC_ELT (labels, i), 0)) == 0)
  1181. delete_related_insns (XEXP (RTVEC_ELT (labels, i), 0));
  1182. while (next && next->deleted ())
  1183. next = NEXT_INSN (next);
  1184. return next;
  1185. }
  1186. /* Likewise for any JUMP_P / INSN / CALL_INSN with a
  1187. REG_LABEL_OPERAND or REG_LABEL_TARGET note. */
  1188. if (INSN_P (insn))
  1189. for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1190. if ((REG_NOTE_KIND (note) == REG_LABEL_OPERAND
  1191. || REG_NOTE_KIND (note) == REG_LABEL_TARGET)
  1192. /* This could also be a NOTE_INSN_DELETED_LABEL note. */
  1193. && LABEL_P (XEXP (note, 0)))
  1194. if (LABEL_NUSES (XEXP (note, 0)) == 0)
  1195. delete_related_insns (XEXP (note, 0));
  1196. while (prev && (prev->deleted () || NOTE_P (prev)))
  1197. prev = PREV_INSN (prev);
  1198. /* If INSN was a label and a dispatch table follows it,
  1199. delete the dispatch table. The tablejump must have gone already.
  1200. It isn't useful to fall through into a table. */
  1201. if (was_code_label
  1202. && NEXT_INSN (insn) != 0
  1203. && JUMP_TABLE_DATA_P (NEXT_INSN (insn)))
  1204. next = delete_related_insns (NEXT_INSN (insn));
  1205. /* If INSN was a label, delete insns following it if now unreachable. */
  1206. if (was_code_label && prev && BARRIER_P (prev))
  1207. {
  1208. enum rtx_code code;
  1209. while (next)
  1210. {
  1211. code = GET_CODE (next);
  1212. if (code == NOTE)
  1213. next = NEXT_INSN (next);
  1214. /* Keep going past other deleted labels to delete what follows. */
  1215. else if (code == CODE_LABEL && next->deleted ())
  1216. next = NEXT_INSN (next);
  1217. /* Keep the (use (insn))s created by dbr_schedule, which needs
  1218. them in order to track liveness relative to a previous
  1219. barrier. */
  1220. else if (INSN_P (next)
  1221. && GET_CODE (PATTERN (next)) == USE
  1222. && INSN_P (XEXP (PATTERN (next), 0)))
  1223. next = NEXT_INSN (next);
  1224. else if (code == BARRIER || INSN_P (next))
  1225. /* Note: if this deletes a jump, it can cause more
  1226. deletion of unreachable code, after a different label.
  1227. As long as the value from this recursive call is correct,
  1228. this invocation functions correctly. */
  1229. next = delete_related_insns (next);
  1230. else
  1231. break;
  1232. }
  1233. }
  1234. /* I feel a little doubtful about this loop,
  1235. but I see no clean and sure alternative way
  1236. to find the first insn after INSN that is not now deleted.
  1237. I hope this works. */
  1238. while (next && next->deleted ())
  1239. next = NEXT_INSN (next);
  1240. return next;
  1241. }
  1242. /* Delete a range of insns from FROM to TO, inclusive.
  1243. This is for the sake of peephole optimization, so assume
  1244. that whatever these insns do will still be done by a new
  1245. peephole insn that will replace them. */
  1246. void
  1247. delete_for_peephole (rtx_insn *from, rtx_insn *to)
  1248. {
  1249. rtx_insn *insn = from;
  1250. while (1)
  1251. {
  1252. rtx_insn *next = NEXT_INSN (insn);
  1253. rtx_insn *prev = PREV_INSN (insn);
  1254. if (!NOTE_P (insn))
  1255. {
  1256. insn->set_deleted();
  1257. /* Patch this insn out of the chain. */
  1258. /* We don't do this all at once, because we
  1259. must preserve all NOTEs. */
  1260. if (prev)
  1261. SET_NEXT_INSN (prev) = next;
  1262. if (next)
  1263. SET_PREV_INSN (next) = prev;
  1264. }
  1265. if (insn == to)
  1266. break;
  1267. insn = next;
  1268. }
  1269. /* Note that if TO is an unconditional jump
  1270. we *do not* delete the BARRIER that follows,
  1271. since the peephole that replaces this sequence
  1272. is also an unconditional jump in that case. */
  1273. }
  1274. /* A helper function for redirect_exp_1; examines its input X and returns
  1275. either a LABEL_REF around a label, or a RETURN if X was NULL. */
  1276. static rtx
  1277. redirect_target (rtx x)
  1278. {
  1279. if (x == NULL_RTX)
  1280. return ret_rtx;
  1281. if (!ANY_RETURN_P (x))
  1282. return gen_rtx_LABEL_REF (Pmode, x);
  1283. return x;
  1284. }
  1285. /* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
  1286. NLABEL as a return. Accrue modifications into the change group. */
  1287. static void
  1288. redirect_exp_1 (rtx *loc, rtx olabel, rtx nlabel, rtx insn)
  1289. {
  1290. rtx x = *loc;
  1291. RTX_CODE code = GET_CODE (x);
  1292. int i;
  1293. const char *fmt;
  1294. if ((code == LABEL_REF && LABEL_REF_LABEL (x) == olabel)
  1295. || x == olabel)
  1296. {
  1297. x = redirect_target (nlabel);
  1298. if (GET_CODE (x) == LABEL_REF && loc == &PATTERN (insn))
  1299. x = gen_rtx_SET (VOIDmode, pc_rtx, x);
  1300. validate_change (insn, loc, x, 1);
  1301. return;
  1302. }
  1303. if (code == SET && SET_DEST (x) == pc_rtx
  1304. && ANY_RETURN_P (nlabel)
  1305. && GET_CODE (SET_SRC (x)) == LABEL_REF
  1306. && LABEL_REF_LABEL (SET_SRC (x)) == olabel)
  1307. {
  1308. validate_change (insn, loc, nlabel, 1);
  1309. return;
  1310. }
  1311. if (code == IF_THEN_ELSE)
  1312. {
  1313. /* Skip the condition of an IF_THEN_ELSE. We only want to
  1314. change jump destinations, not eventual label comparisons. */
  1315. redirect_exp_1 (&XEXP (x, 1), olabel, nlabel, insn);
  1316. redirect_exp_1 (&XEXP (x, 2), olabel, nlabel, insn);
  1317. return;
  1318. }
  1319. fmt = GET_RTX_FORMAT (code);
  1320. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1321. {
  1322. if (fmt[i] == 'e')
  1323. redirect_exp_1 (&XEXP (x, i), olabel, nlabel, insn);
  1324. else if (fmt[i] == 'E')
  1325. {
  1326. int j;
  1327. for (j = 0; j < XVECLEN (x, i); j++)
  1328. redirect_exp_1 (&XVECEXP (x, i, j), olabel, nlabel, insn);
  1329. }
  1330. }
  1331. }
  1332. /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
  1333. the modifications into the change group. Return false if we did
  1334. not see how to do that. */
  1335. int
  1336. redirect_jump_1 (rtx jump, rtx nlabel)
  1337. {
  1338. int ochanges = num_validated_changes ();
  1339. rtx *loc, asmop;
  1340. gcc_assert (nlabel != NULL_RTX);
  1341. asmop = extract_asm_operands (PATTERN (jump));
  1342. if (asmop)
  1343. {
  1344. if (nlabel == NULL)
  1345. return 0;
  1346. gcc_assert (ASM_OPERANDS_LABEL_LENGTH (asmop) == 1);
  1347. loc = &ASM_OPERANDS_LABEL (asmop, 0);
  1348. }
  1349. else if (GET_CODE (PATTERN (jump)) == PARALLEL)
  1350. loc = &XVECEXP (PATTERN (jump), 0, 0);
  1351. else
  1352. loc = &PATTERN (jump);
  1353. redirect_exp_1 (loc, JUMP_LABEL (jump), nlabel, jump);
  1354. return num_validated_changes () > ochanges;
  1355. }
  1356. /* Make JUMP go to NLABEL instead of where it jumps now. If the old
  1357. jump target label is unused as a result, it and the code following
  1358. it may be deleted.
  1359. Normally, NLABEL will be a label, but it may also be a RETURN rtx;
  1360. in that case we are to turn the jump into a (possibly conditional)
  1361. return insn.
  1362. The return value will be 1 if the change was made, 0 if it wasn't
  1363. (this can only occur when trying to produce return insns). */
  1364. int
  1365. redirect_jump (rtx jump, rtx nlabel, int delete_unused)
  1366. {
  1367. rtx olabel = JUMP_LABEL (jump);
  1368. if (!nlabel)
  1369. {
  1370. /* If there is no label, we are asked to redirect to the EXIT block.
  1371. When before the epilogue is emitted, return/simple_return cannot be
  1372. created so we return 0 immediately. After the epilogue is emitted,
  1373. we always expect a label, either a non-null label, or a
  1374. return/simple_return RTX. */
  1375. if (!epilogue_completed)
  1376. return 0;
  1377. gcc_unreachable ();
  1378. }
  1379. if (nlabel == olabel)
  1380. return 1;
  1381. if (! redirect_jump_1 (jump, nlabel) || ! apply_change_group ())
  1382. return 0;
  1383. redirect_jump_2 (jump, olabel, nlabel, delete_unused, 0);
  1384. return 1;
  1385. }
  1386. /* Fix up JUMP_LABEL and label ref counts after OLABEL has been replaced with
  1387. NLABEL in JUMP.
  1388. If DELETE_UNUSED is positive, delete related insn to OLABEL if its ref
  1389. count has dropped to zero. */
  1390. void
  1391. redirect_jump_2 (rtx jump, rtx olabel, rtx nlabel, int delete_unused,
  1392. int invert)
  1393. {
  1394. rtx note;
  1395. gcc_assert (JUMP_LABEL (jump) == olabel);
  1396. /* Negative DELETE_UNUSED used to be used to signalize behavior on
  1397. moving FUNCTION_END note. Just sanity check that no user still worry
  1398. about this. */
  1399. gcc_assert (delete_unused >= 0);
  1400. JUMP_LABEL (jump) = nlabel;
  1401. if (!ANY_RETURN_P (nlabel))
  1402. ++LABEL_NUSES (nlabel);
  1403. /* Update labels in any REG_EQUAL note. */
  1404. if ((note = find_reg_note (jump, REG_EQUAL, NULL_RTX)) != NULL_RTX)
  1405. {
  1406. if (ANY_RETURN_P (nlabel)
  1407. || (invert && !invert_exp_1 (XEXP (note, 0), jump)))
  1408. remove_note (jump, note);
  1409. else
  1410. {
  1411. redirect_exp_1 (&XEXP (note, 0), olabel, nlabel, jump);
  1412. confirm_change_group ();
  1413. }
  1414. }
  1415. /* Handle the case where we had a conditional crossing jump to a return
  1416. label and are now changing it into a direct conditional return.
  1417. The jump is no longer crossing in that case. */
  1418. if (ANY_RETURN_P (nlabel))
  1419. CROSSING_JUMP_P (jump) = 0;
  1420. if (!ANY_RETURN_P (olabel)
  1421. && --LABEL_NUSES (olabel) == 0 && delete_unused > 0
  1422. /* Undefined labels will remain outside the insn stream. */
  1423. && INSN_UID (olabel))
  1424. delete_related_insns (olabel);
  1425. if (invert)
  1426. invert_br_probabilities (jump);
  1427. }
  1428. /* Invert the jump condition X contained in jump insn INSN. Accrue the
  1429. modifications into the change group. Return nonzero for success. */
  1430. static int
  1431. invert_exp_1 (rtx x, rtx insn)
  1432. {
  1433. RTX_CODE code = GET_CODE (x);
  1434. if (code == IF_THEN_ELSE)
  1435. {
  1436. rtx comp = XEXP (x, 0);
  1437. rtx tem;
  1438. enum rtx_code reversed_code;
  1439. /* We can do this in two ways: The preferable way, which can only
  1440. be done if this is not an integer comparison, is to reverse
  1441. the comparison code. Otherwise, swap the THEN-part and ELSE-part
  1442. of the IF_THEN_ELSE. If we can't do either, fail. */
  1443. reversed_code = reversed_comparison_code (comp, insn);
  1444. if (reversed_code != UNKNOWN)
  1445. {
  1446. validate_change (insn, &XEXP (x, 0),
  1447. gen_rtx_fmt_ee (reversed_code,
  1448. GET_MODE (comp), XEXP (comp, 0),
  1449. XEXP (comp, 1)),
  1450. 1);
  1451. return 1;
  1452. }
  1453. tem = XEXP (x, 1);
  1454. validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1);
  1455. validate_change (insn, &XEXP (x, 2), tem, 1);
  1456. return 1;
  1457. }
  1458. else
  1459. return 0;
  1460. }
  1461. /* Invert the condition of the jump JUMP, and make it jump to label
  1462. NLABEL instead of where it jumps now. Accrue changes into the
  1463. change group. Return false if we didn't see how to perform the
  1464. inversion and redirection. */
  1465. int
  1466. invert_jump_1 (rtx_insn *jump, rtx nlabel)
  1467. {
  1468. rtx x = pc_set (jump);
  1469. int ochanges;
  1470. int ok;
  1471. ochanges = num_validated_changes ();
  1472. if (x == NULL)
  1473. return 0;
  1474. ok = invert_exp_1 (SET_SRC (x), jump);
  1475. gcc_assert (ok);
  1476. if (num_validated_changes () == ochanges)
  1477. return 0;
  1478. /* redirect_jump_1 will fail of nlabel == olabel, and the current use is
  1479. in Pmode, so checking this is not merely an optimization. */
  1480. return nlabel == JUMP_LABEL (jump) || redirect_jump_1 (jump, nlabel);
  1481. }
  1482. /* Invert the condition of the jump JUMP, and make it jump to label
  1483. NLABEL instead of where it jumps now. Return true if successful. */
  1484. int
  1485. invert_jump (rtx_insn *jump, rtx nlabel, int delete_unused)
  1486. {
  1487. rtx olabel = JUMP_LABEL (jump);
  1488. if (invert_jump_1 (jump, nlabel) && apply_change_group ())
  1489. {
  1490. redirect_jump_2 (jump, olabel, nlabel, delete_unused, 1);
  1491. return 1;
  1492. }
  1493. cancel_changes (0);
  1494. return 0;
  1495. }
  1496. /* Like rtx_equal_p except that it considers two REGs as equal
  1497. if they renumber to the same value and considers two commutative
  1498. operations to be the same if the order of the operands has been
  1499. reversed. */
  1500. int
  1501. rtx_renumbered_equal_p (const_rtx x, const_rtx y)
  1502. {
  1503. int i;
  1504. const enum rtx_code code = GET_CODE (x);
  1505. const char *fmt;
  1506. if (x == y)
  1507. return 1;
  1508. if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
  1509. && (REG_P (y) || (GET_CODE (y) == SUBREG
  1510. && REG_P (SUBREG_REG (y)))))
  1511. {
  1512. int reg_x = -1, reg_y = -1;
  1513. int byte_x = 0, byte_y = 0;
  1514. struct subreg_info info;
  1515. if (GET_MODE (x) != GET_MODE (y))
  1516. return 0;
  1517. /* If we haven't done any renumbering, don't
  1518. make any assumptions. */
  1519. if (reg_renumber == 0)
  1520. return rtx_equal_p (x, y);
  1521. if (code == SUBREG)
  1522. {
  1523. reg_x = REGNO (SUBREG_REG (x));
  1524. byte_x = SUBREG_BYTE (x);
  1525. if (reg_renumber[reg_x] >= 0)
  1526. {
  1527. subreg_get_info (reg_renumber[reg_x],
  1528. GET_MODE (SUBREG_REG (x)), byte_x,
  1529. GET_MODE (x), &info);
  1530. if (!info.representable_p)
  1531. return 0;
  1532. reg_x = info.offset;
  1533. byte_x = 0;
  1534. }
  1535. }
  1536. else
  1537. {
  1538. reg_x = REGNO (x);
  1539. if (reg_renumber[reg_x] >= 0)
  1540. reg_x = reg_renumber[reg_x];
  1541. }
  1542. if (GET_CODE (y) == SUBREG)
  1543. {
  1544. reg_y = REGNO (SUBREG_REG (y));
  1545. byte_y = SUBREG_BYTE (y);
  1546. if (reg_renumber[reg_y] >= 0)
  1547. {
  1548. subreg_get_info (reg_renumber[reg_y],
  1549. GET_MODE (SUBREG_REG (y)), byte_y,
  1550. GET_MODE (y), &info);
  1551. if (!info.representable_p)
  1552. return 0;
  1553. reg_y = info.offset;
  1554. byte_y = 0;
  1555. }
  1556. }
  1557. else
  1558. {
  1559. reg_y = REGNO (y);
  1560. if (reg_renumber[reg_y] >= 0)
  1561. reg_y = reg_renumber[reg_y];
  1562. }
  1563. return reg_x >= 0 && reg_x == reg_y && byte_x == byte_y;
  1564. }
  1565. /* Now we have disposed of all the cases
  1566. in which different rtx codes can match. */
  1567. if (code != GET_CODE (y))
  1568. return 0;
  1569. switch (code)
  1570. {
  1571. case PC:
  1572. case CC0:
  1573. case ADDR_VEC:
  1574. case ADDR_DIFF_VEC:
  1575. CASE_CONST_UNIQUE:
  1576. return 0;
  1577. case LABEL_REF:
  1578. /* We can't assume nonlocal labels have their following insns yet. */
  1579. if (LABEL_REF_NONLOCAL_P (x) || LABEL_REF_NONLOCAL_P (y))
  1580. return LABEL_REF_LABEL (x) == LABEL_REF_LABEL (y);
  1581. /* Two label-refs are equivalent if they point at labels
  1582. in the same position in the instruction stream. */
  1583. return (next_real_insn (LABEL_REF_LABEL (x))
  1584. == next_real_insn (LABEL_REF_LABEL (y)));
  1585. case SYMBOL_REF:
  1586. return XSTR (x, 0) == XSTR (y, 0);
  1587. case CODE_LABEL:
  1588. /* If we didn't match EQ equality above, they aren't the same. */
  1589. return 0;
  1590. default:
  1591. break;
  1592. }
  1593. /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
  1594. if (GET_MODE (x) != GET_MODE (y))
  1595. return 0;
  1596. /* MEMs referring to different address space are not equivalent. */
  1597. if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
  1598. return 0;
  1599. /* For commutative operations, the RTX match if the operand match in any
  1600. order. Also handle the simple binary and unary cases without a loop. */
  1601. if (targetm.commutative_p (x, UNKNOWN))
  1602. return ((rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
  1603. && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)))
  1604. || (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 1))
  1605. && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 0))));
  1606. else if (NON_COMMUTATIVE_P (x))
  1607. return (rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0))
  1608. && rtx_renumbered_equal_p (XEXP (x, 1), XEXP (y, 1)));
  1609. else if (UNARY_P (x))
  1610. return rtx_renumbered_equal_p (XEXP (x, 0), XEXP (y, 0));
  1611. /* Compare the elements. If any pair of corresponding elements
  1612. fail to match, return 0 for the whole things. */
  1613. fmt = GET_RTX_FORMAT (code);
  1614. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1615. {
  1616. int j;
  1617. switch (fmt[i])
  1618. {
  1619. case 'w':
  1620. if (XWINT (x, i) != XWINT (y, i))
  1621. return 0;
  1622. break;
  1623. case 'i':
  1624. if (XINT (x, i) != XINT (y, i))
  1625. {
  1626. if (((code == ASM_OPERANDS && i == 6)
  1627. || (code == ASM_INPUT && i == 1)))
  1628. break;
  1629. return 0;
  1630. }
  1631. break;
  1632. case 't':
  1633. if (XTREE (x, i) != XTREE (y, i))
  1634. return 0;
  1635. break;
  1636. case 's':
  1637. if (strcmp (XSTR (x, i), XSTR (y, i)))
  1638. return 0;
  1639. break;
  1640. case 'e':
  1641. if (! rtx_renumbered_equal_p (XEXP (x, i), XEXP (y, i)))
  1642. return 0;
  1643. break;
  1644. case 'u':
  1645. if (XEXP (x, i) != XEXP (y, i))
  1646. return 0;
  1647. /* Fall through. */
  1648. case '0':
  1649. break;
  1650. case 'E':
  1651. if (XVECLEN (x, i) != XVECLEN (y, i))
  1652. return 0;
  1653. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1654. if (!rtx_renumbered_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)))
  1655. return 0;
  1656. break;
  1657. default:
  1658. gcc_unreachable ();
  1659. }
  1660. }
  1661. return 1;
  1662. }
  1663. /* If X is a hard register or equivalent to one or a subregister of one,
  1664. return the hard register number. If X is a pseudo register that was not
  1665. assigned a hard register, return the pseudo register number. Otherwise,
  1666. return -1. Any rtx is valid for X. */
  1667. int
  1668. true_regnum (const_rtx x)
  1669. {
  1670. if (REG_P (x))
  1671. {
  1672. if (REGNO (x) >= FIRST_PSEUDO_REGISTER
  1673. && (lra_in_progress || reg_renumber[REGNO (x)] >= 0))
  1674. return reg_renumber[REGNO (x)];
  1675. return REGNO (x);
  1676. }
  1677. if (GET_CODE (x) == SUBREG)
  1678. {
  1679. int base = true_regnum (SUBREG_REG (x));
  1680. if (base >= 0
  1681. && base < FIRST_PSEUDO_REGISTER)
  1682. {
  1683. struct subreg_info info;
  1684. subreg_get_info (lra_in_progress
  1685. ? (unsigned) base : REGNO (SUBREG_REG (x)),
  1686. GET_MODE (SUBREG_REG (x)),
  1687. SUBREG_BYTE (x), GET_MODE (x), &info);
  1688. if (info.representable_p)
  1689. return base + info.offset;
  1690. }
  1691. }
  1692. return -1;
  1693. }
  1694. /* Return regno of the register REG and handle subregs too. */
  1695. unsigned int
  1696. reg_or_subregno (const_rtx reg)
  1697. {
  1698. if (GET_CODE (reg) == SUBREG)
  1699. reg = SUBREG_REG (reg);
  1700. gcc_assert (REG_P (reg));
  1701. return REGNO (reg);
  1702. }