mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
match.pd
10776 lines (10007 loc) · 371 KB
/
match.pd
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
/* Match-and-simplify patterns for shared GENERIC and GIMPLE folding.
This file is consumed by genmatch which produces gimple-match.cc
and generic-match.cc from it.
Copyright (C) 2014-2024 Free Software Foundation, Inc.
Contributed by Richard Biener <rguenther@suse.de>
and Prathamesh Kulkarni <bilbotheelffriend@gmail.com>
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/>. */
/* Generic tree predicates we inherit. */
(define_predicates
integer_onep integer_zerop integer_all_onesp integer_minus_onep
integer_each_onep integer_truep integer_nonzerop
real_zerop real_onep real_minus_onep
zerop
initializer_each_zero_or_onep
CONSTANT_CLASS_P
tree_expr_nonnegative_p
tree_expr_nonzero_p
integer_valued_real_p
integer_pow2p
uniform_integer_cst_p
HONOR_NANS
uniform_vector_p
expand_vec_cmp_expr_p
bitmask_inv_cst_vector_p)
/* Operator lists. */
(define_operator_list tcc_comparison
lt le eq ne ge gt unordered ordered unlt unle ungt unge uneq ltgt)
(define_operator_list inverted_tcc_comparison
ge gt ne eq lt le ordered unordered ge gt le lt ltgt uneq)
(define_operator_list inverted_tcc_comparison_with_nans
unge ungt ne eq unlt unle ordered unordered ge gt le lt ltgt uneq)
(define_operator_list swapped_tcc_comparison
gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt)
(define_operator_list simple_comparison lt le eq ne ge gt)
(define_operator_list swapped_simple_comparison gt ge eq ne le lt)
(define_operator_list BSWAP BUILT_IN_BSWAP16 BUILT_IN_BSWAP32
BUILT_IN_BSWAP64 BUILT_IN_BSWAP128)
#include "cfn-operators.pd"
/* Define operand lists for math rounding functions {,i,l,ll}FN,
where the versions prefixed with "i" return an int, those prefixed with
"l" return a long and those prefixed with "ll" return a long long.
Also define operand lists:
X<FN>F for all float functions, in the order i, l, ll
X<FN> for all double functions, in the same order
X<FN>L for all long double functions, in the same order. */
#define DEFINE_INT_AND_FLOAT_ROUND_FN(FN) \
(define_operator_list X##FN##F BUILT_IN_I##FN##F \
BUILT_IN_L##FN##F \
BUILT_IN_LL##FN##F) \
(define_operator_list X##FN BUILT_IN_I##FN \
BUILT_IN_L##FN \
BUILT_IN_LL##FN) \
(define_operator_list X##FN##L BUILT_IN_I##FN##L \
BUILT_IN_L##FN##L \
BUILT_IN_LL##FN##L)
DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
DEFINE_INT_AND_FLOAT_ROUND_FN (ROUND)
DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Unary operations and their associated IFN_COND_* function. */
(define_operator_list UNCOND_UNARY
negate bit_not)
(define_operator_list COND_UNARY
IFN_COND_NEG IFN_COND_NOT)
(define_operator_list COND_LEN_UNARY
IFN_COND_LEN_NEG IFN_COND_LEN_NOT)
/* Binary operations and their associated IFN_COND_* function. */
(define_operator_list UNCOND_BINARY
plus minus
mult trunc_div trunc_mod rdiv
min max
IFN_FMIN IFN_FMAX IFN_COPYSIGN
bit_and bit_ior bit_xor
lshift rshift)
(define_operator_list COND_BINARY
IFN_COND_ADD IFN_COND_SUB
IFN_COND_MUL IFN_COND_DIV IFN_COND_MOD IFN_COND_RDIV
IFN_COND_MIN IFN_COND_MAX
IFN_COND_FMIN IFN_COND_FMAX IFN_COND_COPYSIGN
IFN_COND_AND IFN_COND_IOR IFN_COND_XOR
IFN_COND_SHL IFN_COND_SHR)
(define_operator_list COND_LEN_BINARY
IFN_COND_LEN_ADD IFN_COND_LEN_SUB
IFN_COND_LEN_MUL IFN_COND_LEN_DIV
IFN_COND_LEN_MOD IFN_COND_LEN_RDIV
IFN_COND_LEN_MIN IFN_COND_LEN_MAX
IFN_COND_LEN_FMIN IFN_COND_LEN_FMAX IFN_COND_LEN_COPYSIGN
IFN_COND_LEN_AND IFN_COND_LEN_IOR IFN_COND_LEN_XOR
IFN_COND_LEN_SHL IFN_COND_LEN_SHR)
/* Same for ternary operations. */
(define_operator_list UNCOND_TERNARY
IFN_FMA IFN_FMS IFN_FNMA IFN_FNMS)
(define_operator_list COND_TERNARY
IFN_COND_FMA IFN_COND_FMS IFN_COND_FNMA IFN_COND_FNMS)
(define_operator_list COND_LEN_TERNARY
IFN_COND_LEN_FMA IFN_COND_LEN_FMS IFN_COND_LEN_FNMA IFN_COND_LEN_FNMS)
/* __atomic_fetch_or_*, __atomic_fetch_xor_*, __atomic_xor_fetch_* */
(define_operator_list ATOMIC_FETCH_OR_XOR_N
BUILT_IN_ATOMIC_FETCH_OR_1 BUILT_IN_ATOMIC_FETCH_OR_2
BUILT_IN_ATOMIC_FETCH_OR_4 BUILT_IN_ATOMIC_FETCH_OR_8
BUILT_IN_ATOMIC_FETCH_OR_16
BUILT_IN_ATOMIC_FETCH_XOR_1 BUILT_IN_ATOMIC_FETCH_XOR_2
BUILT_IN_ATOMIC_FETCH_XOR_4 BUILT_IN_ATOMIC_FETCH_XOR_8
BUILT_IN_ATOMIC_FETCH_XOR_16
BUILT_IN_ATOMIC_XOR_FETCH_1 BUILT_IN_ATOMIC_XOR_FETCH_2
BUILT_IN_ATOMIC_XOR_FETCH_4 BUILT_IN_ATOMIC_XOR_FETCH_8
BUILT_IN_ATOMIC_XOR_FETCH_16)
/* __sync_fetch_and_or_*, __sync_fetch_and_xor_*, __sync_xor_and_fetch_* */
(define_operator_list SYNC_FETCH_OR_XOR_N
BUILT_IN_SYNC_FETCH_AND_OR_1 BUILT_IN_SYNC_FETCH_AND_OR_2
BUILT_IN_SYNC_FETCH_AND_OR_4 BUILT_IN_SYNC_FETCH_AND_OR_8
BUILT_IN_SYNC_FETCH_AND_OR_16
BUILT_IN_SYNC_FETCH_AND_XOR_1 BUILT_IN_SYNC_FETCH_AND_XOR_2
BUILT_IN_SYNC_FETCH_AND_XOR_4 BUILT_IN_SYNC_FETCH_AND_XOR_8
BUILT_IN_SYNC_FETCH_AND_XOR_16
BUILT_IN_SYNC_XOR_AND_FETCH_1 BUILT_IN_SYNC_XOR_AND_FETCH_2
BUILT_IN_SYNC_XOR_AND_FETCH_4 BUILT_IN_SYNC_XOR_AND_FETCH_8
BUILT_IN_SYNC_XOR_AND_FETCH_16)
/* __atomic_fetch_and_*. */
(define_operator_list ATOMIC_FETCH_AND_N
BUILT_IN_ATOMIC_FETCH_AND_1 BUILT_IN_ATOMIC_FETCH_AND_2
BUILT_IN_ATOMIC_FETCH_AND_4 BUILT_IN_ATOMIC_FETCH_AND_8
BUILT_IN_ATOMIC_FETCH_AND_16)
/* __sync_fetch_and_and_*. */
(define_operator_list SYNC_FETCH_AND_AND_N
BUILT_IN_SYNC_FETCH_AND_AND_1 BUILT_IN_SYNC_FETCH_AND_AND_2
BUILT_IN_SYNC_FETCH_AND_AND_4 BUILT_IN_SYNC_FETCH_AND_AND_8
BUILT_IN_SYNC_FETCH_AND_AND_16)
/* With nop_convert? combine convert? and view_convert? in one pattern
plus conditionalize on tree_nop_conversion_p conversions. */
(match (nop_convert @0)
(convert @0)
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))))
(match (nop_convert @0)
(view_convert @0)
(if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@0))
&& known_eq (TYPE_VECTOR_SUBPARTS (type),
TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0)))
&& tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0))))))
/* These are used by gimple_bitwise_inverted_equal_p to simplify
detection of BIT_NOT and comparisons. */
(match (bit_not_with_nop @0)
(bit_not @0))
(match (bit_not_with_nop @0)
(convert (bit_not @0))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))))
(match (bit_xor_cst @0 @1)
(bit_xor @0 uniform_integer_cst_p@1))
(for cmp (tcc_comparison)
(match (maybe_cmp @0)
(cmp@0 @1 @2))
(match (maybe_cmp @0)
(convert (cmp@0 @1 @2))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))))
)
/* `a ^ b` is another form of `a != b` when the type
is a 1bit precission integer. */
(match (maybe_cmp @0)
(bit_xor@0 @1 @2)
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) == 1)))
/* maybe_bit_not is used to match what
is acceptable for bitwise_inverted_equal_p. */
(match (maybe_bit_not @0)
(bit_not_with_nop@0 @1))
(match (maybe_bit_not @0)
(INTEGER_CST@0))
(match (maybe_bit_not @0)
(maybe_cmp@0 @1))
(match (maybe_bit_not @0)
(bit_xor_cst@0 @1 @2))
#if GIMPLE
(match (maybe_truncate @0)
(convert @0)
(if (INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0)))))
#endif
/* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR <x>
ABSU_EXPR returns unsigned absolute value of the operand and the operand
of the ABSU_EXPR will have the corresponding signed type. */
(simplify (abs (convert @0))
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_UNSIGNED (TREE_TYPE (@0))
&& element_precision (type) > element_precision (TREE_TYPE (@0)))
(with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
(convert (absu:utype @0)))))
#if GIMPLE
/* Optimize (X + (X >> (prec - 1))) ^ (X >> (prec - 1)) into abs (X). */
(simplify
(bit_xor:c (plus:c @0 (rshift@2 @0 INTEGER_CST@1)) @2)
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_UNSIGNED (TREE_TYPE (@0))
&& wi::to_widest (@1) == element_precision (TREE_TYPE (@0)) - 1)
(abs @0)))
#endif
/* Simplifications of operations with one constant operand and
simplifications to constants or single values. */
(for op (plus pointer_plus minus bit_ior bit_xor)
(simplify
(op @0 integer_zerop)
(non_lvalue @0)))
/* 0 +p index -> (type)index */
(simplify
(pointer_plus integer_zerop @1)
(non_lvalue (convert @1)))
/* ptr - 0 -> (type)ptr */
(simplify
(pointer_diff @0 integer_zerop)
(convert @0))
/* See if ARG1 is zero and X + ARG1 reduces to X.
Likewise if the operands are reversed. */
(simplify
(plus:c @0 real_zerop@1)
(if (fold_real_zero_addition_p (type, @0, @1, 0))
(non_lvalue @0)))
/* See if ARG1 is zero and X - ARG1 reduces to X. */
(simplify
(minus @0 real_zerop@1)
(if (fold_real_zero_addition_p (type, @0, @1, 1))
(non_lvalue @0)))
/* Even if the fold_real_zero_addition_p can't simplify X + 0.0
into X, we can optimize (X + 0.0) + 0.0 or (X + 0.0) - 0.0
or (X - 0.0) + 0.0 into X + 0.0 and (X - 0.0) - 0.0 into X - 0.0
if not -frounding-math. For sNaNs the first operation would raise
exceptions but turn the result into qNan, so the second operation
would not raise it. */
(for inner_op (plus minus)
(for outer_op (plus minus)
(simplify
(outer_op (inner_op@3 @0 REAL_CST@1) REAL_CST@2)
(if (real_zerop (@1)
&& real_zerop (@2)
&& !HONOR_SIGN_DEPENDENT_ROUNDING (type))
(with { bool inner_plus = ((inner_op == PLUS_EXPR)
^ REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@1)));
bool outer_plus
= ((outer_op == PLUS_EXPR)
^ REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@2))); }
(if (outer_plus && !inner_plus)
(outer_op @0 @2)
@3))))))
/* Simplify x - x.
This is unsafe for certain floats even in non-IEEE formats.
In IEEE, it is unsafe because it does wrong for NaNs.
PR middle-end/98420: x - x may be -0.0 with FE_DOWNWARD.
Also note that operand_equal_p is always false if an operand
is volatile. */
(simplify
(minus @0 @0)
(if (!FLOAT_TYPE_P (type)
|| (!tree_expr_maybe_nan_p (@0)
&& !tree_expr_maybe_infinite_p (@0)
&& (!HONOR_SIGN_DEPENDENT_ROUNDING (type)
|| !HONOR_SIGNED_ZEROS (type))))
{ build_zero_cst (type); }))
(simplify
(pointer_diff @@0 @0)
{ build_zero_cst (type); })
(simplify
(mult @0 integer_zerop@1)
@1)
/* -x == x -> x == 0 */
(for cmp (eq ne)
(simplify
(cmp:c @0 (negate @0))
(if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_OVERFLOW_WRAPS (TREE_TYPE(@0)))
(cmp @0 { build_zero_cst (TREE_TYPE(@0)); }))))
/* Maybe fold x * 0 to 0. The expressions aren't the same
when x is NaN, since x * 0 is also NaN. Nor are they the
same in modes with signed zeros, since multiplying a
negative value by 0 gives -0, not +0. Nor when x is +-Inf,
since x * 0 is NaN. */
(simplify
(mult @0 real_zerop@1)
(if (!tree_expr_maybe_nan_p (@0)
&& (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0))
&& (!HONOR_SIGNED_ZEROS (type) || tree_expr_nonnegative_p (@0)))
@1))
/* In IEEE floating point, x*1 is not equivalent to x for snans.
Likewise for complex arithmetic with signed zeros. */
(simplify
(mult @0 real_onep)
(if (!tree_expr_maybe_signaling_nan_p (@0)
&& (!HONOR_SIGNED_ZEROS (type)
|| !COMPLEX_FLOAT_TYPE_P (type)))
(non_lvalue @0)))
/* Transform x * -1.0 into -x. */
(simplify
(mult @0 real_minus_onep)
(if (!tree_expr_maybe_signaling_nan_p (@0)
&& (!HONOR_SIGNED_ZEROS (type)
|| !COMPLEX_FLOAT_TYPE_P (type)))
(negate @0)))
/* Transform x * { 0 or 1, 0 or 1, ... } into x & { 0 or -1, 0 or -1, ...},
unless the target has native support for the former but not the latter. */
(simplify
(mult @0 VECTOR_CST@1)
(if (initializer_each_zero_or_onep (@1)
&& !HONOR_SNANS (type)
&& !HONOR_SIGNED_ZEROS (type))
(with { tree itype = FLOAT_TYPE_P (type) ? unsigned_type_for (type) : type; }
(if (itype
&& (!VECTOR_MODE_P (TYPE_MODE (type))
|| (VECTOR_MODE_P (TYPE_MODE (itype))
&& optab_handler (and_optab,
TYPE_MODE (itype)) != CODE_FOR_nothing)))
(view_convert (bit_and:itype (view_convert @0)
(ne @1 { build_zero_cst (type); })))))))
/* In SWAR (SIMD within a register) code a signed comparison of packed data
can be constructed with a particular combination of shift, bitwise and,
and multiplication by constants. If that code is vectorized we can
convert this pattern into a more efficient vector comparison. */
(simplify
(mult (bit_and (rshift @0 uniform_integer_cst_p@1)
uniform_integer_cst_p@2)
uniform_integer_cst_p@3)
(with {
tree rshift_cst = uniform_integer_cst_p (@1);
tree bit_and_cst = uniform_integer_cst_p (@2);
tree mult_cst = uniform_integer_cst_p (@3);
}
/* Make sure we're working with vectors and uniform vector constants. */
(if (VECTOR_TYPE_P (type)
&& tree_fits_uhwi_p (rshift_cst)
&& tree_fits_uhwi_p (mult_cst)
&& tree_fits_uhwi_p (bit_and_cst))
/* Compute what constants would be needed for this to represent a packed
comparison based on the shift amount denoted by RSHIFT_CST. */
(with {
HOST_WIDE_INT vec_elem_bits = vector_element_bits (type);
poly_int64 vec_nelts = TYPE_VECTOR_SUBPARTS (type);
poly_int64 vec_bits = vec_elem_bits * vec_nelts;
unsigned HOST_WIDE_INT cmp_bits_i, bit_and_i, mult_i;
unsigned HOST_WIDE_INT target_mult_i, target_bit_and_i;
cmp_bits_i = tree_to_uhwi (rshift_cst) + 1;
mult_i = tree_to_uhwi (mult_cst);
target_mult_i = (HOST_WIDE_INT_1U << cmp_bits_i) - 1;
bit_and_i = tree_to_uhwi (bit_and_cst);
target_bit_and_i = 0;
/* The bit pattern in BIT_AND_I should be a mask for the least
significant bit of each packed element that is CMP_BITS wide. */
for (unsigned i = 0; i < vec_elem_bits / cmp_bits_i; i++)
target_bit_and_i = (target_bit_and_i << cmp_bits_i) | 1U;
}
(if ((exact_log2 (cmp_bits_i)) >= 0
&& cmp_bits_i < HOST_BITS_PER_WIDE_INT
&& multiple_p (vec_bits, cmp_bits_i)
&& vec_elem_bits <= HOST_BITS_PER_WIDE_INT
&& target_mult_i == mult_i
&& target_bit_and_i == bit_and_i)
/* Compute the vector shape for the comparison and check if the target is
able to expand the comparison with that type. */
(with {
/* We're doing a signed comparison. */
tree cmp_type = build_nonstandard_integer_type (cmp_bits_i, 0);
poly_int64 vector_type_nelts = exact_div (vec_bits, cmp_bits_i);
tree vec_cmp_type = build_vector_type (cmp_type, vector_type_nelts);
tree vec_truth_type = truth_type_for (vec_cmp_type);
tree zeros = build_zero_cst (vec_cmp_type);
tree ones = build_all_ones_cst (vec_cmp_type);
}
(if (expand_vec_cmp_expr_p (vec_cmp_type, vec_truth_type, LT_EXPR)
&& expand_vec_cond_expr_p (vec_cmp_type, vec_truth_type, LT_EXPR))
(view_convert:type (vec_cond (lt:vec_truth_type
(view_convert:vec_cmp_type @0)
{ zeros; })
{ ones; } { zeros; })))))))))
(for cmp (gt ge lt le)
outp (convert convert negate negate)
outn (negate negate convert convert)
/* Transform X * (X > 0.0 ? 1.0 : -1.0) into abs(X). */
/* Transform X * (X >= 0.0 ? 1.0 : -1.0) into abs(X). */
/* Transform X * (X < 0.0 ? 1.0 : -1.0) into -abs(X). */
/* Transform X * (X <= 0.0 ? 1.0 : -1.0) into -abs(X). */
(simplify
(mult:c @0 (cond (cmp @0 real_zerop) real_onep@1 real_minus_onep))
(if (!tree_expr_maybe_nan_p (@0) && !HONOR_SIGNED_ZEROS (type))
(outp (abs @0))))
/* Transform X * (X > 0.0 ? -1.0 : 1.0) into -abs(X). */
/* Transform X * (X >= 0.0 ? -1.0 : 1.0) into -abs(X). */
/* Transform X * (X < 0.0 ? -1.0 : 1.0) into abs(X). */
/* Transform X * (X <= 0.0 ? -1.0 : 1.0) into abs(X). */
(simplify
(mult:c @0 (cond (cmp @0 real_zerop) real_minus_onep real_onep@1))
(if (!tree_expr_maybe_nan_p (@0) && !HONOR_SIGNED_ZEROS (type))
(outn (abs @0)))))
/* Transform X * copysign (1.0, X) into abs(X). */
(simplify
(mult:c @0 (COPYSIGN_ALL real_onep @0))
(if (!tree_expr_maybe_nan_p (@0) && !HONOR_SIGNED_ZEROS (type))
(abs @0)))
/* Transform X * copysign (1.0, -X) into -abs(X). */
(simplify
(mult:c @0 (COPYSIGN_ALL real_onep (negate @0)))
(if (!tree_expr_maybe_nan_p (@0) && !HONOR_SIGNED_ZEROS (type))
(negate (abs @0))))
/* Transform copysign (CST, X) into copysign (ABS(CST), X). */
(simplify
(COPYSIGN_ALL REAL_CST@0 @1)
(if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@0)))
(COPYSIGN_ALL (negate @0) @1)))
/* Transform c ? x * copysign (1, y) : z to c ? x ^ signs(y) : z.
tree-ssa-math-opts.cc does the corresponding optimization for
unconditional multiplications (via xorsign). */
(simplify
(IFN_COND_MUL:c @0 @1 (IFN_COPYSIGN real_onep @2) @3)
(with { tree signs = sign_mask_for (type); }
(if (signs)
(with { tree inttype = TREE_TYPE (signs); }
(view_convert:type
(IFN_COND_XOR:inttype @0
(view_convert:inttype @1)
(bit_and (view_convert:inttype @2) { signs; })
(view_convert:inttype @3)))))))
/* (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) -> abs x. */
(simplify
(plus:c (max @0 integer_zerop) (max (negate @0) integer_zerop))
(if (ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_UNDEFINED (type))
(abs @0)))
/* X * 1, X / 1 -> X. */
(for op (mult trunc_div ceil_div floor_div round_div exact_div)
(simplify
(op @0 integer_onep)
(non_lvalue @0)))
/* (A / (1 << B)) -> (A >> B).
Only for unsigned A. For signed A, this would not preserve rounding
toward zero.
For example: (-1 / ( 1 << B)) != -1 >> B.
Also handle widening conversions, like:
(A / (unsigned long long) (1U << B)) -> (A >> B)
or
(A / (unsigned long long) (1 << B)) -> (A >> B).
If the left shift is signed, it can be done only if the upper bits
of A starting from shift's type sign bit are zero, as
(unsigned long long) (1 << 31) is -2147483648ULL, not 2147483648ULL,
so it is valid only if A >> 31 is zero. */
(simplify
(trunc_div (convert?@0 @3) (convert2? (lshift integer_onep@1 @2)))
(if ((TYPE_UNSIGNED (type) || tree_expr_nonnegative_p (@0))
&& (!VECTOR_TYPE_P (type)
|| target_supports_op_p (type, RSHIFT_EXPR, optab_vector)
|| target_supports_op_p (type, RSHIFT_EXPR, optab_scalar))
&& (useless_type_conversion_p (type, TREE_TYPE (@1))
|| (element_precision (type) >= element_precision (TREE_TYPE (@1))
&& (TYPE_UNSIGNED (TREE_TYPE (@1))
|| (element_precision (type)
== element_precision (TREE_TYPE (@1)))
|| (INTEGRAL_TYPE_P (type)
&& (tree_nonzero_bits (@0)
& wi::mask (element_precision (TREE_TYPE (@1)) - 1,
true,
element_precision (type))) == 0)))))
(if (!VECTOR_TYPE_P (type)
&& useless_type_conversion_p (TREE_TYPE (@3), TREE_TYPE (@1))
&& element_precision (TREE_TYPE (@3)) < element_precision (type))
(convert