[llvm] r277768 - GlobalISel: refuse to halve size of 1-byte & odd-sized LLTs.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 4 13:54:06 PDT 2016
Author: tnorthover
Date: Thu Aug 4 15:54:05 2016
New Revision: 277768
URL: http://llvm.org/viewvc/llvm-project?rev=277768&view=rev
Log:
GlobalISel: refuse to halve size of 1-byte & odd-sized LLTs.
Modified:
llvm/trunk/include/llvm/CodeGen/LowLevelType.h
llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
Modified: llvm/trunk/include/llvm/CodeGen/LowLevelType.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LowLevelType.h?rev=277768&r1=277767&r2=277768&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LowLevelType.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LowLevelType.h Thu Aug 4 15:54:05 2016
@@ -131,7 +131,8 @@ public:
/// size of the scalar type involved. For example `s32` will become `s16`,
/// `<2 x s32>` will become `<2 x s16>`.
LLT halfScalarSize() const {
- assert(isSized() && "cannot change size of this type");
+ assert(isSized() && getScalarSizeInBits() > 1 &&
+ getScalarSizeInBits() % 2 == 0 && "cannot half size of this type");
return LLT{Kind, NumElements, SizeOrAddrSpace / 2};
}
Modified: llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp?rev=277768&r1=277767&r2=277768&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp Thu Aug 4 15:54:05 2016
@@ -34,7 +34,7 @@ TEST(LowLevelTypeTest, Scalar) {
for (unsigned S : {1U, 17U, 32U, 64U, 0xfffffU}) {
const LLT Ty = LLT::scalar(S);
- const LLT HalfTy = Ty.halfScalarSize();
+ const LLT HalfTy = (S % 2) == 0 ? Ty.halfScalarSize() : Ty;
const LLT DoubleTy = Ty.doubleScalarSize();
// Test kind.
@@ -51,13 +51,14 @@ TEST(LowLevelTypeTest, Scalar) {
EXPECT_EQ(S, Ty.getSizeInBits());
EXPECT_EQ(S, Ty.getScalarSizeInBits());
- // Is it OK to half an odd-sized scalar? It currently is.
- EXPECT_EQ(S/2, HalfTy.getSizeInBits());
- EXPECT_EQ(S/2, HalfTy.getScalarSizeInBits());
-
EXPECT_EQ(S*2, DoubleTy.getSizeInBits());
EXPECT_EQ(S*2, DoubleTy.getScalarSizeInBits());
+ if ((S % 2) == 0) {
+ EXPECT_EQ(S/2, HalfTy.getSizeInBits());
+ EXPECT_EQ(S/2, HalfTy.getScalarSizeInBits());
+ }
+
// Test equality operators.
EXPECT_TRUE(Ty == Ty);
EXPECT_FALSE(Ty != Ty);
@@ -87,7 +88,7 @@ TEST(LowLevelTypeTest, Vector) {
// Test getElementType().
EXPECT_EQ(STy, VTy.getElementType());
- const LLT HalfSzTy = VTy.halfScalarSize();
+ const LLT HalfSzTy = ((S % 2) == 0) ? VTy.halfScalarSize() : VTy;
const LLT DoubleSzTy = VTy.doubleScalarSize();
// halfElements requires an even number of elements.
@@ -123,9 +124,11 @@ TEST(LowLevelTypeTest, Vector) {
EXPECT_EQ(S, VTy.getScalarSizeInBits());
EXPECT_EQ(Elts, VTy.getNumElements());
- EXPECT_EQ((S / 2) * Elts, HalfSzTy.getSizeInBits());
- EXPECT_EQ(S / 2, HalfSzTy.getScalarSizeInBits());
- EXPECT_EQ(Elts, HalfSzTy.getNumElements());
+ if ((S % 2) == 0) {
+ EXPECT_EQ((S / 2) * Elts, HalfSzTy.getSizeInBits());
+ EXPECT_EQ(S / 2, HalfSzTy.getScalarSizeInBits());
+ EXPECT_EQ(Elts, HalfSzTy.getNumElements());
+ }
EXPECT_EQ((S * 2) * Elts, DoubleSzTy.getSizeInBits());
EXPECT_EQ(S * 2, DoubleSzTy.getScalarSizeInBits());
More information about the llvm-commits
mailing list