summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/CodeGen
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2019-02-04 19:15:50 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2019-02-04 19:15:50 +0000
commit8121ec26c0be6fbcdbd30e35dacefe4f5d7c1e65 (patch)
treef393c6c8ca48095b6331f9b4da6f0ddf8b51db1e /llvm/unittests/CodeGen
parenta1cc4ea7bb1a527917f4be87475e5931d034a4ca (diff)
downloadbcm5719-llvm-8121ec26c0be6fbcdbd30e35dacefe4f5d7c1e65.tar.gz
bcm5719-llvm-8121ec26c0be6fbcdbd30e35dacefe4f5d7c1e65.zip
GlobalISel: Fix CSE handling of buildConstant
This fixes two problems with CSE done in buildConstant. First, this would hit an assert when used with a vector result type. Solve this by allowing CSE on the vector elements, but not on the result vector for now. Second, this was also performing the CSE based on the input ConstantInt pointer. The underlying buildConstant could potentially convert the constant depending on the result type, giving in a different ConstantInt*. Stop allowing the APInt and ConstantInt forms from automatically casting to the result type to avoid any similar problems in the future. llvm-svn: 353077
Diffstat (limited to 'llvm/unittests/CodeGen')
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/CSETest.cpp13
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp40
2 files changed, 49 insertions, 4 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp b/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
index cd6f99bf6e4..02627cae164 100644
--- a/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
@@ -25,6 +25,7 @@ TEST_F(GISelMITest, TestCSE) {
CSEInfo.analyze(*MF);
B.setCSEInfo(&CSEInfo);
CSEMIRBuilder CSEB(B.getState());
+
CSEB.setInsertPt(*EntryMBB, EntryMBB->begin());
unsigned AddReg = MRI->createGenericVirtualRegister(s16);
auto MIBAddCopy =
@@ -54,6 +55,18 @@ TEST_F(GISelMITest, TestCSE) {
EXPECT_TRUE(&*MIBFP0 == &*MIBFP0_1);
CSEInfo.print();
+ // Make sure buildConstant with a vector type doesn't crash, and the elements
+ // CSE.
+ auto Splat0 = CSEB.buildConstant(LLT::vector(2, s32), 0);
+ EXPECT_EQ(TargetOpcode::G_BUILD_VECTOR, Splat0->getOpcode());
+ EXPECT_EQ(Splat0->getOperand(1).getReg(), Splat0->getOperand(2).getReg());
+ EXPECT_EQ(&*MIBCst, MRI->getVRegDef(Splat0->getOperand(1).getReg()));
+
+ auto FSplat = CSEB.buildFConstant(LLT::vector(2, s32), 1.0);
+ EXPECT_EQ(TargetOpcode::G_BUILD_VECTOR, FSplat->getOpcode());
+ EXPECT_EQ(FSplat->getOperand(1).getReg(), FSplat->getOperand(2).getReg());
+ EXPECT_EQ(&*MIBFP0, MRI->getVRegDef(FSplat->getOperand(1).getReg()));
+
// Check G_UNMERGE_VALUES
auto MIBUnmerge = CSEB.buildUnmerge({s32, s32}, Copies[0]);
auto MIBUnmerge2 = CSEB.buildUnmerge({s32, s32}, Copies[0]);
diff --git a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
index ca25ec54d6d..9a2533159be 100644
--- a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
@@ -13,9 +13,6 @@ TEST_F(GISelMITest, TestBuildConstantFConstant) {
if (!TM)
return;
- MachineIRBuilder B(*MF);
- B.setInsertPt(*EntryMBB, EntryMBB->begin());
-
B.buildConstant(LLT::scalar(32), 42);
B.buildFConstant(LLT::scalar(32), 1.0);
@@ -27,9 +24,44 @@ TEST_F(GISelMITest, TestBuildConstantFConstant) {
CHECK: [[FCONST0:%[0-9]+]]:_(s32) = G_FCONSTANT float 1.000000e+00
CHECK: [[CONST1:%[0-9]+]]:_(s32) = G_CONSTANT i32 99
CHECK: [[VEC0:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[CONST1]]:_(s32), [[CONST1]]:_(s32)
- CHECK: [[FCONST1:%[0-9]+]]:_(s32) = G_FCONSTANT double 2.000000e+00
+ CHECK: [[FCONST1:%[0-9]+]]:_(s32) = G_FCONSTANT float 2.000000e+00
CHECK: [[VEC1:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[FCONST1]]:_(s32), [[FCONST1]]:_(s32)
)";
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+
+TEST_F(GISelMITest, TestBuildConstantFConstantDeath) {
+ if (!TM)
+ return;
+
+ LLVMContext &Ctx = MF->getFunction().getContext();
+ APInt APV32(32, 12345);
+
+ // Test APInt version breaks
+ EXPECT_DEATH(B.buildConstant(LLT::scalar(16), APV32),
+ "creating constant with the wrong size");
+ EXPECT_DEATH(B.buildConstant(LLT::vector(2, 16), APV32),
+ "creating constant with the wrong size");
+
+ // Test ConstantInt version breaks
+ ConstantInt *CI = ConstantInt::get(Ctx, APV32);
+ EXPECT_DEATH(B.buildConstant(LLT::scalar(16), *CI),
+ "creating constant with the wrong size");
+ EXPECT_DEATH(B.buildConstant(LLT::vector(2, 16), *CI),
+ "creating constant with the wrong size");
+
+ APFloat DoubleVal(APFloat::IEEEdouble());
+ ConstantFP *CF = ConstantFP::get(Ctx, DoubleVal);
+ EXPECT_DEATH(B.buildFConstant(LLT::scalar(16), *CF),
+ "creating fconstant with the wrong size");
+ EXPECT_DEATH(B.buildFConstant(LLT::vector(2, 16), *CF),
+ "creating fconstant with the wrong size");
+}
+
+#endif
+#endif
OpenPOWER on IntegriCloud