[llvm] r353069 - GlobalISel: Fix moreElementsToNextPow2
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 4 10:42:24 PST 2019
Author: arsenm
Date: Mon Feb 4 10:42:24 2019
New Revision: 353069
URL: http://llvm.org/viewvc/llvm-project?rev=353069&view=rev
Log:
GlobalISel: Fix moreElementsToNextPow2
This was completely broken. The condition was inverted, and changed
the element type for vectors of pointers.
Fixes bug 40592.
Modified:
llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp?rev=353069&r1=353068&r2=353069&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalityPredicates.cpp Mon Feb 4 10:42:24 2019
@@ -115,8 +115,8 @@ LegalityPredicate LegalityPredicates::me
LegalityPredicate LegalityPredicates::numElementsNotPow2(unsigned TypeIdx) {
return [=](const LegalityQuery &Query) {
- const LLT &QueryTy = Query.Types[TypeIdx];
- return QueryTy.isVector() && isPowerOf2_32(QueryTy.getNumElements());
+ const LLT QueryTy = Query.Types[TypeIdx];
+ return QueryTy.isVector() && !isPowerOf2_32(QueryTy.getNumElements());
};
}
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp?rev=353069&r1=353068&r2=353069&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizeMutations.cpp Mon Feb 4 10:42:24 2019
@@ -40,12 +40,11 @@ LegalizeMutation LegalizeMutations::wide
LegalizeMutation LegalizeMutations::moreElementsToNextPow2(unsigned TypeIdx,
unsigned Min) {
return [=](const LegalityQuery &Query) {
- const LLT &VecTy = Query.Types[TypeIdx];
- unsigned NewNumElements = 1 << Log2_32_Ceil(VecTy.getNumElements());
- if (NewNumElements < Min)
- NewNumElements = Min;
- return std::make_pair(
- TypeIdx, LLT::vector(NewNumElements, VecTy.getScalarSizeInBits()));
+ const LLT VecTy = Query.Types[TypeIdx];
+ unsigned NewNumElements =
+ std::max(1u << Log2_32_Ceil(VecTy.getNumElements()), Min);
+ return std::make_pair(TypeIdx,
+ LLT::vector(NewNumElements, VecTy.getElementType()));
};
}
Modified: llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp?rev=353069&r1=353068&r2=353069&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp Mon Feb 4 10:42:24 2019
@@ -41,6 +41,12 @@ operator<<(std::ostream &OS, const llvm:
OS << SS.str();
return OS;
}
+
+std::ostream &operator<<(std::ostream &OS, const llvm::LegalizeActionStep Ty) {
+ OS << "LegalizeActionStep(" << Ty.Action << ", " << Ty.TypeIdx << ", "
+ << Ty.NewType << ')';
+ return OS;
+}
}
namespace {
@@ -198,3 +204,37 @@ TEST(LegalizerInfoTest, SizeChangeStrate
LegalizeActionStep(Unsupported, 0, LLT::scalar(33)));
}
}
+
+#define EXPECT_ACTION(Action, Index, Type, Query) \
+ do { \
+ auto A = LI.getAction(Query); \
+ EXPECT_EQ(LegalizeActionStep(Action, Index, Type), A) << A; \
+ } while (0)
+
+TEST(LegalizerInfoTest, RuleSets) {
+ using namespace TargetOpcode;
+
+ const LLT s32 = LLT::scalar(32);
+
+ const LLT v2s32 = LLT::vector(2, 32);
+ const LLT v3s32 = LLT::vector(3, 32);
+ const LLT v4s32 = LLT::vector(4, 32);
+
+ const LLT p0 = LLT::pointer(0, 32);
+ const LLT v3p0 = LLT::vector(3, p0);
+ const LLT v4p0 = LLT::vector(4, p0);
+
+ {
+ LegalizerInfo LI;
+
+ LI.getActionDefinitionsBuilder(G_IMPLICIT_DEF)
+ .legalFor({v4s32, v4p0})
+ .moreElementsToNextPow2(0);
+ LI.computeTables();
+
+ EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_IMPLICIT_DEF, {s32}));
+ EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_IMPLICIT_DEF, {v2s32}));
+ EXPECT_ACTION(MoreElements, 0, v4p0, LegalityQuery(G_IMPLICIT_DEF, {v3p0}));
+ EXPECT_ACTION(MoreElements, 0, v4s32, LegalityQuery(G_IMPLICIT_DEF, {v3s32}));
+ }
+}
More information about the llvm-commits
mailing list