|
| 1 | +//===- llvm/unittests/Transforms/Vectorize/VPlanTransformsTest.cpp --------===// |
| 2 | +// |
| 3 | +// |
| 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 |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include "../lib/Transforms/Vectorize/VPlanTransforms.h" |
| 11 | +#include "../lib/Transforms/Vectorize/VPlan.h" |
| 12 | +#include "VPlanTestBase.h" |
| 13 | +#include "gtest/gtest.h" |
| 14 | + |
| 15 | +namespace llvm { |
| 16 | + |
| 17 | +namespace { |
| 18 | +using VPlanTransformsTest = VPlanTestBase; |
| 19 | + |
| 20 | +// Test we create and merge replicate regions: |
| 21 | +// VPBB1: |
| 22 | +// REPLICATE %Rep0 = add |
| 23 | +// REPLICATE %Rep1 = add |
| 24 | +// REPLICATE %Rep2 = add |
| 25 | +// No successors |
| 26 | +// |
| 27 | +// -> |
| 28 | +// |
| 29 | +// <xVFxUF> pred.add: { |
| 30 | +// pred.add.entry: |
| 31 | +// BRANCH-ON-MASK %Mask |
| 32 | +// Successor(s): pred.add.if, pred.add.continue |
| 33 | +// |
| 34 | +// pred.add.if: |
| 35 | +// REPLICATE %Rep0 = add |
| 36 | +// REPLICATE %Rep1 = add |
| 37 | +// REPLICATE %Rep2 = add |
| 38 | +// Successor(s): pred.add.continue |
| 39 | +// |
| 40 | +// pred.add.continue: |
| 41 | +// No successors |
| 42 | +// } |
| 43 | +TEST_F(VPlanTransformsTest, createAndOptimizeReplicateRegions) { |
| 44 | + VPlan &Plan = getPlan(); |
| 45 | + |
| 46 | + IntegerType *Int32 = IntegerType::get(C, 32); |
| 47 | + auto *AI = BinaryOperator::CreateAdd(PoisonValue::get(Int32), |
| 48 | + PoisonValue::get(Int32)); |
| 49 | + |
| 50 | + auto *VPBB0 = Plan.getEntry(); |
| 51 | + auto *VPBB1 = Plan.createVPBasicBlock("VPBB1"); |
| 52 | + VPRegionBlock *R1 = Plan.createVPRegionBlock(VPBB1, VPBB1, "R1"); |
| 53 | + VPBlockUtils::connectBlocks(VPBB0, R1); |
| 54 | + auto *Mask = new VPInstruction(0, {}); |
| 55 | + auto *Rep0 = new VPReplicateRecipe(AI, {}, false, Mask); |
| 56 | + auto *Rep1 = new VPReplicateRecipe(AI, {}, false, Mask); |
| 57 | + auto *Rep2 = new VPReplicateRecipe(AI, {}, false, Mask); |
| 58 | + VPBB1->appendRecipe(Rep0); |
| 59 | + VPBB1->appendRecipe(Rep1); |
| 60 | + VPBB1->appendRecipe(Rep2); |
| 61 | + |
| 62 | + VPlanTransforms::createAndOptimizeReplicateRegions(Plan); |
| 63 | + |
| 64 | + auto *Replicator = cast<VPRegionBlock>(R1->getEntry()->getSingleSuccessor()); |
| 65 | + EXPECT_TRUE(Replicator->isReplicator()); |
| 66 | + auto *ReplicatorEntry = cast<VPBasicBlock>(Replicator->getEntry()); |
| 67 | + EXPECT_EQ(ReplicatorEntry->size(), 1u); |
| 68 | + EXPECT_TRUE(isa<VPBranchOnMaskRecipe>(ReplicatorEntry->front())); |
| 69 | + auto *ReplicatorIf = cast<VPBasicBlock>(ReplicatorEntry->getSuccessors()[0]); |
| 70 | + EXPECT_EQ(ReplicatorIf->size(), 3u); |
| 71 | + EXPECT_EQ(ReplicatorEntry->getSuccessors()[1], |
| 72 | + ReplicatorIf->getSingleSuccessor()); |
| 73 | + EXPECT_EQ(ReplicatorIf->getSingleSuccessor(), Replicator->getExiting()); |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace |
| 77 | +} // namespace llvm |
0 commit comments