summaryrefslogtreecommitdiffstats
path: root/recipes-devtools/gcc/files/gcc.builtin_isel.patch
blob: 10e59999b90598a30124cb97577222dd9f5d9b40 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
diff -ruN gcc-4.6.0-orig/gcc/config/rs6000/rs6000-builtin.def gcc-4.6.0-new/gcc/config/rs6000/rs6000-builtin.def
--- gcc-4.6.0-orig/gcc/config/rs6000/rs6000-builtin.def	2011-02-21 15:38:21.000000000 -0600
+++ gcc-4.6.0-new/gcc/config/rs6000/rs6000-builtin.def	2011-07-25 12:32:26.626006000 -0500
@@ -750,6 +750,71 @@
 RS6000_BUILTIN(SPE_BUILTIN_MFSPEFSCR,			RS6000_BTC_MISC)
 RS6000_BUILTIN(SPE_BUILTIN_BRINC,			RS6000_BTC_MISC)
 
+/* ISEL builtins.  */
+/* Generic versions that get resolved to specific builtins.  */
+RS6000_BUILTIN(RS6000_BUILTIN_ISELEQ,                  RS6000_BTC_PURE)
+RS6000_BUILTIN_EQUATE(ISEL_BUILTIN_OVERLOADED_FIRST,
+                     RS6000_BUILTIN_ISELEQ)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELGT,                  RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELLT,                  RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELGTU,                 RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELLTU,                 RS6000_BTC_PURE)
+/* Same deal, but for 64-bit comparisons.  */
+RS6000_BUILTIN(RS6000_BUILTIN_ISELEQD,                 RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELGTD,                 RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELLTD,                 RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELGTDU,                        RS6000_BTC_PURE)
+RS6000_BUILTIN(RS6000_BUILTIN_ISELLTDU,                        RS6000_BTC_PURE)
+RS6000_BUILTIN_EQUATE(ISEL_BUILTIN_OVERLOADED_LAST,
+                     RS6000_BUILTIN_ISELLTDU)
+
+/* Each set of arguments is polymorphic in selected arguments and return
+   value.  */
+#undef RS6000_ISEL_BASE
+#define RS6000_ISEL_BASE(ARG, PRED, CMP)                                       \
+  RS6000_BUILTIN(RS6000_BUILTIN_ISEL_##PRED##CMP##_##ARG##_SS, RS6000_BTC_PURE) \
+  RS6000_BUILTIN(RS6000_BUILTIN_ISEL_##PRED##CMP##_##ARG##_PP, RS6000_BTC_PURE) \
+  RS6000_BUILTIN(RS6000_BUILTIN_ISEL_##PRED##CMP##_##ARG##_UU, RS6000_BTC_PURE)
+#undef RS6000_ISEL_PTR_ARG
+#define RS6000_ISEL_PTR_ARG(PRED, CMP) RS6000_ISEL_BASE(PP, PRED, CMP)
+#undef RS6000_ISEL_SIGNED_ARG
+#define RS6000_ISEL_SIGNED_ARG(PRED, CMP) RS6000_ISEL_BASE(SS, PRED, CMP)
+#undef RS6000_ISEL_UNSIGNED_ARG
+#define RS6000_ISEL_UNSIGNED_ARG(PRED, CMP) RS6000_ISEL_BASE(UU, PRED, CMP)
+
+#undef RS6000_ISEL_EQ
+#define RS6000_ISEL_EQ(CMP)                    \
+  RS6000_ISEL_PTR_ARG(EQ, CMP)                 \
+  RS6000_ISEL_SIGNED_ARG(EQ, CMP)              \
+  RS6000_ISEL_UNSIGNED_ARG(EQ, CMP)
+
+#undef RS6000_ISEL_LT
+#define RS6000_ISEL_LT(CMP) RS6000_ISEL_SIGNED_ARG(LT, CMP)
+
+#undef RS6000_ISEL_GT
+#define RS6000_ISEL_GT(CMP) RS6000_ISEL_SIGNED_ARG(GT, CMP)
+
+#undef RS6000_ISEL_LTU
+#define RS6000_ISEL_LTU(CMP)                   \
+  RS6000_ISEL_PTR_ARG(LTU, CMP)                        \
+  RS6000_ISEL_UNSIGNED_ARG(LTU, CMP)
+
+#undef RS6000_ISEL_GTU
+#define RS6000_ISEL_GTU(CMP)                   \
+  RS6000_ISEL_PTR_ARG(GTU, CMP)                        \
+  RS6000_ISEL_UNSIGNED_ARG(GTU, CMP)
+
+RS6000_ISEL_EQ(CMPW)
+RS6000_ISEL_LT(CMPW)
+RS6000_ISEL_GT(CMPW)
+RS6000_ISEL_LTU(CMPW)
+RS6000_ISEL_GTU(CMPW)
+RS6000_ISEL_EQ(CMPD)
+RS6000_ISEL_LT(CMPD)
+RS6000_ISEL_GT(CMPD)
+RS6000_ISEL_LTU(CMPD)
+RS6000_ISEL_GTU(CMPD)
+
 /* PAIRED builtins.  */
 RS6000_BUILTIN(PAIRED_BUILTIN_DIVV2SF3,			RS6000_BTC_MISC)
 RS6000_BUILTIN(PAIRED_BUILTIN_ABSV2SF2,			RS6000_BTC_MISC)
diff -ruN gcc-4.6.0-orig/gcc/config/rs6000/rs6000.c gcc-4.6.0-new/gcc/config/rs6000/rs6000.c
--- gcc-4.6.0-orig/gcc/config/rs6000/rs6000.c	2011-03-15 07:57:37.000000000 -0500
+++ gcc-4.6.0-new/gcc/config/rs6000/rs6000.c	2011-07-25 13:19:52.415921000 -0500
@@ -12402,6 +12402,289 @@
   return target;
 }
 
+/* isel builtins are a bit funny, because we want the user to be able to do:
+
+   char *p, *q, *r;
+   int x, y, z;
+   unsigned int a, b, c;
+   ...
+   p = __builtin_iseleq (i, j, q, r);
+   x = __builtin_iseleq (i, j, y, z);
+   a = __builtin_iseleq (i, j, b, c);
+
+   and, of course, i and j may be of several different types depending on the
+   condition.
+
+   We handle this by having generic builtins that
+   TARGET_RESOLVE_OVERLOADED_BUILTIN takes and turns into calls to our
+   specific builtins.  */
+
+/* Macros to help constructing the isel_builtin_desc arrays.
+   These closely mirror the macros in rs6000-builtins.def.  */
+/* HACK: Use VOIDmode here as a constant approximation to Pmode and fix
+   at runtime.  We can't use Pmode because in biarch its definition is
+   not constant.  */
+#define ISEL_Pmode VOIDmode
+#define ISEL_BASE(FLAGS, ARG, RESULT, PRED, CMP, MODE, RMODE)          \
+  { NULL, FLAGS, RS6000_BUILTIN_ISEL_##PRED##CMP##_##ARG##_##RESULT,   \
+      PRED, MODE, RMODE },
+#define ISEL_P_RESULT(FLAGS, ARG, PRED, CMP, MODE, RMODE)              \
+  ISEL_BASE (FLAGS | ISEL_FLAG_SEL_PTR, ARG, PP, PRED,         \
+            CMP, MODE, ISEL_Pmode)
+#define ISEL_S_RESULT(FLAGS, ARG, PRED, CMP, MODE, RMODE)              \
+  ISEL_BASE (FLAGS | ISEL_FLAG_SEL_SIGNED, ARG, SS, PRED,              \
+            CMP, MODE, RMODE)
+#define ISEL_U_RESULT(FLAGS, ARG, PRED, CMP, MODE, RMODE)              \
+  ISEL_BASE (FLAGS | ISEL_FLAG_SEL_UNSIGNED, ARG, UU, PRED,            \
+            CMP, MODE, RMODE)
+
+#define ISEL_EXPAND_ARG(FLAG, ARG, PRED, CMP, MODE, RMODE)             \
+  ISEL_P_RESULT (FLAG, ARG, PRED, CMP, MODE, RMODE)            \
+  ISEL_S_RESULT (FLAG, ARG, PRED, CMP, MODE, RMODE)            \
+  ISEL_U_RESULT (FLAG, ARG, PRED, CMP, MODE, RMODE)
+#define ISEL_PTR_ARG(PRED, CMP, MODE)                          \
+  ISEL_EXPAND_ARG (ISEL_FLAG_CMP_PTR, PP, PRED, CMP, ISEL_Pmode, MODE)
+#define ISEL_SIGNED_ARG(PRED, CMP, MODE)                       \
+  ISEL_EXPAND_ARG (ISEL_FLAG_CMP_SIGNED, SS, PRED, CMP, MODE, MODE)
+#define ISEL_UNSIGNED_ARG(PRED, CMP, MODE)                     \
+  ISEL_EXPAND_ARG (ISEL_FLAG_CMP_UNSIGNED, UU, PRED, CMP, MODE, MODE)
+
+#define ISEL_EQ(CMP, MODE)                                     \
+  ISEL_PTR_ARG (EQ, CMP, MODE)                                 \
+  ISEL_SIGNED_ARG (EQ, CMP, MODE)                              \
+  ISEL_UNSIGNED_ARG (EQ, CMP, MODE)
+#define ISEL_LT(CMP, MODE) ISEL_SIGNED_ARG (LT, CMP, MODE)
+#define ISEL_GT(CMP, MODE) ISEL_SIGNED_ARG (GT, CMP, MODE)
+#define ISEL_LTU(CMP, MODE)                                    \
+  ISEL_PTR_ARG (LTU, CMP, MODE)                                        \
+  ISEL_UNSIGNED_ARG (LTU, CMP, MODE)
+#define ISEL_GTU(CMP, MODE)                                    \
+  ISEL_PTR_ARG (GTU, CMP, MODE)                                        \
+  ISEL_UNSIGNED_ARG (GTU, CMP, MODE)
+
+const struct isel_builtin_desc builtin_iselw[32] = {
+  ISEL_EQ (CMPW, SImode)
+  ISEL_LT (CMPW, SImode)
+  ISEL_GT (CMPW, SImode)
+  ISEL_LTU (CMPW, SImode)
+  ISEL_GTU (CMPW, SImode)
+  { "__builtin_iseleq", 0, RS6000_BUILTIN_ISELEQ, EQ, SImode, SImode },
+  { "__builtin_isellt", 0, RS6000_BUILTIN_ISELLT, LT, SImode, SImode },
+  { "__builtin_iselgt", 0, RS6000_BUILTIN_ISELGT, GT, SImode, SImode },
+  { "__builtin_iselltu", 0, RS6000_BUILTIN_ISELLTU, LTU, SImode, SImode },
+  { "__builtin_iselgtu", 0, RS6000_BUILTIN_ISELGTU, GTU, SImode, SImode }
+};
+
+const struct isel_builtin_desc builtin_iseld[32] = {
+  ISEL_EQ (CMPD, DImode)
+  ISEL_LT (CMPD, DImode)
+  ISEL_GT (CMPD, DImode)
+  ISEL_LTU (CMPD, DImode)
+  ISEL_GTU (CMPD, DImode)
+  { "__builtin_isel64eq", 0, RS6000_BUILTIN_ISELEQD, EQ, DImode, DImode },
+  { "__builtin_isel64lt", 0, RS6000_BUILTIN_ISELLTD, LT, DImode, DImode },
+  { "__builtin_isel64gt", 0, RS6000_BUILTIN_ISELGTD, GT, DImode, DImode },
+  { "__builtin_isel64ltu", 0, RS6000_BUILTIN_ISELLTDU, LTU, DImode, DImode },
+  { "__builtin_isel64gtu", 0, RS6000_BUILTIN_ISELGTDU, GTU, DImode, DImode }
+};
+
+/* Return the mode which DESC uses for comparisons.  */
+
+static enum machine_mode
+isel_cmp_mode (const struct isel_builtin_desc *desc)
+{
+  enum machine_mode mode = (enum machine_mode) desc->cmp_mode;
+
+  return (mode == VOIDmode ? Pmode : mode);
+}
+
+/* Return the mode in which DESC selects arguments.  */
+
+static enum machine_mode
+isel_sel_mode (const struct isel_builtin_desc *desc)
+{
+  enum machine_mode mode = (enum machine_mode) desc->sel_mode;
+
+  return (mode == VOIDmode ? Pmode : mode);
+}
+
+/* Return a tree describing the arguments for DESC according to CMPP:
+   true for comparison arguments, false for select arguments.  */
+
+static tree
+isel_argtype (const struct isel_builtin_desc *desc, bool cmpp)
+{
+  switch (desc->arg_flags & (cmpp
+                            ? ISEL_FLAG_CMP_MASK
+                            : ISEL_FLAG_SEL_MASK))
+    {
+    case ISEL_FLAG_CMP_PTR:
+    case ISEL_FLAG_SEL_PTR:
+      return ptr_type_node;
+    case ISEL_FLAG_CMP_SIGNED:
+      return (isel_cmp_mode (desc) == SImode
+             ? integer_type_node
+             : long_integer_type_node);
+    case ISEL_FLAG_SEL_SIGNED:
+      return (isel_sel_mode (desc) == SImode
+             ? integer_type_node
+             : long_integer_type_node);
+    case ISEL_FLAG_CMP_UNSIGNED:
+      return (isel_cmp_mode (desc) == SImode
+             ? unsigned_type_node
+             : long_unsigned_type_node);
+    case ISEL_FLAG_SEL_UNSIGNED:
+    default:
+      return (isel_sel_mode (desc) == SImode
+             ? unsigned_type_node
+             : long_unsigned_type_node);
+    }
+}
+
+/* Return a mnemonic string describing the argument or result of FLAGS
+   depending on CMPP.  */
+
+static const char *
+isel_strdesc (int flags, bool cmpp)
+{
+  switch (flags & (cmpp ? ISEL_FLAG_CMP_MASK : ISEL_FLAG_SEL_MASK))
+    {
+    case ISEL_FLAG_CMP_PTR:
+    case ISEL_FLAG_SEL_PTR:
+      return "p";
+    case ISEL_FLAG_CMP_SIGNED:
+    case ISEL_FLAG_SEL_SIGNED:
+      return "s";
+    case ISEL_FLAG_CMP_UNSIGNED:
+    case ISEL_FLAG_SEL_UNSIGNED:
+      return "u";
+    default:
+      gcc_unreachable ();
+    }
+}
+
+/* Initialize N_DESC isel builtins from DESC.  SIGNED_TYPE holds the
+   basic type for signed variants of isel, UNSIGNED_TYPE the type for
+   unsigned variants.  */
+
+static void
+rs6000_init_isel_builtins (const struct isel_builtin_desc *desc, int n_descs)
+{
+  int i;
+  const char *is64 = (desc == &builtin_iselw[0] ? "32" : "64");
+
+  for (i = 0; i < n_descs; i++)
+    {
+      const struct isel_builtin_desc *d = &desc[i];
+      tree cmptype, seltype, ftype;
+
+      cmptype = isel_argtype (d, true);
+      seltype = isel_argtype (d, false);
+
+      ftype = build_function_type_list (seltype, cmptype, cmptype,
+                                       seltype, seltype, NULL_TREE);
+
+      if (d->name)
+       def_builtin (MASK_ISEL, d->name, ftype, d->code);
+      else
+       {
+         char builtin_name[40];
+
+         sprintf (builtin_name, "__builtin_isel%s%s%s%s%s%s",
+                  is64,
+                  GET_RTX_NAME (d->cmp_code),
+                  GET_MODE_NAME (isel_cmp_mode (d)),
+                  isel_strdesc (d->arg_flags, true),
+                  isel_strdesc (d->arg_flags, false),
+                  GET_MODE_NAME (isel_sel_mode (d)));
+
+         def_builtin (MASK_ISEL, ggc_strdup (builtin_name), ftype, d->code);
+       }
+    }
+}
+
+static rtx
+rs6000_expand_isel_builtin (const struct isel_builtin_desc *desc,
+                           int n_descs, tree exp, rtx target, int fcode)
+{
+  int i;
+
+  for (i = 0; i < n_descs; i++)
+    {
+      const struct isel_builtin_desc *d = &desc[i];
+
+      if (fcode == (int) d->code)
+       {
+         int opidx;
+         unsigned int j;
+         rtx cmp;
+         rtx operands[4];
+         enum insn_code icode;
+         enum machine_mode opmode;
+         enum machine_mode cmpmode = isel_cmp_mode (d);
+         enum machine_mode selmode = isel_sel_mode (d);
+
+         /* Determine underlying isel insn.  */
+         switch (d->cmp_code)
+           {
+           case GTU:
+           case LTU:
+             icode = (Pmode == SImode
+                      ? CODE_FOR_isel_unsigned_si
+                      : CODE_FOR_isel_unsigned_di);
+             break;
+           default:
+             icode = (Pmode == SImode
+                      ? CODE_FOR_isel_signed_si
+                      : CODE_FOR_isel_signed_di);
+             break;
+           }
+
+         for (j = 0; j < ARRAY_SIZE (operands); j++)
+           {
+             tree arg = CALL_EXPR_ARG (exp, j);
+
+             /* If we got invalid arguments, bail out before generating
+                bad rtl.  */
+             if (arg == error_mark_node)
+               return const0_rtx;
+
+             operands[j] = expand_normal (arg);
+
+             /* Validate.  */
+             /* HACK: The isel pattern doesn't actually consume all the
+                operands to the builtin; it only consumes 2 and 3.  The
+                other two will be handed off to a compare
+                insn. Unfortunately, said insn is not named, so we
+                can't directly access its insn_data here.  Fake it by
+                validating operands 0 and 1 with the isel pattern; that
+                should be good enough.  */
+             opidx = (j < 2 ? 2 : j);
+             opmode = (j < 2 ? cmpmode : selmode);
+             if (! (*insn_data[icode].operand[opidx].predicate) (operands[j],
+                                                                 opmode))
+               operands[j] = copy_to_mode_reg (opmode, operands[j]);
+           }
+
+         /* Validate target.  */
+         if (target == NULL_RTX
+             || GET_MODE (target) != selmode
+             || ! (*insn_data[icode].operand[0].predicate) (target, selmode))
+           target = gen_reg_rtx (selmode);
+
+         /* Generate comparison.  */
+         cmp = gen_rtx_fmt_ee ((enum rtx_code)d->cmp_code, cmpmode,
+                               operands[0], operands[1]);
+
+         rs6000_emit_int_cmove (target, cmp, operands[2], operands[3]);
+
+         return target;
+       }
+    }
+
+  return NULL_RTX;
+}
+
 /* Expand an expression EXP that calls a built-in function,
    with result going to TARGET if that's convenient
    (and in mode MODE if that's convenient).
@@ -12520,6 +12803,24 @@
       if (success)
 	return ret;
     }  
+  if (TARGET_ISEL)
+    {
+      ret = rs6000_expand_isel_builtin (builtin_iselw,
+                                       ARRAY_SIZE (builtin_iselw),
+                                       exp, target, fcode);
+
+      if (ret != NULL_RTX)
+       return ret;
+    }
+  if (TARGET_ISEL64)
+    {
+      ret = rs6000_expand_isel_builtin (builtin_iseld,
+                                       ARRAY_SIZE (builtin_iseld),
+                                       exp, target, fcode);
+
+      if (ret != NULL_RTX)
+       return ret;
+    }
 
   gcc_assert (TARGET_ALTIVEC || TARGET_VSX || TARGET_SPE || TARGET_PAIRED_FLOAT);
 
@@ -12738,6 +13039,10 @@
     spe_init_builtins ();
   if (TARGET_ALTIVEC)
     altivec_init_builtins ();
+  if (TARGET_ISEL)
+    rs6000_init_isel_builtins (builtin_iselw, ARRAY_SIZE (builtin_iselw));
+  if (TARGET_ISEL64)
+    rs6000_init_isel_builtins (builtin_iseld, ARRAY_SIZE (builtin_iseld));
   if (TARGET_ALTIVEC || TARGET_SPE || TARGET_PAIRED_FLOAT || TARGET_VSX)
     rs6000_common_init_builtins ();
   if (TARGET_FRE)
diff -ruN gcc-4.6.0-orig/gcc/config/rs6000/rs6000-c.c gcc-4.6.0-new/gcc/config/rs6000/rs6000-c.c
--- gcc-4.6.0-orig/gcc/config/rs6000/rs6000-c.c	2011-02-02 23:42:19.000000000 -0600
+++ gcc-4.6.0-new/gcc/config/rs6000/rs6000-c.c	2011-07-25 16:07:14.616209000 -0500
@@ -3439,7 +3439,7 @@
 /* Implementation of the resolve_overloaded_builtin target hook, to
    support Altivec's overloaded builtins.  */
 
-tree
+static tree
 altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
 				    void *passed_arglist)
 {
@@ -3770,3 +3770,148 @@
   error ("invalid parameter combination for AltiVec intrinsic");
   return error_mark_node;
 }
+
+/* Return true if the pair of arguments in ARGS is acceptable according
+   to DECLTYPES and FLAGS.  CMPP determines whether this is for the
+   comparison arguments.  */
+
+static bool
+isel_arguments_valid (tree *args, tree *decltypes, int flags, bool cmpp)
+{
+  tree type0 = TREE_TYPE (args[0]);
+  tree type1 = TREE_TYPE (args[1]);
+  tree decltype0 = decltypes[0];
+  tree decltype1 = decltypes[1];
+
+  switch (flags & (cmpp ? ISEL_FLAG_CMP_MASK : ISEL_FLAG_SEL_MASK))
+    {
+      /* For pointer arguments and results, we just need to make sure
+        we're receiving pointers, and they can be freely converted to
+        and from void *.  For pointer results, we also need to ensure
+        that the types of the passed arguments are compatible: this is
+        similar to what the ?: construct would need to ensure.  */
+    case ISEL_FLAG_CMP_PTR:
+    case ISEL_FLAG_SEL_PTR:
+      {
+       /* Results compatible with each other?  */
+       if (!lang_hooks.types_compatible_p (type0, type1))
+         return false;
+
+       return (POINTER_TYPE_P (type0)
+               && POINTER_TYPE_P (type1));
+      }
+      break;
+      /* For signed and unsigned arguments and results, we just need to
+        make sure that the argument types are compatible with the
+        declared types; we can insert conversions to make everything
+        match up.  */
+    case ISEL_FLAG_CMP_SIGNED:
+    case ISEL_FLAG_SEL_SIGNED:
+    case ISEL_FLAG_CMP_UNSIGNED:
+    case ISEL_FLAG_SEL_UNSIGNED:
+      return (lang_hooks.types_compatible_p (type0, decltype0)
+             && lang_hooks.types_compatible_p (type1, decltype1));
+    default:
+      ;
+    }
+
+  gcc_unreachable ();
+}
+
+/* Determine if FNDECL is a generic isel intrinsic and if it can be
+   resolved to a non-generic version with a proper type using the
+   descriptions found in DESC.  Return a call to the non-generic builtin
+   if so.  */
+
+static tree
+rs6000_resolve_isel_builtin (location_t loc, tree fndecl,
+                            void *passed_arglist,
+                            const struct isel_builtin_desc *desc,
+                            int n_descs)
+{
+  VEC(tree,gc) *arglist = (VEC(tree,gc) *) passed_arglist;
+  unsigned int nargs = VEC_length (tree, arglist);
+  int i;
+  unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
+  const struct isel_builtin_desc *generic = NULL;
+
+  /* Is this even a builtin we care about?  */
+  if (fcode < ISEL_BUILTIN_OVERLOADED_FIRST
+      || fcode > ISEL_BUILTIN_OVERLOADED_LAST)
+    return NULL_TREE;
+
+  if (nargs != 4)
+    {
+      error ("isel intrinsics only accept 4 arguments");
+      return error_mark_node;
+    }
+
+  /* Find the generic builtin we're resolving.  */
+  for (i = 0; i < n_descs; i++)
+    if (desc[i].code == fcode)
+      {
+       generic = &desc[i];
+       break;
+      }
+
+  /* Happens if we're looking for a 64-bit builtin in the 32-bit
+     descriptors.  */
+  if (generic == NULL)
+    return NULL_TREE;
+
+  /* Try all the builtins whose comparison matches the generic one.  */
+  for (i = 0; i < n_descs; i++)
+    {
+      const struct isel_builtin_desc *d = &desc[i];
+      int j;
+      tree *argp = VEC_address (tree, arglist);
+      tree impl_fndecl;
+      tree decltypes[4], t;
+      tree converted_args[4];
+
+      if (d == generic || d->cmp_code != generic->cmp_code)
+       continue;
+
+      impl_fndecl = rs6000_builtin_decls[d->code];
+      t = TYPE_ARG_TYPES (TREE_TYPE (impl_fndecl));
+      for (j = 0 ; t != void_list_node; j++, t = TREE_CHAIN (t))
+       decltypes[j] = TREE_VALUE (t);
+
+      if (!isel_arguments_valid (argp, decltypes, d->arg_flags, true)
+         || !isel_arguments_valid (argp+2, decltypes+2, d->arg_flags, false))
+       continue;
+
+      /* We got here, we're ok.  Build a new, resolved CALL_EXPR.  */
+      for (j = 0; j < 4; j++)
+       converted_args[j] = fold_convert (decltypes[j], argp[j]);
+
+      return build_call_expr_loc (loc, impl_fndecl, 4,
+                                 converted_args[0], converted_args[1],
+                                 converted_args[2], converted_args[3]);
+    }
+
+  error ("invalid parameter combination for isel intrinsic");
+  return error_mark_node;
+}
+
+tree
+rs6000_resolve_overloaded_builtin (location_t loc, tree fndecl, void *arglist)
+{
+  tree t;
+
+  t = altivec_resolve_overloaded_builtin (loc, fndecl, arglist);
+  if (t)
+    return t;
+
+  t = rs6000_resolve_isel_builtin (loc, fndecl, arglist,
+                                  builtin_iselw, ARRAY_SIZE (builtin_iselw));
+  if (t)
+    return t;
+
+  t = rs6000_resolve_isel_builtin (loc, fndecl, arglist,
+                                  builtin_iseld, ARRAY_SIZE (builtin_iseld));
+  if (t)
+    return t;
+
+  return NULL_TREE;
+}
diff -ruN gcc-4.6.0-orig/gcc/config/rs6000/rs6000.h gcc-4.6.0-new/gcc/config/rs6000/rs6000.h
--- gcc-4.6.0-orig/gcc/config/rs6000/rs6000.h	2011-03-07 13:27:09.000000000 -0600
+++ gcc-4.6.0-new/gcc/config/rs6000/rs6000.h	2011-07-25 16:07:04.045105000 -0500
@@ -535,7 +535,7 @@
 #define REGISTER_TARGET_PRAGMAS() do {				\
   c_register_pragma (0, "longcall", rs6000_pragma_longcall);	\
   targetm.target_option.pragma_parse = rs6000_pragma_target_parse; \
-  targetm.resolve_overloaded_builtin = altivec_resolve_overloaded_builtin; \
+  targetm.resolve_overloaded_builtin = rs6000_resolve_overloaded_builtin; \
 } while (0)
 
 /* Target #defines.  */
@@ -2446,3 +2446,41 @@
 extern GTY(()) tree rs6000_builtin_types[RS6000_BTI_MAX];
 extern GTY(()) tree rs6000_builtin_decls[RS6000_BUILTIN_COUNT];
 
+/* Values for struct isel_builtin_desc.arg_flags.  */
+enum {
+  ISEL_FLAG_CMP_PTR = 0x1,
+  ISEL_FLAG_CMP_SIGNED = 0x2,
+  ISEL_FLAG_CMP_UNSIGNED = 0x4,
+  ISEL_FLAG_CMP_MASK = 0x7,
+  ISEL_FLAG_SEL_PTR = 0x10,
+  ISEL_FLAG_SEL_SIGNED = 0x20,
+  ISEL_FLAG_SEL_UNSIGNED = 0x40,
+  ISEL_FLAG_SEL_MASK = 0x70
+};
+
+struct isel_builtin_desc {
+  /* Name of this builtin.  NULL if we should construct it.  */
+  const char *name;
+
+  /* Flags for argument combinations accepted by the builtin.
+     Zero if this builtin is a generic builtin, to be resolved later.  */
+  int arg_flags;
+
+  /* The code of the builtin.  */
+  enum rs6000_builtins code;
+
+  /* rtx_code and machine_mode are not available here; use ints instead.  */
+  /* The comparison code the builtin uses.  */
+  int cmp_code;
+
+  /* The mode the builtin does comparisons in.  */
+  int cmp_mode;
+
+  /* The mode the builtin's selected arguments are in.
+     Also happens to be its result mode.  */
+  int sel_mode;
+};
+
+/* Arrays describing isel builtins.  */
+extern const struct isel_builtin_desc builtin_iselw[32];
+extern const struct isel_builtin_desc builtin_iseld[32];
diff -ruN gcc-4.6.0-orig/gcc/config/rs6000/rs6000-protos.h gcc-4.6.0-new/gcc/config/rs6000/rs6000-protos.h
--- gcc-4.6.0-orig/gcc/config/rs6000/rs6000-protos.h	2011-03-15 07:57:37.000000000 -0500
+++ gcc-4.6.0-new/gcc/config/rs6000/rs6000-protos.h	2011-07-25 16:07:50.484773000 -0500
@@ -142,7 +142,7 @@
 						     unsigned int);
 extern unsigned int darwin_rs6000_special_round_type_align (tree, unsigned int,
 							    unsigned int);
-extern tree altivec_resolve_overloaded_builtin (location_t, tree, void *);
+extern tree rs6000_resolve_overloaded_builtin (location_t, tree, void *);
 extern rtx rs6000_libcall_value (enum machine_mode);
 extern rtx rs6000_va_arg (tree, tree);
 extern int function_ok_for_sibcall (tree);
diff -ruN gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel64.c gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel64.c
--- gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel64.c	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel64.c	2011-07-25 12:27:55.343932000 -0500
@@ -0,0 +1,75 @@
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-options "-mcpu=e500mc64" } */
+
+#include "builtin-isel.h"
+
+/* Equality comparisons.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64eq
+
+SIGNED64_PROTO
+{
+  L = ISEL_BUILTIN (x, y, a, b);
+  U = ISEL_BUILTIN (x, y, (unsigned long) a, (unsigned long) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  L = ISEL_BUILTIN (p, q, a, b);
+  /* Equality checks explicitly permit unsigned comparison operands.  */
+  L = ISEL_BUILTIN ((unsigned long) x, (unsigned long) y, a, b);
+  r = ISEL_BUILTIN ((unsigned long) x, (unsigned long) y, p, q);
+}
+
+/* less-than, greater-than.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64lt
+
+SIGNED64_PROTO
+{
+  L = ISEL_BUILTIN (x, y, a, b);
+  U = ISEL_BUILTIN (x, y, (unsigned long) a, (unsigned long) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64gt
+
+SIGNED64_PROTO
+{
+  L = ISEL_BUILTIN (x, y, a, b);
+  U = ISEL_BUILTIN (x, y, (unsigned long) a, (unsigned long) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+}
+
+/* Unsigned variants.  These permit unsigned and pointer operands for
+   comparison only.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64ltu
+
+UNSIGNED64_PROTO
+{
+  L = ISEL_BUILTIN (x, y, a, b);
+  U = ISEL_BUILTIN (x, y, (unsigned long) a, (unsigned long) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  L = ISEL_BUILTIN (p, q, a, b);
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64gtu
+
+UNSIGNED64_PROTO
+{
+  L = ISEL_BUILTIN (x, y, a, b);
+  U = ISEL_BUILTIN (x, y, (unsigned long) a, (unsigned long) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  L = ISEL_BUILTIN (p, q, a, b);
+}
+
+/* Don't use bare isel, as that'll match function names and the like.  */
+/* { dg-final { scan-assembler-times "isel " 26 } } */
diff -ruN gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel64-errors.c gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel64-errors.c
--- gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel64-errors.c	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel64-errors.c	2011-07-25 12:27:55.372965000 -0500
@@ -0,0 +1,110 @@
+/* Test rejection of invalid parameter combinations in isel builtins.  */
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-options "-mcpu=e5500" } */
+
+#include "builtin-isel.h"
+
+
+/* Equality comparisons.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64eq
+
+SIGNED64_PROTO
+{
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned long) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned long) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((long *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (long *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned long) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned long) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (long *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (long *) q); /* { dg-error "isel intrinsic" } */
+}
+
+/* less-than, greater-than.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64lt
+
+SIGNED64_PROTO
+{
+  /* Unsigned comparison should be done with the *u variants.  */
+  ISEL_BUILTIN ((unsigned long) x, (unsigned long) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* So should pointer comparison.  */
+  ISEL_BUILTIN (p, q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned long) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned long) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((long *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (long *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned long) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned long) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (long *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (long *) q); /* { dg-error "isel intrinsic" } */
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64gt
+
+SIGNED64_PROTO
+{
+  /* Unsigned comparison should be done with the *u variants.  */
+  ISEL_BUILTIN ((unsigned long) x, (unsigned long) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* So should pointer comparison.  */
+  ISEL_BUILTIN (p, q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned long) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned long) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((long *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (long *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned long) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned long) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (long *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (long *) q); /* { dg-error "isel intrinsic" } */
+}
+
+/* Unsigned variants.  These permit unsigned and pointer operands for
+   comparison only.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64ltu
+
+UNSIGNED64_PROTO
+{
+  /* Signed comparison should be done with the signed variants.  */
+  ISEL_BUILTIN ((long) x, (long) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((long) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (long) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((long *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (long *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned long) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned long) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (long *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (long *) q); /* { dg-error "isel intrinsic" } */
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isel64gtu
+
+UNSIGNED64_PROTO
+{
+  /* Signed comparison should be done with the signed variants.  */
+  ISEL_BUILTIN ((long) x, (long) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((long) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (long) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((long *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (long *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned long) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned long) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (long *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (long *) q); /* { dg-error "isel intrinsic" } */
+}
diff -ruN gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel.c gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel.c
--- gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel.c	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel.c	2011-07-25 12:27:55.405959000 -0500
@@ -0,0 +1,81 @@
+/* { dg-do compile } */
+/* { dg-options "-mcpu=e500mc" } */
+
+#include "builtin-isel.h"
+
+/* We're not being clever with the preprocessor here because DejaGNU
+   will get confused.  We do try to use it to eliminate what duplication
+   we can.  */
+
+/* We check to see that the resolution permits polymorphic results.  */
+
+/* Equality comparisons.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iseleq
+
+SIGNED_PROTO
+{
+  i = ISEL_BUILTIN (x, y, a, b);
+  u = ISEL_BUILTIN (x, y, (unsigned int) a, (unsigned int) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  i = ISEL_BUILTIN (p, q, a, b);
+  /* Equality checks explicitly permit unsigned comparison operands.  */
+  i = ISEL_BUILTIN ((unsigned int) x, (unsigned int) y, a, b);
+  r = ISEL_BUILTIN ((unsigned int) x, (unsigned int) y, p, q);
+}
+
+/* less-than, greater-than.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isellt
+
+SIGNED_PROTO
+{
+  i = ISEL_BUILTIN (x, y, a, b);
+  u = ISEL_BUILTIN (x, y, (unsigned int) a, (unsigned int) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselgt
+
+SIGNED_PROTO
+{
+  i = ISEL_BUILTIN (x, y, a, b);
+  u = ISEL_BUILTIN (x, y, (unsigned int) a, (unsigned int) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+}
+
+/* Unsigned variants.  These permit unsigned and pointer operands for
+   comparison only.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselltu
+
+UNSIGNED_PROTO
+{
+  i = ISEL_BUILTIN (x, y, a, b);
+  u = ISEL_BUILTIN (x, y, (unsigned int) a, (unsigned int) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  i = ISEL_BUILTIN (p, q, a, b);
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselgtu
+
+UNSIGNED_PROTO
+{
+  i = ISEL_BUILTIN (x, y, a, b);
+  u = ISEL_BUILTIN (x, y, (unsigned int) a, (unsigned int) b);
+  r = ISEL_BUILTIN (x, y, p, q);
+  r = ISEL_BUILTIN (x, y, (char *) p, (char *) q);
+  i = ISEL_BUILTIN (p, q, a, b);
+}
+
+/* Don't use bare isel, as that'll match function names and the like.  */
+/* { dg-final { scan-assembler-times "isel " 26 } } */
diff -ruN gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel-errors.c gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel-errors.c
--- gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel-errors.c	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel-errors.c	2011-07-25 12:27:55.443938000 -0500
@@ -0,0 +1,117 @@
+/* Test rejection of invalid parameter combinations in isel builtins.  */
+/* { dg-do compile } */
+/* { dg-options "-mcpu=e500mc" } */
+
+#include "builtin-isel.h"
+
+/* We're not being clever with the preprocessor here because DejaGNU
+   will get confused.  We do try to use it to eliminate what duplication
+   we can.  */
+
+/* We check basic resolution of each builtin.  We also check to see that
+   the resolution permits polymorphic results.  Argument type mismatches
+   and result type mismatches are not permitted, except where noted.  */
+
+/* Equality comparisons.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iseleq
+
+SIGNED_PROTO
+{
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned int) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned int) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((int *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (int *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned int) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned int) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (int *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (int *) q); /* { dg-error "isel intrinsic" } */
+}
+
+/* less-than, greater-than.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME isellt
+
+SIGNED_PROTO
+{
+  /* Unsigned comparison should be done with the *u variants.  */
+  ISEL_BUILTIN ((unsigned int) x, (unsigned int) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* So should pointer comparison.  */
+  ISEL_BUILTIN (p, q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned int) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned int) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((int *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (int *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned int) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned int) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (int *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (int *) q); /* { dg-error "isel intrinsic" } */
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselgt
+
+SIGNED_PROTO
+{
+  /* Unsigned comparison should be done with the *u variants.  */
+  ISEL_BUILTIN ((unsigned int) x, (unsigned int) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* So should pointer comparison.  */
+  ISEL_BUILTIN (p, q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((unsigned int) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (unsigned int) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((int *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (int *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned int) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned int) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (int *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (int *) q); /* { dg-error "isel intrinsic" } */
+}
+
+/* Unsigned variants.  These permit unsigned and pointer operands for
+   comparison only.  */
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselltu
+
+UNSIGNED_PROTO
+{
+  /* Signed comparison should be done with the signed variants.  */
+  ISEL_BUILTIN ((int) x, (int) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((int) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (int) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((int *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (int *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned int) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned int) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (int *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (int *) q); /* { dg-error "isel intrinsic" } */
+}
+
+#undef FUNCTION_NAME
+#define FUNCTION_NAME iselgtu
+
+UNSIGNED_PROTO
+{
+  /* Signed comparison should be done with the signed variants.  */
+  ISEL_BUILTIN ((int) x, (int) y, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in argument type.  */
+  ISEL_BUILTIN ((int) x, y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, (int) y, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN ((int *) p, q, a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (p, (int *) q, a, b); /* { dg-error "isel intrinsic" } */
+  /* Mismatches in return type.  */
+  ISEL_BUILTIN (x, y, (unsigned int) a, b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, a, (unsigned int) b); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, (int *) p, q); /* { dg-error "isel intrinsic" } */
+  ISEL_BUILTIN (x, y, p, (int *) q); /* { dg-error "isel intrinsic" } */
+}
diff -ruN gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel.h gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel.h
--- gcc-4.6.0-orig/gcc/testsuite/gcc.target/powerpc/builtin-isel.h	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.6.0-new/gcc/testsuite/gcc.target/powerpc/builtin-isel.h	2011-07-25 12:27:55.483942000 -0500
@@ -0,0 +1,25 @@
+/* Common definitions for builtin isel testing.  */
+
+#define SIGNED_ARGLIST (int x, int y, int a, int b, void *p, void *q)
+#define UNSIGNED_ARGLIST (unsigned int x, unsigned int y, \
+			  int a, int b, void *p, void *q)
+
+#define SIGNED_PROTO void FUNCTION_NAME SIGNED_ARGLIST
+#define UNSIGNED_PROTO void FUNCTION_NAME UNSIGNED_ARGLIST
+
+#define SIGNED64_ARGLIST (long x, long y, long a, long b, void *p, void *q)
+#define UNSIGNED64_ARGLIST (unsigned long x, unsigned long y, \
+			    long a, long b, void *p, void *q)
+
+#define SIGNED64_PROTO void FUNCTION_NAME SIGNED64_ARGLIST
+#define UNSIGNED64_PROTO void FUNCTION_NAME UNSIGNED64_ARGLIST
+
+#define CONCAT2(X,Y) X##Y
+#define CONCAT(X,Y) CONCAT2(X, Y)
+#define ISEL_BUILTIN CONCAT(__builtin_, FUNCTION_NAME)
+
+volatile int i;
+volatile unsigned int u;
+volatile void *r;
+volatile long L;
+volatile unsigned long U;