@@ -282,6 +282,10 @@ LegalityPredicate typePairAndMemDescInSet(
282282 std::initializer_list<TypePairAndMemDesc> TypesAndMemDescInit);
283283// / True iff the specified type index is a scalar.
284284LegalityPredicate isScalar (unsigned TypeIdx);
285+ // / True iff the specified type index is a integer.
286+ LegalityPredicate isInteger (unsigned TypeIdx);
287+ // / True iff the specified type index is a float.
288+ LegalityPredicate isFloat (unsigned TypeIdx);
285289// / True iff the specified type index is a vector.
286290LegalityPredicate isVector (unsigned TypeIdx);
287291// / True iff the specified type index is a pointer (with any address space).
@@ -292,6 +296,14 @@ LegalityPredicate isPointer(unsigned TypeIdx, unsigned AddrSpace);
292296// / True iff the specified type index is a vector of pointers (with any address
293297// / space).
294298LegalityPredicate isPointerVector (unsigned TypeIdx);
299+ // / True iff the specified type index is a vector of integer
300+ LegalityPredicate isIntegerVector (unsigned TypeIdx);
301+ // / True iff the specified type index is a vector of floats.
302+ LegalityPredicate isFloatVector (unsigned TypeIdx);
303+
304+ LegalityPredicate isFloatOrFloatVector (unsigned TypeIdx);
305+
306+ LegalityPredicate isIntegerOrIntegerVector (unsigned TypeIdx);
295307
296308// / True if the type index is a vector with element type \p EltTy
297309LegalityPredicate elementTypeIs (unsigned TypeIdx, LLT EltTy);
@@ -330,6 +342,10 @@ LegalityPredicate sizeIs(unsigned TypeIdx, unsigned Size);
330342// / True iff the specified type indices are both the same bit size.
331343LegalityPredicate sameSize (unsigned TypeIdx0, unsigned TypeIdx1);
332344
345+ LegalityPredicate sameScalarKind (unsigned TypeIdx, LLT Ty);
346+
347+ LegalityPredicate sameKind (unsigned TypeIdx, LLT Ty);
348+
333349// / True iff the first type index has a larger total bit size than second type
334350// / index.
335351LegalityPredicate largerThan (unsigned TypeIdx0, unsigned TypeIdx1);
@@ -381,6 +397,8 @@ LegalizeMutation changeElementCountTo(unsigned TypeIdx, ElementCount EC);
381397// / only changes the size.
382398LegalizeMutation changeElementSizeTo (unsigned TypeIdx, unsigned FromTypeIdx);
383399
400+ LegalizeMutation changeToInteger (unsigned TypeIdx);
401+
384402// / Widen the scalar type or vector element type for the given type index to the
385403// / next power of 2.
386404LegalizeMutation widenScalarOrEltToNextPow2 (unsigned TypeIdx, unsigned Min = 0 );
@@ -942,6 +960,16 @@ class LegalizeRuleSet {
942960 LegalizeMutations::widenScalarOrEltToNextPow2 (TypeIdx, MinSize));
943961 }
944962
963+ LegalizeRuleSet &widenScalarToNextPow2Bitcast (unsigned TypeIdx,
964+ unsigned MinSize = 0 ) {
965+ using namespace LegalityPredicates ;
966+ using namespace LegalizeMutations ;
967+ return actionIf (
968+ LegalizeAction::Bitcast,
969+ all (isFloatOrFloatVector (TypeIdx), sizeNotPow2 (typeIdx (TypeIdx))),
970+ changeToInteger (TypeIdx));
971+ }
972+
945973 // / Widen the scalar to the next multiple of Size. No effect if the
946974 // / type is not a scalar or is a multiple of Size.
947975 LegalizeRuleSet &widenScalarToNextMultipleOf (unsigned TypeIdx,
@@ -997,20 +1025,32 @@ class LegalizeRuleSet {
9971025 LegalizeRuleSet &minScalarOrElt (unsigned TypeIdx, const LLT Ty) {
9981026 using namespace LegalityPredicates ;
9991027 using namespace LegalizeMutations ;
1000- return actionIf (LegalizeAction::WidenScalar,
1001- scalarOrEltNarrowerThan (TypeIdx, Ty.getScalarSizeInBits ()),
1002- changeElementTo (typeIdx (TypeIdx), Ty));
1028+ return actionIf (
1029+ LegalizeAction::WidenScalar,
1030+ all (sameScalarKind (TypeIdx, Ty),
1031+ scalarOrEltNarrowerThan (TypeIdx, Ty.getScalarSizeInBits ())),
1032+ changeElementTo (typeIdx (TypeIdx), Ty));
1033+ }
1034+ LegalizeRuleSet &minScalarOrEltBitcast (unsigned TypeIdx, const LLT Ty) {
1035+ using namespace LegalityPredicates ;
1036+ using namespace LegalizeMutations ;
1037+ return actionIf (
1038+ LegalizeAction::Bitcast,
1039+ all (isFloatOrFloatVector (TypeIdx),
1040+ scalarOrEltNarrowerThan (TypeIdx, Ty.getScalarSizeInBits ())),
1041+ changeToInteger (typeIdx (TypeIdx)));
10031042 }
10041043
10051044 // / Ensure the scalar or element is at least as wide as Ty.
10061045 LegalizeRuleSet &minScalarOrEltIf (LegalityPredicate Predicate,
10071046 unsigned TypeIdx, const LLT Ty) {
10081047 using namespace LegalityPredicates ;
10091048 using namespace LegalizeMutations ;
1010- return actionIf (LegalizeAction::WidenScalar,
1011- all (Predicate, scalarOrEltNarrowerThan (
1012- TypeIdx, Ty.getScalarSizeInBits ())),
1013- changeElementTo (typeIdx (TypeIdx), Ty));
1049+ return actionIf (
1050+ LegalizeAction::WidenScalar,
1051+ all (Predicate, sameScalarKind (TypeIdx, Ty),
1052+ scalarOrEltNarrowerThan (TypeIdx, Ty.getScalarSizeInBits ())),
1053+ changeElementTo (typeIdx (TypeIdx), Ty));
10141054 }
10151055
10161056 // / Ensure the vector size is at least as wide as VectorSize by promoting the
@@ -1039,14 +1079,23 @@ class LegalizeRuleSet {
10391079 using namespace LegalityPredicates ;
10401080 using namespace LegalizeMutations ;
10411081 return actionIf (LegalizeAction::WidenScalar,
1042- scalarNarrowerThan (TypeIdx, Ty.getSizeInBits ()),
1082+ all (sameKind (TypeIdx, Ty),
1083+ scalarNarrowerThan (TypeIdx, Ty.getSizeInBits ())),
10431084 changeTo (typeIdx (TypeIdx), Ty));
10441085 }
10451086 LegalizeRuleSet &minScalar (bool Pred, unsigned TypeIdx, const LLT Ty) {
10461087 if (!Pred)
10471088 return *this ;
10481089 return minScalar (TypeIdx, Ty);
10491090 }
1091+ LegalizeRuleSet &minScalarBitcast (unsigned TypeIdx, const LLT Ty) {
1092+ using namespace LegalityPredicates ;
1093+ using namespace LegalizeMutations ;
1094+ return actionIf (LegalizeAction::Bitcast,
1095+ all (isFloatOrFloatVector (TypeIdx),
1096+ scalarNarrowerThan (TypeIdx, Ty.getSizeInBits ())),
1097+ changeToInteger (typeIdx (TypeIdx)));
1098+ }
10501099
10511100 // / Ensure the scalar is at least as wide as Ty if condition is met.
10521101 LegalizeRuleSet &minScalarIf (LegalityPredicate Predicate, unsigned TypeIdx,
@@ -1068,19 +1117,39 @@ class LegalizeRuleSet {
10681117 LegalizeRuleSet &maxScalarOrElt (unsigned TypeIdx, const LLT Ty) {
10691118 using namespace LegalityPredicates ;
10701119 using namespace LegalizeMutations ;
1071- return actionIf (LegalizeAction::NarrowScalar,
1072- scalarOrEltWiderThan (TypeIdx, Ty.getScalarSizeInBits ()),
1073- changeElementTo (typeIdx (TypeIdx), Ty));
1120+ return actionIf (
1121+ LegalizeAction::NarrowScalar,
1122+ all (sameScalarKind (TypeIdx, Ty),
1123+ scalarOrEltWiderThan (TypeIdx, Ty.getScalarSizeInBits ())),
1124+ changeElementTo (typeIdx (TypeIdx), Ty));
1125+ }
1126+ LegalizeRuleSet &maxScalarOrEltBitcast (unsigned TypeIdx, const LLT Ty) {
1127+ using namespace LegalityPredicates ;
1128+ using namespace LegalizeMutations ;
1129+ return actionIf (
1130+ LegalizeAction::NarrowScalar,
1131+ all (isFloatOrFloatVector (TypeIdx),
1132+ scalarOrEltWiderThan (TypeIdx, Ty.getScalarSizeInBits ())),
1133+ changeToInteger (typeIdx (TypeIdx)));
10741134 }
10751135
10761136 // / Ensure the scalar is at most as wide as Ty.
10771137 LegalizeRuleSet &maxScalar (unsigned TypeIdx, const LLT Ty) {
10781138 using namespace LegalityPredicates ;
10791139 using namespace LegalizeMutations ;
10801140 return actionIf (LegalizeAction::NarrowScalar,
1081- scalarWiderThan (TypeIdx, Ty.getSizeInBits ()),
1141+ all (sameKind (TypeIdx, Ty),
1142+ scalarWiderThan (TypeIdx, Ty.getSizeInBits ())),
10821143 changeTo (typeIdx (TypeIdx), Ty));
10831144 }
1145+ LegalizeRuleSet &maxScalarBitcast (unsigned TypeIdx, const LLT Ty) {
1146+ using namespace LegalityPredicates ;
1147+ using namespace LegalizeMutations ;
1148+ return actionIf (LegalizeAction::NarrowScalar,
1149+ all (isFloatOrFloatVector (TypeIdx),
1150+ scalarWiderThan (TypeIdx, Ty.getSizeInBits ())),
1151+ changeToInteger (typeIdx (TypeIdx)));
1152+ }
10841153
10851154 // / Conditionally limit the maximum size of the scalar.
10861155 // / For example, when the maximum size of one type depends on the size of
@@ -1103,10 +1172,20 @@ class LegalizeRuleSet {
11031172 // / Limit the range of scalar sizes to MinTy and MaxTy.
11041173 LegalizeRuleSet &clampScalar (unsigned TypeIdx, const LLT MinTy,
11051174 const LLT MaxTy) {
1175+ assert (MinTy.getKind () == MaxTy.getKind () &&
1176+ " Expected LLT of the same kind" );
11061177 assert (MinTy.isScalar () && MaxTy.isScalar () && " Expected scalar types" );
11071178 return minScalar (TypeIdx, MinTy).maxScalar (TypeIdx, MaxTy);
11081179 }
11091180
1181+ LegalizeRuleSet &clampScalarBitcast (unsigned TypeIdx, const LLT MinTy,
1182+ const LLT MaxTy) {
1183+ assert (MinTy.getKind () == MaxTy.getKind () &&
1184+ " Expected LLT of the same kind" );
1185+ assert (MinTy.isScalar () && MaxTy.isScalar () && " Expected scalar types" );
1186+ return minScalarBitcast (TypeIdx, MinTy).maxScalarBitcast (TypeIdx, MaxTy);
1187+ }
1188+
11101189 LegalizeRuleSet &clampScalar (bool Pred, unsigned TypeIdx, const LLT MinTy,
11111190 const LLT MaxTy) {
11121191 if (!Pred)
@@ -1120,6 +1199,12 @@ class LegalizeRuleSet {
11201199 return minScalarOrElt (TypeIdx, MinTy).maxScalarOrElt (TypeIdx, MaxTy);
11211200 }
11221201
1202+ LegalizeRuleSet &clampScalarOrEltBitcast (unsigned TypeIdx, const LLT MinTy,
1203+ const LLT MaxTy) {
1204+ return minScalarOrEltBitcast (TypeIdx, MinTy)
1205+ .maxScalarOrEltBitcast (TypeIdx, MaxTy);
1206+ }
1207+
11231208 // / Widen the scalar to match the size of another.
11241209 LegalizeRuleSet &minScalarSameAs (unsigned TypeIdx, unsigned LargeTypeIdx) {
11251210 typeIdx (TypeIdx);
0 commit comments