forked from openhwgroup/corev-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathifcvt.cc
6097 lines (5103 loc) · 168 KB
/
ifcvt.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* If-conversion support.
Copyright (C) 2000-2023 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "cfghooks.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "expmed.h"
#include "optabs.h"
#include "regs.h"
#include "emit-rtl.h"
#include "recog.h"
#include "cfgrtl.h"
#include "cfganal.h"
#include "cfgcleanup.h"
#include "expr.h"
#include "output.h"
#include "cfgloop.h"
#include "tree-pass.h"
#include "dbgcnt.h"
#include "shrink-wrap.h"
#include "rtl-iter.h"
#include "ifcvt.h"
#ifndef MAX_CONDITIONAL_EXECUTE
#define MAX_CONDITIONAL_EXECUTE \
(BRANCH_COST (optimize_function_for_speed_p (cfun), false) \
+ 1)
#endif
#define IFCVT_MULTIPLE_DUMPS 1
#define NULL_BLOCK ((basic_block) NULL)
/* True if after combine pass. */
static bool ifcvt_after_combine;
/* True if the target has the cbranchcc4 optab. */
static bool have_cbranchcc4;
/* # of IF-THEN or IF-THEN-ELSE blocks we looked at */
static int num_possible_if_blocks;
/* # of IF-THEN or IF-THEN-ELSE blocks were converted to conditional
execution. */
static int num_updated_if_blocks;
/* # of changes made. */
static int num_true_changes;
/* Whether conditional execution changes were made. */
static bool cond_exec_changed_p;
/* Forward references. */
static int count_bb_insns (const_basic_block);
static bool cheap_bb_rtx_cost_p (const_basic_block, profile_probability, int);
static rtx_insn *first_active_insn (basic_block);
static rtx_insn *last_active_insn (basic_block, bool);
static rtx_insn *find_active_insn_before (basic_block, rtx_insn *);
static rtx_insn *find_active_insn_after (basic_block, rtx_insn *);
static basic_block block_fallthru (basic_block);
static rtx cond_exec_get_condition (rtx_insn *, bool);
static rtx noce_get_condition (rtx_insn *, rtx_insn **, bool);
static bool noce_operand_ok (const_rtx);
static void merge_if_block (ce_if_block *);
static bool find_cond_trap (basic_block, edge, edge);
static basic_block find_if_header (basic_block, int);
static int block_jumps_and_fallthru (basic_block, basic_block);
static bool noce_find_if_block (basic_block, edge, edge, int);
static bool cond_exec_find_if_block (ce_if_block *);
static bool find_if_case_1 (basic_block, edge, edge);
static bool find_if_case_2 (basic_block, edge, edge);
static bool dead_or_predicable (basic_block, basic_block, basic_block,
edge, bool);
static void noce_emit_move_insn (rtx, rtx);
static rtx_insn *block_has_only_trap (basic_block);
static void need_cmov_or_rewire (basic_block, hash_set<rtx_insn *> *,
hash_map<rtx_insn *, int> *);
static bool noce_convert_multiple_sets_1 (struct noce_if_info *,
hash_set<rtx_insn *> *,
hash_map<rtx_insn *, int> *,
auto_vec<rtx> *,
auto_vec<rtx> *,
auto_vec<rtx_insn *> *, int *);
/* Count the number of non-jump active insns in BB. */
static int
count_bb_insns (const_basic_block bb)
{
int count = 0;
rtx_insn *insn = BB_HEAD (bb);
while (1)
{
if (active_insn_p (insn) && !JUMP_P (insn))
count++;
if (insn == BB_END (bb))
break;
insn = NEXT_INSN (insn);
}
return count;
}
/* Determine whether the total insn_cost on non-jump insns in
basic block BB is less than MAX_COST. This function returns
false if the cost of any instruction could not be estimated.
The cost of the non-jump insns in BB is scaled by REG_BR_PROB_BASE
as those insns are being speculated. MAX_COST is scaled with SCALE
plus a small fudge factor. */
static bool
cheap_bb_rtx_cost_p (const_basic_block bb,
profile_probability prob, int max_cost)
{
int count = 0;
rtx_insn *insn = BB_HEAD (bb);
bool speed = optimize_bb_for_speed_p (bb);
int scale = prob.initialized_p () ? prob.to_reg_br_prob_base ()
: REG_BR_PROB_BASE;
/* Set scale to REG_BR_PROB_BASE to void the identical scaling
applied to insn_cost when optimizing for size. Only do
this after combine because if-conversion might interfere with
passes before combine.
Use optimize_function_for_speed_p instead of the pre-defined
variable speed to make sure it is set to same value for all
basic blocks in one if-conversion transformation. */
if (!optimize_function_for_speed_p (cfun) && ifcvt_after_combine)
scale = REG_BR_PROB_BASE;
/* Our branch probability/scaling factors are just estimates and don't
account for cases where we can get speculation for free and other
secondary benefits. So we fudge the scale factor to make speculating
appear a little more profitable when optimizing for performance. */
else
scale += REG_BR_PROB_BASE / 8;
max_cost *= scale;
while (1)
{
if (NONJUMP_INSN_P (insn))
{
int cost = insn_cost (insn, speed) * REG_BR_PROB_BASE;
if (cost == 0)
return false;
/* If this instruction is the load or set of a "stack" register,
such as a floating point register on x87, then the cost of
speculatively executing this insn may need to include
the additional cost of popping its result off of the
register stack. Unfortunately, correctly recognizing and
accounting for this additional overhead is tricky, so for
now we simply prohibit such speculative execution. */
#ifdef STACK_REGS
{
rtx set = single_set (insn);
if (set && STACK_REG_P (SET_DEST (set)))
return false;
}
#endif
count += cost;
if (count >= max_cost)
return false;
}
else if (CALL_P (insn))
return false;
if (insn == BB_END (bb))
break;
insn = NEXT_INSN (insn);
}
return true;
}
/* Return the first non-jump active insn in the basic block. */
static rtx_insn *
first_active_insn (basic_block bb)
{
rtx_insn *insn = BB_HEAD (bb);
if (LABEL_P (insn))
{
if (insn == BB_END (bb))
return NULL;
insn = NEXT_INSN (insn);
}
while (NOTE_P (insn) || DEBUG_INSN_P (insn))
{
if (insn == BB_END (bb))
return NULL;
insn = NEXT_INSN (insn);
}
if (JUMP_P (insn))
return NULL;
return insn;
}
/* Return the last non-jump active (non-jump) insn in the basic block. */
static rtx_insn *
last_active_insn (basic_block bb, bool skip_use_p)
{
rtx_insn *insn = BB_END (bb);
rtx_insn *head = BB_HEAD (bb);
while (NOTE_P (insn)
|| JUMP_P (insn)
|| DEBUG_INSN_P (insn)
|| (skip_use_p
&& NONJUMP_INSN_P (insn)
&& GET_CODE (PATTERN (insn)) == USE))
{
if (insn == head)
return NULL;
insn = PREV_INSN (insn);
}
if (LABEL_P (insn))
return NULL;
return insn;
}
/* Return the active insn before INSN inside basic block CURR_BB. */
static rtx_insn *
find_active_insn_before (basic_block curr_bb, rtx_insn *insn)
{
if (!insn || insn == BB_HEAD (curr_bb))
return NULL;
while ((insn = PREV_INSN (insn)) != NULL_RTX)
{
if (NONJUMP_INSN_P (insn) || JUMP_P (insn) || CALL_P (insn))
break;
/* No other active insn all the way to the start of the basic block. */
if (insn == BB_HEAD (curr_bb))
return NULL;
}
return insn;
}
/* Return the active insn after INSN inside basic block CURR_BB. */
static rtx_insn *
find_active_insn_after (basic_block curr_bb, rtx_insn *insn)
{
if (!insn || insn == BB_END (curr_bb))
return NULL;
while ((insn = NEXT_INSN (insn)) != NULL_RTX)
{
if (NONJUMP_INSN_P (insn) || JUMP_P (insn) || CALL_P (insn))
break;
/* No other active insn all the way to the end of the basic block. */
if (insn == BB_END (curr_bb))
return NULL;
}
return insn;
}
/* Return the basic block reached by falling though the basic block BB. */
static basic_block
block_fallthru (basic_block bb)
{
edge e = find_fallthru_edge (bb->succs);
return (e) ? e->dest : NULL_BLOCK;
}
/* Return true if RTXs A and B can be safely interchanged. */
static bool
rtx_interchangeable_p (const_rtx a, const_rtx b)
{
if (!rtx_equal_p (a, b))
return false;
if (GET_CODE (a) != MEM)
return true;
/* A dead type-unsafe memory reference is legal, but a live type-unsafe memory
reference is not. Interchanging a dead type-unsafe memory reference with
a live type-safe one creates a live type-unsafe memory reference, in other
words, it makes the program illegal.
We check here conservatively whether the two memory references have equal
memory attributes. */
return mem_attrs_eq_p (get_mem_attrs (a), get_mem_attrs (b));
}
/* Go through a bunch of insns, converting them to conditional
execution format if possible. Return TRUE if all of the non-note
insns were processed. */
static bool
cond_exec_process_insns (ce_if_block *ce_info ATTRIBUTE_UNUSED,
/* if block information */rtx_insn *start,
/* first insn to look at */rtx end,
/* last insn to look at */rtx test,
/* conditional execution test */profile_probability
prob_val,
/* probability of branch taken. */bool mod_ok)
{
bool must_be_last = false;
rtx_insn *insn;
rtx xtest;
rtx pattern;
if (!start || !end)
return false;
for (insn = start; ; insn = NEXT_INSN (insn))
{
/* dwarf2out can't cope with conditional prologues. */
if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_PROLOGUE_END)
return false;
if (NOTE_P (insn) || DEBUG_INSN_P (insn))
goto insn_done;
gcc_assert (NONJUMP_INSN_P (insn) || CALL_P (insn));
/* dwarf2out can't cope with conditional unwind info. */
if (RTX_FRAME_RELATED_P (insn))
return false;
/* Remove USE insns that get in the way. */
if (reload_completed && GET_CODE (PATTERN (insn)) == USE)
{
/* ??? Ug. Actually unlinking the thing is problematic,
given what we'd have to coordinate with our callers. */
SET_INSN_DELETED (insn);
goto insn_done;
}
/* Last insn wasn't last? */
if (must_be_last)
return false;
if (modified_in_p (test, insn))
{
if (!mod_ok)
return false;
must_be_last = true;
}
/* Now build the conditional form of the instruction. */
pattern = PATTERN (insn);
xtest = copy_rtx (test);
/* If this is already a COND_EXEC, rewrite the test to be an AND of the
two conditions. */
if (GET_CODE (pattern) == COND_EXEC)
{
if (GET_MODE (xtest) != GET_MODE (COND_EXEC_TEST (pattern)))
return false;
xtest = gen_rtx_AND (GET_MODE (xtest), xtest,
COND_EXEC_TEST (pattern));
pattern = COND_EXEC_CODE (pattern);
}
pattern = gen_rtx_COND_EXEC (VOIDmode, xtest, pattern);
/* If the machine needs to modify the insn being conditionally executed,
say for example to force a constant integer operand into a temp
register, do so here. */
#ifdef IFCVT_MODIFY_INSN
IFCVT_MODIFY_INSN (ce_info, pattern, insn);
if (! pattern)
return false;
#endif
validate_change (insn, &PATTERN (insn), pattern, 1);
if (CALL_P (insn) && prob_val.initialized_p ())
validate_change (insn, ®_NOTES (insn),
gen_rtx_INT_LIST ((machine_mode) REG_BR_PROB,
prob_val.to_reg_br_prob_note (),
REG_NOTES (insn)), 1);
insn_done:
if (insn == end)
break;
}
return true;
}
/* Return the condition for a jump. Do not do any special processing. */
static rtx
cond_exec_get_condition (rtx_insn *jump, bool get_reversed = false)
{
rtx test_if, cond;
if (any_condjump_p (jump))
test_if = SET_SRC (pc_set (jump));
else
return NULL_RTX;
cond = XEXP (test_if, 0);
/* If this branches to JUMP_LABEL when the condition is false,
reverse the condition. */
if (get_reversed
|| (GET_CODE (XEXP (test_if, 2)) == LABEL_REF
&& label_ref_label (XEXP (test_if, 2))
== JUMP_LABEL (jump)))
{
enum rtx_code rev = reversed_comparison_code (cond, jump);
if (rev == UNKNOWN)
return NULL_RTX;
cond = gen_rtx_fmt_ee (rev, GET_MODE (cond), XEXP (cond, 0),
XEXP (cond, 1));
}
return cond;
}
/* Given a simple IF-THEN or IF-THEN-ELSE block, attempt to convert it
to conditional execution. Return TRUE if we were successful at
converting the block. */
static bool
cond_exec_process_if_block (ce_if_block * ce_info,
/* if block information */bool do_multiple_p)
{
basic_block test_bb = ce_info->test_bb; /* last test block */
basic_block then_bb = ce_info->then_bb; /* THEN */
basic_block else_bb = ce_info->else_bb; /* ELSE or NULL */
rtx test_expr; /* expression in IF_THEN_ELSE that is tested */
rtx_insn *then_start; /* first insn in THEN block */
rtx_insn *then_end; /* last insn + 1 in THEN block */
rtx_insn *else_start = NULL; /* first insn in ELSE block or NULL */
rtx_insn *else_end = NULL; /* last insn + 1 in ELSE block */
int max; /* max # of insns to convert. */
bool then_mod_ok; /* whether conditional mods are ok in THEN */
rtx true_expr; /* test for else block insns */
rtx false_expr; /* test for then block insns */
profile_probability true_prob_val;/* probability of else block */
profile_probability false_prob_val;/* probability of then block */
rtx_insn *then_last_head = NULL; /* Last match at the head of THEN */
rtx_insn *else_last_head = NULL; /* Last match at the head of ELSE */
rtx_insn *then_first_tail = NULL; /* First match at the tail of THEN */
rtx_insn *else_first_tail = NULL; /* First match at the tail of ELSE */
int then_n_insns, else_n_insns, n_insns;
enum rtx_code false_code;
rtx note;
/* If test is comprised of && or || elements, and we've failed at handling
all of them together, just use the last test if it is the special case of
&& elements without an ELSE block. */
if (!do_multiple_p && ce_info->num_multiple_test_blocks)
{
if (else_bb || ! ce_info->and_and_p)
return false;
ce_info->test_bb = test_bb = ce_info->last_test_bb;
ce_info->num_multiple_test_blocks = 0;
ce_info->num_and_and_blocks = 0;
ce_info->num_or_or_blocks = 0;
}
/* Find the conditional jump to the ELSE or JOIN part, and isolate
the test. */
test_expr = cond_exec_get_condition (BB_END (test_bb));
if (! test_expr)
return false;
/* If the conditional jump is more than just a conditional jump,
then we cannot do conditional execution conversion on this block. */
if (! onlyjump_p (BB_END (test_bb)))
return false;
/* Collect the bounds of where we're to search, skipping any labels, jumps
and notes at the beginning and end of the block. Then count the total
number of insns and see if it is small enough to convert. */
then_start = first_active_insn (then_bb);
then_end = last_active_insn (then_bb, true);
then_n_insns = ce_info->num_then_insns = count_bb_insns (then_bb);
n_insns = then_n_insns;
max = MAX_CONDITIONAL_EXECUTE;
if (else_bb)
{
int n_matching;
max *= 2;
else_start = first_active_insn (else_bb);
else_end = last_active_insn (else_bb, true);
else_n_insns = ce_info->num_else_insns = count_bb_insns (else_bb);
n_insns += else_n_insns;
/* Look for matching sequences at the head and tail of the two blocks,
and limit the range of insns to be converted if possible. */
n_matching = flow_find_cross_jump (then_bb, else_bb,
&then_first_tail, &else_first_tail,
NULL);
if (then_first_tail == BB_HEAD (then_bb))
then_start = then_end = NULL;
if (else_first_tail == BB_HEAD (else_bb))
else_start = else_end = NULL;
if (n_matching > 0)
{
if (then_end)
then_end = find_active_insn_before (then_bb, then_first_tail);
if (else_end)
else_end = find_active_insn_before (else_bb, else_first_tail);
n_insns -= 2 * n_matching;
}
if (then_start
&& else_start
&& then_n_insns > n_matching
&& else_n_insns > n_matching)
{
int longest_match = MIN (then_n_insns - n_matching,
else_n_insns - n_matching);
n_matching
= flow_find_head_matching_sequence (then_bb, else_bb,
&then_last_head,
&else_last_head,
longest_match);
if (n_matching > 0)
{
rtx_insn *insn;
/* We won't pass the insns in the head sequence to
cond_exec_process_insns, so we need to test them here
to make sure that they don't clobber the condition. */
for (insn = BB_HEAD (then_bb);
insn != NEXT_INSN (then_last_head);
insn = NEXT_INSN (insn))
if (!LABEL_P (insn) && !NOTE_P (insn)
&& !DEBUG_INSN_P (insn)
&& modified_in_p (test_expr, insn))
return false;
}
if (then_last_head == then_end)
then_start = then_end = NULL;
if (else_last_head == else_end)
else_start = else_end = NULL;
if (n_matching > 0)
{
if (then_start)
then_start = find_active_insn_after (then_bb, then_last_head);
if (else_start)
else_start = find_active_insn_after (else_bb, else_last_head);
n_insns -= 2 * n_matching;
}
}
}
if (n_insns > max)
return false;
/* Map test_expr/test_jump into the appropriate MD tests to use on
the conditionally executed code. */
true_expr = test_expr;
false_code = reversed_comparison_code (true_expr, BB_END (test_bb));
if (false_code != UNKNOWN)
false_expr = gen_rtx_fmt_ee (false_code, GET_MODE (true_expr),
XEXP (true_expr, 0), XEXP (true_expr, 1));
else
false_expr = NULL_RTX;
#ifdef IFCVT_MODIFY_TESTS
/* If the machine description needs to modify the tests, such as setting a
conditional execution register from a comparison, it can do so here. */
IFCVT_MODIFY_TESTS (ce_info, true_expr, false_expr);
/* See if the conversion failed. */
if (!true_expr || !false_expr)
goto fail;
#endif
note = find_reg_note (BB_END (test_bb), REG_BR_PROB, NULL_RTX);
if (note)
{
true_prob_val = profile_probability::from_reg_br_prob_note (XINT (note, 0));
false_prob_val = true_prob_val.invert ();
}
else
{
true_prob_val = profile_probability::uninitialized ();
false_prob_val = profile_probability::uninitialized ();
}
/* If we have && or || tests, do them here. These tests are in the adjacent
blocks after the first block containing the test. */
if (ce_info->num_multiple_test_blocks > 0)
{
basic_block bb = test_bb;
basic_block last_test_bb = ce_info->last_test_bb;
if (! false_expr)
goto fail;
do
{
rtx_insn *start, *end;
rtx t, f;
enum rtx_code f_code;
bb = block_fallthru (bb);
start = first_active_insn (bb);
end = last_active_insn (bb, true);
if (start
&& ! cond_exec_process_insns (ce_info, start, end, false_expr,
false_prob_val, false))
goto fail;
/* If the conditional jump is more than just a conditional jump, then
we cannot do conditional execution conversion on this block. */
if (! onlyjump_p (BB_END (bb)))
goto fail;
/* Find the conditional jump and isolate the test. */
t = cond_exec_get_condition (BB_END (bb));
if (! t)
goto fail;
f_code = reversed_comparison_code (t, BB_END (bb));
if (f_code == UNKNOWN)
goto fail;
f = gen_rtx_fmt_ee (f_code, GET_MODE (t), XEXP (t, 0), XEXP (t, 1));
if (ce_info->and_and_p)
{
t = gen_rtx_AND (GET_MODE (t), true_expr, t);
f = gen_rtx_IOR (GET_MODE (t), false_expr, f);
}
else
{
t = gen_rtx_IOR (GET_MODE (t), true_expr, t);
f = gen_rtx_AND (GET_MODE (t), false_expr, f);
}
/* If the machine description needs to modify the tests, such as
setting a conditional execution register from a comparison, it can
do so here. */
#ifdef IFCVT_MODIFY_MULTIPLE_TESTS
IFCVT_MODIFY_MULTIPLE_TESTS (ce_info, bb, t, f);
/* See if the conversion failed. */
if (!t || !f)
goto fail;
#endif
true_expr = t;
false_expr = f;
}
while (bb != last_test_bb);
}
/* For IF-THEN-ELSE blocks, we don't allow modifications of the test
on then THEN block. */
then_mod_ok = (else_bb == NULL_BLOCK);
/* Go through the THEN and ELSE blocks converting the insns if possible
to conditional execution. */
if (then_end
&& (! false_expr
|| ! cond_exec_process_insns (ce_info, then_start, then_end,
false_expr, false_prob_val,
then_mod_ok)))
goto fail;
if (else_bb && else_end
&& ! cond_exec_process_insns (ce_info, else_start, else_end,
true_expr, true_prob_val, true))
goto fail;
/* If we cannot apply the changes, fail. Do not go through the normal fail
processing, since apply_change_group will call cancel_changes. */
if (! apply_change_group ())
{
#ifdef IFCVT_MODIFY_CANCEL
/* Cancel any machine dependent changes. */
IFCVT_MODIFY_CANCEL (ce_info);
#endif
return false;
}
#ifdef IFCVT_MODIFY_FINAL
/* Do any machine dependent final modifications. */
IFCVT_MODIFY_FINAL (ce_info);
#endif
/* Conversion succeeded. */
if (dump_file)
fprintf (dump_file, "%d insn%s converted to conditional execution.\n",
n_insns, (n_insns == 1) ? " was" : "s were");
/* Merge the blocks! If we had matching sequences, make sure to delete one
copy at the appropriate location first: delete the copy in the THEN branch
for a tail sequence so that the remaining one is executed last for both
branches, and delete the copy in the ELSE branch for a head sequence so
that the remaining one is executed first for both branches. */
if (then_first_tail)
{
rtx_insn *from = then_first_tail;
if (!INSN_P (from))
from = find_active_insn_after (then_bb, from);
delete_insn_chain (from, get_last_bb_insn (then_bb), false);
}
if (else_last_head)
delete_insn_chain (first_active_insn (else_bb), else_last_head, false);
merge_if_block (ce_info);
cond_exec_changed_p = true;
return true;
fail:
#ifdef IFCVT_MODIFY_CANCEL
/* Cancel any machine dependent changes. */
IFCVT_MODIFY_CANCEL (ce_info);
#endif
cancel_changes (0);
return false;
}
static rtx noce_emit_store_flag (struct noce_if_info *, rtx, bool, int);
static bool noce_try_move (struct noce_if_info *);
static bool noce_try_ifelse_collapse (struct noce_if_info *);
static bool noce_try_store_flag (struct noce_if_info *);
static bool noce_try_addcc (struct noce_if_info *);
static bool noce_try_store_flag_constants (struct noce_if_info *);
static bool noce_try_store_flag_mask (struct noce_if_info *);
static rtx noce_emit_cmove (struct noce_if_info *, rtx, enum rtx_code, rtx,
rtx, rtx, rtx, rtx = NULL, rtx = NULL);
static bool noce_try_cmove (struct noce_if_info *);
static bool noce_try_cmove_arith (struct noce_if_info *);
static rtx noce_get_alt_condition (struct noce_if_info *, rtx, rtx_insn **);
static bool noce_try_minmax (struct noce_if_info *);
static bool noce_try_abs (struct noce_if_info *);
static bool noce_try_sign_mask (struct noce_if_info *);
/* Return the comparison code for reversed condition for IF_INFO,
or UNKNOWN if reversing the condition is not possible. */
static inline enum rtx_code
noce_reversed_cond_code (struct noce_if_info *if_info)
{
if (if_info->rev_cond)
return GET_CODE (if_info->rev_cond);
return reversed_comparison_code (if_info->cond, if_info->jump);
}
/* Return true if SEQ is a good candidate as a replacement for the
if-convertible sequence described in IF_INFO.
This is the default implementation that targets can override
through a target hook. */
bool
default_noce_conversion_profitable_p (rtx_insn *seq,
struct noce_if_info *if_info)
{
bool speed_p = if_info->speed_p;
/* Cost up the new sequence. */
unsigned int cost = seq_cost (seq, speed_p);
if (cost <= if_info->original_cost)
return true;
/* When compiling for size, we can make a reasonably accurately guess
at the size growth. When compiling for speed, use the maximum. */
return speed_p && cost <= if_info->max_seq_cost;
}
/* Helper function for noce_try_store_flag*. */
static rtx
noce_emit_store_flag (struct noce_if_info *if_info, rtx x, bool reversep,
int normalize)
{
rtx cond = if_info->cond;
bool cond_complex;
enum rtx_code code;
cond_complex = (! general_operand (XEXP (cond, 0), VOIDmode)
|| ! general_operand (XEXP (cond, 1), VOIDmode));
/* If earliest == jump, or when the condition is complex, try to
build the store_flag insn directly. */
if (cond_complex)
{
rtx set = pc_set (if_info->jump);
cond = XEXP (SET_SRC (set), 0);
if (GET_CODE (XEXP (SET_SRC (set), 2)) == LABEL_REF
&& label_ref_label (XEXP (SET_SRC (set), 2)) == JUMP_LABEL (if_info->jump))
reversep = !reversep;
if (if_info->then_else_reversed)
reversep = !reversep;
}
else if (reversep
&& if_info->rev_cond
&& general_operand (XEXP (if_info->rev_cond, 0), VOIDmode)
&& general_operand (XEXP (if_info->rev_cond, 1), VOIDmode))
{
cond = if_info->rev_cond;
reversep = false;
}
if (reversep)
code = reversed_comparison_code (cond, if_info->jump);
else
code = GET_CODE (cond);
if ((if_info->cond_earliest == if_info->jump || cond_complex)
&& (normalize == 0 || STORE_FLAG_VALUE == normalize))
{
rtx src = gen_rtx_fmt_ee (code, GET_MODE (x), XEXP (cond, 0),
XEXP (cond, 1));
rtx set = gen_rtx_SET (x, src);
start_sequence ();
rtx_insn *insn = emit_insn (set);
if (recog_memoized (insn) >= 0)
{
rtx_insn *seq = get_insns ();
end_sequence ();
emit_insn (seq);
if_info->cond_earliest = if_info->jump;
return x;
}
end_sequence ();
}
/* Don't even try if the comparison operands or the mode of X are weird. */
if (cond_complex || !SCALAR_INT_MODE_P (GET_MODE (x)))
return NULL_RTX;
return emit_store_flag (x, code, XEXP (cond, 0),
XEXP (cond, 1), VOIDmode,
(code == LTU || code == LEU
|| code == GEU || code == GTU), normalize);
}
/* Return true if X can be safely forced into a register by copy_to_mode_reg
/ force_operand. */
static bool
noce_can_force_operand (rtx x)
{
if (general_operand (x, VOIDmode))
return true;
if (SUBREG_P (x))
{
if (!noce_can_force_operand (SUBREG_REG (x)))
return false;
return true;
}
if (ARITHMETIC_P (x))
{
if (!noce_can_force_operand (XEXP (x, 0))
|| !noce_can_force_operand (XEXP (x, 1)))
return false;
switch (GET_CODE (x))
{
case MULT:
case DIV:
case MOD:
case UDIV:
case UMOD:
return true;
default:
return code_to_optab (GET_CODE (x));
}
}
if (UNARY_P (x))
{
if (!noce_can_force_operand (XEXP (x, 0)))
return false;
switch (GET_CODE (x))
{
case ZERO_EXTEND:
case SIGN_EXTEND:
case TRUNCATE:
case FLOAT_EXTEND:
case FLOAT_TRUNCATE:
case FIX:
case UNSIGNED_FIX:
case FLOAT:
case UNSIGNED_FLOAT:
return true;
default:
return code_to_optab (GET_CODE (x));
}
}
return false;
}
/* Emit instruction to move an rtx, possibly into STRICT_LOW_PART.
X is the destination/target and Y is the value to copy. */
static void
noce_emit_move_insn (rtx x, rtx y)
{
machine_mode outmode;
rtx outer, inner;
poly_int64 bitpos;
if (GET_CODE (x) != STRICT_LOW_PART)
{
rtx_insn *seq, *insn;
rtx target;
optab ot;
start_sequence ();
/* Check that the SET_SRC is reasonable before calling emit_move_insn,
otherwise construct a suitable SET pattern ourselves. */
insn = (OBJECT_P (y) || CONSTANT_P (y) || GET_CODE (y) == SUBREG)
? emit_move_insn (x, y)
: emit_insn (gen_rtx_SET (x, y));
seq = get_insns ();
end_sequence ();
if (recog_memoized (insn) <= 0)
{
if (GET_CODE (x) == ZERO_EXTRACT)
{
rtx op = XEXP (x, 0);
unsigned HOST_WIDE_INT size = INTVAL (XEXP (x, 1));
unsigned HOST_WIDE_INT start = INTVAL (XEXP (x, 2));
/* store_bit_field expects START to be relative to
BYTES_BIG_ENDIAN and adjusts this value for machines with
BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN. In order to be able to
invoke store_bit_field again it is necessary to have the START
value from the first call. */
if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
{
if (MEM_P (op))
start = BITS_PER_UNIT - start - size;
else
{
gcc_assert (REG_P (op));
start = BITS_PER_WORD - start - size;
}
}