forked from OSchip/llvm-project
Add IsBytewiseValue unit test
Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63966 llvm-svn: 365710
This commit is contained in:
parent
d03bd1db59
commit
329d15b5df
|
@ -13,8 +13,8 @@
|
||||||
#include "llvm/IR/LLVMContext.h"
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
#include "llvm/Support/KnownBits.h"
|
#include "llvm/Support/KnownBits.h"
|
||||||
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -23,21 +23,26 @@ namespace {
|
||||||
|
|
||||||
class ValueTrackingTest : public testing::Test {
|
class ValueTrackingTest : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void parseAssembly(const char *Assembly) {
|
std::unique_ptr<Module> parseModule(StringRef Assembly) {
|
||||||
SMDiagnostic Error;
|
SMDiagnostic Error;
|
||||||
M = parseAssemblyString(Assembly, Error, Context);
|
std::unique_ptr<Module> M = parseAssemblyString(Assembly, Error, Context);
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
raw_string_ostream os(errMsg);
|
raw_string_ostream os(errMsg);
|
||||||
Error.print("", os);
|
Error.print("", os);
|
||||||
|
EXPECT_TRUE(M) << os.str();
|
||||||
|
|
||||||
// A failure here means that the test itself is buggy.
|
return M;
|
||||||
if (!M)
|
}
|
||||||
report_fatal_error(os.str());
|
|
||||||
|
void parseAssembly(StringRef Assembly) {
|
||||||
|
M = parseModule(Assembly);
|
||||||
|
ASSERT_TRUE(M);
|
||||||
|
|
||||||
Function *F = M->getFunction("test");
|
Function *F = M->getFunction("test");
|
||||||
if (F == nullptr)
|
ASSERT_TRUE(F) << "Test must have a function @test";
|
||||||
report_fatal_error("Test must have a function named @test");
|
if (!F)
|
||||||
|
return;
|
||||||
|
|
||||||
A = nullptr;
|
A = nullptr;
|
||||||
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
||||||
|
@ -46,13 +51,12 @@ protected:
|
||||||
A = &*I;
|
A = &*I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (A == nullptr)
|
ASSERT_TRUE(A) << "@test must have an instruction %A";
|
||||||
report_fatal_error("@test must have an instruction %A");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMContext Context;
|
LLVMContext Context;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M;
|
||||||
Instruction *A;
|
Instruction *A = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MatchSelectPatternTest : public ValueTrackingTest {
|
class MatchSelectPatternTest : public ValueTrackingTest {
|
||||||
|
@ -689,3 +693,256 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownUSubSatZerosPreserved) {
|
||||||
"declare i8 @llvm.usub.sat.i8(i8, i8)\n");
|
"declare i8 @llvm.usub.sat.i8(i8, i8)\n");
|
||||||
expectKnownBits(/*zero*/ 2u, /*one*/ 0u);
|
expectKnownBits(/*zero*/ 2u, /*one*/ 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IsBytewiseValueTest : public ValueTrackingTest,
|
||||||
|
public ::testing::WithParamInterface<
|
||||||
|
std::pair<const char *, const char *>> {
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i48* null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"i48* undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i8 zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i8 0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -86",
|
||||||
|
"i8 -86",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"i8 -1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"i16 undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i16 0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i16 7",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -86",
|
||||||
|
"i16 -21846",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"i16 -1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i48 0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"i48 -1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i49 0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i49 -1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"half 0xH0000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -85",
|
||||||
|
"half 0xHABAB",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"float 0.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"float 0xFFFFFFFFE0000000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"double 0.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -15",
|
||||||
|
"double 0xF1F1F1F1F1F1F1F1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"i16* undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"i16* inttoptr (i64 0 to i16*)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i16* inttoptr (i64 -1 to i16*)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i16* inttoptr (i64 -6148914691236517206 to i16*)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i16* inttoptr (i48 -1 to i16*)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"i16* inttoptr (i96 -1 to i16*)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"[0 x i8] zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"[0 x i8] undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"[5 x [0 x i8]] zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"[5 x [0 x i8]] undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"[6 x i8] zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"[6 x i8] undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 1",
|
||||||
|
"[5 x i8] [i8 1, i8 1, i8 1, i8 1, i8 1]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"[5 x i64] [i64 1, i64 1, i64 1, i64 1, i64 1]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"[5 x i64] [i64 -1, i64 -1, i64 -1, i64 -1, i64 -1]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"[4 x i8] [i8 1, i8 2, i8 1, i8 1]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 1",
|
||||||
|
"[4 x i8] [i8 1, i8 undef, i8 1, i8 1]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"<6 x i8> zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"<6 x i8> undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 1",
|
||||||
|
"<5 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"<5 x i64> <i64 1, i64 1, i64 1, i64 1, i64 1>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -1",
|
||||||
|
"<5 x i64> <i64 -1, i64 -1, i64 -1, i64 -1, i64 -1>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"<4 x i8> <i8 1, i8 1, i8 2, i8 1>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"<2 x i8> < i8 5, i8 undef >",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"[2 x [2 x i16]] zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"[2 x [2 x i16]] undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -86",
|
||||||
|
"[2 x [2 x i16]] [[2 x i16] [i16 -21846, i16 -21846], "
|
||||||
|
"[2 x i16] [i16 -21846, i16 -21846]]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"[2 x [2 x i16]] [[2 x i16] [i16 -21846, i16 -21846], "
|
||||||
|
"[2 x i16] [i16 -21836, i16 -21846]]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"{ } zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"{ } undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"{ {}, {} } zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"{ {}, {} } undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 0",
|
||||||
|
"{i8, i64, i16*} zeroinitializer",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 undef",
|
||||||
|
"{i8, i64, i16*} undef",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"i8 -86",
|
||||||
|
"{i8, i64, i16*} {i8 -86, i64 -6148914691236517206, i16* undef}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
"{i8, i64, i16*} {i8 86, i64 -6148914691236517206, i16* undef}",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(IsBytewiseValueParamTests, IsBytewiseValueTest,
|
||||||
|
::testing::ValuesIn(IsBytewiseValueTests));
|
||||||
|
|
||||||
|
TEST_P(IsBytewiseValueTest, IsBytewiseValue) {
|
||||||
|
auto M = parseModule(std::string("@test = global ") + GetParam().second);
|
||||||
|
GlobalVariable *GV = dyn_cast<GlobalVariable>(M->getNamedValue("test"));
|
||||||
|
Value *Actual = isBytewiseValue(GV->getInitializer(), M->getDataLayout());
|
||||||
|
std::string Buff;
|
||||||
|
raw_string_ostream S(Buff);
|
||||||
|
if (Actual)
|
||||||
|
S << *Actual;
|
||||||
|
EXPECT_EQ(GetParam().first, S.str());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue