80 lines · cpp
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-exception7//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 19namespace llvm {20 21namespace {22using VPPatternMatchTest = VPlanTestBase;23 24TEST_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 54TEST_F(VPPatternMatchTest, GetElementPtr) {55 VPlan &Plan = getPlan();56 VPBasicBlock *VPBB = Plan.createVPBasicBlock("entry");57 VPBuilder Builder(VPBB);58 59 IntegerType *I64Ty = IntegerType::get(C, 64);60 VPValue *One = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 1));61 VPValue *Two = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 2));62 VPValue *Ptr =63 Plan.getOrAddLiveIn(Constant::getNullValue(PointerType::get(C, 0)));64 65 VPInstruction *PtrAdd = Builder.createPtrAdd(Ptr, One);66 VPInstruction *WidePtrAdd = Builder.createWidePtrAdd(Ptr, Two);67 68 using namespace VPlanPatternMatch;69 ASSERT_TRUE(70 match(PtrAdd, m_GetElementPtr(m_Specific(Ptr), m_SpecificInt(1))));71 ASSERT_FALSE(72 match(PtrAdd, m_GetElementPtr(m_Specific(Ptr), m_SpecificInt(2))));73 ASSERT_TRUE(74 match(WidePtrAdd, m_GetElementPtr(m_Specific(Ptr), m_SpecificInt(2))));75 ASSERT_FALSE(76 match(WidePtrAdd, m_GetElementPtr(m_Specific(Ptr), m_SpecificInt(1))));77}78} // namespace79} // namespace llvm80