|
| 1 | +//===- llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.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/VPlanPatternMatch.h" |
| 11 | +#include "../lib/Transforms/Vectorize/LoopVectorizationPlanner.h" |
| 12 | +#include "../lib/Transforms/Vectorize/VPlan.h" |
| 13 | +#include "../lib/Transforms/Vectorize/VPlanHelpers.h" |
| 14 | +#include "VPlanTestBase.h" |
| 15 | +#include "llvm/IR/Instruction.h" |
| 16 | +#include "llvm/IR/Instructions.h" |
| 17 | +#include "gtest/gtest.h" |
| 18 | + |
| 19 | +namespace llvm { |
| 20 | + |
| 21 | +namespace { |
| 22 | +using VPPatternMatchTest = VPlanTestBase; |
| 23 | + |
| 24 | +TEST_F(VPPatternMatchTest, ScalarIVSteps) { |
| 25 | + VPlan &Plan = getPlan(); |
| 26 | + VPBasicBlock *VPBB = Plan.createVPBasicBlock(""); |
| 27 | + VPBuilder Builder(VPBB); |
| 28 | + |
| 29 | + IntegerType *I64Ty = IntegerType::get(C, 64); |
| 30 | + VPValue *StartV = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 0)); |
| 31 | + auto *CanonicalIVPHI = new VPCanonicalIVPHIRecipe(StartV, DebugLoc()); |
| 32 | + Builder.insert(CanonicalIVPHI); |
| 33 | + |
| 34 | + VPValue *Inc = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 1)); |
| 35 | + VPValue *VF = &Plan.getVF(); |
| 36 | + VPValue *Steps = Builder.createScalarIVSteps( |
| 37 | + Instruction::Add, nullptr, CanonicalIVPHI, Inc, VF, DebugLoc()); |
| 38 | + |
| 39 | + VPValue *Inc2 = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 2)); |
| 40 | + VPValue *Steps2 = Builder.createScalarIVSteps( |
| 41 | + Instruction::Add, nullptr, CanonicalIVPHI, Inc2, VF, DebugLoc()); |
| 42 | + |
| 43 | + using namespace VPlanPatternMatch; |
| 44 | + |
| 45 | + ASSERT_TRUE(match(Steps, m_ScalarIVSteps(m_Specific(CanonicalIVPHI), |
| 46 | + m_SpecificInt(1), m_Specific(VF)))); |
| 47 | + ASSERT_FALSE( |
| 48 | + match(Steps2, m_ScalarIVSteps(m_Specific(CanonicalIVPHI), |
| 49 | + m_SpecificInt(1), m_Specific(VF)))); |
| 50 | + ASSERT_TRUE(match(Steps2, m_ScalarIVSteps(m_Specific(CanonicalIVPHI), |
| 51 | + m_SpecificInt(2), m_Specific(VF)))); |
| 52 | +} |
| 53 | + |
| 54 | +} // namespace |
| 55 | +} // namespace llvm |
0 commit comments