[llvm] 9faff9a - [GlobalISel][Legalizer] add minScalarIf action
Ties Stuij via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 08:20:56 PST 2022
Author: Ties Stuij
Date: 2022-12-22T16:20:31Z
New Revision: 9faff9a09178eee3b79b669859df72d75de412c3
URL: https://github.com/llvm/llvm-project/commit/9faff9a09178eee3b79b669859df72d75de412c3
DIFF: https://github.com/llvm/llvm-project/commit/9faff9a09178eee3b79b669859df72d75de412c3.diff
LOG: [GlobalISel][Legalizer] add minScalarIf action
Ensure scalar is at least as wide as type, but only if the specified condition
is met.
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D140305
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
index 090388d107ed2..50b11a4920bbd 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
@@ -950,6 +950,22 @@ class LegalizeRuleSet {
changeTo(typeIdx(TypeIdx), Ty));
}
+ /// Ensure the scalar is at least as wide as Ty if condition is met.
+ LegalizeRuleSet &minScalarIf(LegalityPredicate Predicate, unsigned TypeIdx,
+ const LLT Ty) {
+ using namespace LegalityPredicates;
+ using namespace LegalizeMutations;
+ return actionIf(
+ LegalizeAction::WidenScalar,
+ [=](const LegalityQuery &Query) {
+ const LLT QueryTy = Query.Types[TypeIdx];
+ return QueryTy.isScalar() &&
+ QueryTy.getSizeInBits() < Ty.getSizeInBits() &&
+ Predicate(Query);
+ },
+ changeTo(typeIdx(TypeIdx), Ty));
+ }
+
/// Ensure the scalar is at most as wide as Ty.
LegalizeRuleSet &maxScalarOrElt(unsigned TypeIdx, const LLT Ty) {
using namespace LegalityPredicates;
diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
index 5ff5a07902471..988e307909232 100644
--- a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
@@ -321,6 +321,27 @@ TEST(LegalizerInfoTest, RuleSets) {
EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_OR, {v2s16}));
}
+ // Test minScalarIf
+ {
+ bool IfCond = true;
+ LegalizerInfo LI;
+ auto &LegacyInfo = LI.getLegacyLegalizerInfo();
+ LI.getActionDefinitionsBuilder(G_OR)
+ .legalFor({s32})
+ .minScalarIf([&](const LegalityQuery &Query) {
+ return IfCond;
+ }, 0, s32);
+ LegacyInfo.computeTables();
+
+ // Only handle scalars, ignore vectors.
+ EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_OR, {s16}));
+ EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_OR, {v2s16}));
+
+ IfCond = false;
+ EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_OR, {s16}));
+ EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_OR, {v2s16}));
+ }
+
// Test maxScalar
{
LegalizerInfo LI;
More information about the llvm-commits
mailing list