1 //===- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp - VPlan tests ----===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "../lib/Transforms/Vectorize/VPlan.h"
11 #include "llvm/IR/Instruction.h"
12 #include "llvm/IR/Instructions.h"
13 #include "gtest/gtest.h"
18 #define CHECK_ITERATOR(Range1, ...) \
20 std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
21 EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
23 for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
24 EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
27 TEST(VPInstructionTest
, insertBefore
) {
28 VPInstruction
*I1
= new VPInstruction(0, {});
29 VPInstruction
*I2
= new VPInstruction(1, {});
30 VPInstruction
*I3
= new VPInstruction(2, {});
33 VPBB1
.appendRecipe(I1
);
36 CHECK_ITERATOR(VPBB1
, I2
, I1
);
39 CHECK_ITERATOR(VPBB1
, I3
, I2
, I1
);
42 TEST(VPInstructionTest
, eraseFromParent
) {
43 VPInstruction
*I1
= new VPInstruction(0, {});
44 VPInstruction
*I2
= new VPInstruction(1, {});
45 VPInstruction
*I3
= new VPInstruction(2, {});
48 VPBB1
.appendRecipe(I1
);
49 VPBB1
.appendRecipe(I2
);
50 VPBB1
.appendRecipe(I3
);
52 I2
->eraseFromParent();
53 CHECK_ITERATOR(VPBB1
, I1
, I3
);
55 I1
->eraseFromParent();
56 CHECK_ITERATOR(VPBB1
, I3
);
58 I3
->eraseFromParent();
59 EXPECT_TRUE(VPBB1
.empty());
62 TEST(VPInstructionTest
, moveAfter
) {
63 VPInstruction
*I1
= new VPInstruction(0, {});
64 VPInstruction
*I2
= new VPInstruction(1, {});
65 VPInstruction
*I3
= new VPInstruction(2, {});
68 VPBB1
.appendRecipe(I1
);
69 VPBB1
.appendRecipe(I2
);
70 VPBB1
.appendRecipe(I3
);
74 CHECK_ITERATOR(VPBB1
, I2
, I1
, I3
);
76 VPInstruction
*I4
= new VPInstruction(4, {});
77 VPInstruction
*I5
= new VPInstruction(5, {});
79 VPBB2
.appendRecipe(I4
);
80 VPBB2
.appendRecipe(I5
);
84 CHECK_ITERATOR(VPBB1
, I2
, I1
);
85 CHECK_ITERATOR(VPBB2
, I4
, I3
, I5
);