Skip to content

Commit af8e15d

Browse files
committed
Implement legalization for some operations
1 parent efc2b24 commit af8e15d

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,17 @@ class LegalizeRuleSet {
950950
changeTo(typeIdx(TypeIdx), Ty));
951951
}
952952

953+
/// Conditionally limit the minimum size of the scalar.
954+
LegalizeRuleSet &minScalarIf(LegalityPredicate Predicate, unsigned TypeIdx,
955+
const LLT Ty) {
956+
using namespace LegalityPredicates;
957+
using namespace LegalizeMutations;
958+
return actionIf(
959+
LegalizeAction::WidenScalar,
960+
all(scalarNarrowerThan(TypeIdx, Ty.getSizeInBits()), Predicate),
961+
changeTo(typeIdx(TypeIdx), Ty));
962+
}
963+
953964
/// Ensure the scalar is at most as wide as Ty.
954965
LegalizeRuleSet &maxScalarOrElt(unsigned TypeIdx, const LLT Ty) {
955966
using namespace LegalityPredicates;
@@ -977,13 +988,8 @@ class LegalizeRuleSet {
977988
using namespace LegalizeMutations;
978989
return actionIf(
979990
LegalizeAction::NarrowScalar,
980-
[=](const LegalityQuery &Query) {
981-
const LLT QueryTy = Query.Types[TypeIdx];
982-
return QueryTy.isScalar() &&
983-
QueryTy.getSizeInBits() > Ty.getSizeInBits() &&
984-
Predicate(Query);
985-
},
986-
changeElementTo(typeIdx(TypeIdx), Ty));
991+
all(scalarWiderThan(TypeIdx, Ty.getSizeInBits()), Predicate),
992+
changeTo(typeIdx(TypeIdx), Ty));
987993
}
988994

989995
/// Limit the range of scalar sizes to MinTy and MaxTy.

llvm/lib/Target/Z80/GISel/Z80LegalizerInfo.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ using namespace MIPatternMatch;
2929
Z80LegalizerInfo::Z80LegalizerInfo(const Z80Subtarget &STI,
3030
const Z80TargetMachine &TM)
3131
: Subtarget(STI), TM(TM) {
32+
using namespace LegalityPredicates;
33+
using namespace LegalizeMutations;
34+
3235
bool Is24Bit = Subtarget.is24Bit();
36+
LegalityPredicate pred24Bit = [=](const LegalityQuery &) { return Is24Bit; };
37+
38+
LegalityPredicate predZ180Ops = [this](const LegalityQuery &) { return Subtarget.hasZ180Ops(); };
3339

3440
std::array<LLT, 5> p;
3541
for (int AddrSpace = 0; AddrSpace != p.size(); ++AddrSpace)
@@ -39,6 +45,7 @@ Z80LegalizerInfo::Z80LegalizerInfo(const Z80Subtarget &STI,
3945
LLT s16 = LLT::scalar(16);
4046
LLT s24 = LLT::scalar(24);
4147
LLT s32 = LLT::scalar(32);
48+
LLT s48 = LLT::scalar(48);
4249
LLT s64 = LLT::scalar(64);
4350
LLT sMax = Is24Bit ? s24 : s16;
4451
LLT sOther = Is24Bit ? s16 : s24;
@@ -159,13 +166,15 @@ Z80LegalizerInfo::Z80LegalizerInfo(const Z80Subtarget &STI,
159166
.legalForCartesianProduct(LegalScalars, {s1})
160167
.clampScalar(0, s8, sMax);
161168

162-
{
163-
auto &&Mul = getActionDefinitionsBuilder(G_MUL);
164-
if (Subtarget.hasZ180Ops())
165-
Mul.legalFor({s8});
166-
Mul.libcallFor(LegalLibcallScalars)
167-
.clampScalar(0, s8, s32);
168-
}
169+
getActionDefinitionsBuilder(G_MUL)
170+
.legalIf(all(predZ180Ops, typeIs(0, s8)))
171+
.libcallFor(LegalLibcallScalars)
172+
.minScalar(0, s8)
173+
.minScalar(0, s16)
174+
.minScalarIf(pred24Bit, 0, s24)
175+
.minScalar(0, s32)
176+
.minScalar(0, s64)
177+
.maxScalar(0, s64);
169178

170179
getActionDefinitionsBuilder({G_SDIV, G_UDIV, G_SREM, G_UREM})
171180
.libcallFor(LegalLibcallScalars)
@@ -179,7 +188,12 @@ Z80LegalizerInfo::Z80LegalizerInfo(const Z80Subtarget &STI,
179188
getActionDefinitionsBuilder({G_SHL, G_LSHR, G_ASHR})
180189
.customForCartesianProduct(LegalLibcallScalars, {s8})
181190
.clampScalar(1, s8, s8)
182-
.clampScalar(0, s8, s64);
191+
.minScalar(0, s8)
192+
.minScalar(0, s16)
193+
.minScalarIf(pred24Bit, 0, s24)
194+
.minScalar(0, s32)
195+
.minScalar(0, s64)
196+
.maxScalar(0, s64);
183197

184198
getActionDefinitionsBuilder({G_FSHL, G_FSHR, G_ROTR, G_ROTL, G_UMULO,
185199
G_UMULFIX, G_SMULFIX, G_SMULFIXSAT, G_UMULFIXSAT,

0 commit comments

Comments
 (0)