summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorPawel Bylica <chfast@gmail.com>2015-04-27 09:30:49 +0000
committerPawel Bylica <chfast@gmail.com>2015-04-27 09:30:49 +0000
commitc25918a043de023f94f40f513aba26455abe01a7 (patch)
treedcbc6c7119f9d887ef6aa135fece8b60739dce54 /llvm/unittests
parent980b92a8e65b8aa36d4ceb3eb1ff8abce5eb74fc (diff)
downloadbcm5719-llvm-c25918a043de023f94f40f513aba26455abe01a7.tar.gz
bcm5719-llvm-c25918a043de023f94f40f513aba26455abe01a7.zip
Constfold insertelement to undef when index is out-of-bounds
Summary: This patch adds constant folding of insertelement instruction to undef value when index operand is constant and is not less than vector size or is undef. InstCombine does not support this case, but I'm happy to add it there also if this change is accepted. Test Plan: Unittests and regression tests for ConstProp pass. Reviewers: majnemer Reviewed By: majnemer Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9287 llvm-svn: 235854
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/IR/ConstantsTest.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index d02217dc355..7741b448fa8 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -190,7 +190,10 @@ TEST(ConstantsTest, AsInstructionsTest) {
Constant *Two = ConstantInt::get(Int64Ty, 2);
Constant *Big = ConstantInt::get(getGlobalContext(),
APInt{256, uint64_t(-1), true});
- Constant *Undef = UndefValue::get(Int64Ty);
+ Constant *Elt = ConstantInt::get(Int16Ty, 2015);
+ Constant *Undef16 = UndefValue::get(Int16Ty);
+ Constant *Undef64 = UndefValue::get(Int64Ty);
+ Constant *UndefV16 = UndefValue::get(P6->getType());
#define P0STR "ptrtoint (i32** @dummy to i32)"
#define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)"
@@ -260,9 +263,15 @@ TEST(ConstantsTest, AsInstructionsTest) {
CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> "
P6STR ", i32 1");
- EXPECT_TRUE(isa<UndefValue>(ConstantExpr::getExtractElement(P6, Two)));
- EXPECT_TRUE(isa<UndefValue>(ConstantExpr::getExtractElement(P6, Big)));
- EXPECT_TRUE(isa<UndefValue>(ConstantExpr::getExtractElement(P6, Undef)));
+ EXPECT_EQ(Undef16, ConstantExpr::getExtractElement(P6, Two));
+ EXPECT_EQ(Undef16, ConstantExpr::getExtractElement(P6, Big));
+ EXPECT_EQ(Undef16, ConstantExpr::getExtractElement(P6, Undef64));
+
+ EXPECT_EQ(Elt, ConstantExpr::getExtractElement(
+ ConstantExpr::getInsertElement(P6, Elt, One), One));
+ EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Two));
+ EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Big));
+ EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Undef64));
}
#ifdef GTEST_HAS_DEATH_TEST
OpenPOWER on IntegriCloud