[llvm] r362972 - [Analysis] add unit test file for VectorUtils; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 11:19:06 PDT 2019
Author: spatel
Date: Mon Jun 10 11:19:05 2019
New Revision: 362972
URL: http://llvm.org/viewvc/llvm-project?rev=362972&view=rev
Log:
[Analysis] add unit test file for VectorUtils; NFC
Added:
llvm/trunk/unittests/Analysis/VectorUtilsTest.cpp
Modified:
llvm/trunk/unittests/Analysis/CMakeLists.txt
Modified: llvm/trunk/unittests/Analysis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/CMakeLists.txt?rev=362972&r1=362971&r2=362972&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Analysis/CMakeLists.txt Mon Jun 10 11:19:05 2019
@@ -34,4 +34,5 @@ add_llvm_unittest(AnalysisTests
UnrollAnalyzerTest.cpp
ValueLatticeTest.cpp
ValueTrackingTest.cpp
+ VectorUtilsTest.cpp
)
Added: llvm/trunk/unittests/Analysis/VectorUtilsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/VectorUtilsTest.cpp?rev=362972&view=auto
==============================================================================
--- llvm/trunk/unittests/Analysis/VectorUtilsTest.cpp (added)
+++ llvm/trunk/unittests/Analysis/VectorUtilsTest.cpp Mon Jun 10 11:19:05 2019
@@ -0,0 +1,91 @@
+//===- VectorUtilsTest.cpp - VectorUtils tests ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/VectorUtils.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/KnownBits.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+class VectorUtilsTest : public testing::Test {
+protected:
+ void parseAssembly(const char *Assembly) {
+ SMDiagnostic Error;
+ M = parseAssemblyString(Assembly, Error, Context);
+
+ std::string errMsg;
+ raw_string_ostream os(errMsg);
+ Error.print("", os);
+
+ // A failure here means that the test itself is buggy.
+ if (!M)
+ report_fatal_error(os.str());
+
+ Function *F = M->getFunction("test");
+ if (F == nullptr)
+ report_fatal_error("Test must have a function named @test");
+
+ A = nullptr;
+ for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
+ if (I->hasName()) {
+ if (I->getName() == "A")
+ A = &*I;
+ }
+ }
+ if (A == nullptr)
+ report_fatal_error("@test must have an instruction %A");
+ }
+
+ LLVMContext Context;
+ std::unique_ptr<Module> M;
+ Instruction *A;
+};
+
+} // namespace
+
+TEST_F(VectorUtilsTest, getSplatValueElt0) {
+ parseAssembly(
+ "define <2 x i8> @test(i8 %x) {\n"
+ " %ins = insertelement <2 x i8> undef, i8 %x, i32 0\n"
+ " %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> zeroinitializer\n"
+ " ret <2 x i8> %A\n"
+ "}\n");
+ EXPECT_EQ(getSplatValue(A)->getName(), "x");
+}
+
+TEST_F(VectorUtilsTest, getSplatValueEltMismatch) {
+ parseAssembly(
+ "define <2 x i8> @test(i8 %x) {\n"
+ " %ins = insertelement <2 x i8> undef, i8 %x, i32 1\n"
+ " %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> zeroinitializer\n"
+ " ret <2 x i8> %A\n"
+ "}\n");
+ EXPECT_EQ(getSplatValue(A), nullptr);
+}
+
+// TODO: This is a splat, but we don't recognize it.
+
+TEST_F(VectorUtilsTest, getSplatValueElt1) {
+ parseAssembly(
+ "define <2 x i8> @test(i8 %x) {\n"
+ " %ins = insertelement <2 x i8> undef, i8 %x, i32 1\n"
+ " %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
+ " ret <2 x i8> %A\n"
+ "}\n");
+ EXPECT_EQ(getSplatValue(A), nullptr);
+}
More information about the llvm-commits
mailing list