
783a846 changed VPScalarIVStepsRecipe to take 3 arguments (adding VF explicitly) instead of 2, but didn't change the corresponding pattern matcher. This matcher was only used in vputils::isHeaderMask, and no test ever reached that function with a ScalarIVSteps recipe for the value being matched -- it was always a WideCanonicalIV. So the matcher bailed out immediately before checking arguments and asserting that the number of arguments in the recipe was the same provided by the matcher. Since the constructors for ScalarIVSteps take 3 values, we should be safe to update the matcher and guard it with a dedicated gtest. m_CanonicalIV() on the other hand is removed; as a phi recipe it may not have a consistent number of arguments to match, only requiring one (the start value) when being constructed with the assumption that a second incoming value is added for the backedge later. In order to keep the matcher we would need to add multiple matchers with different numbers of arguments for it depending on what phase of vplan construction we were in, and ensure that we never reorder matcher usage vs. vplan transformation. Since the main IR PatternMatch.h doesn't contain any matchers for PHI nodes, I think we can just remove it and match via m_Specific() using the VPValue we get from Plan.getCanonicalIV().
56 lines
2.1 KiB
C++
56 lines
2.1 KiB
C++
//===- llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp ------===//
|
|
//
|
|
//
|
|
// 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 "../lib/Transforms/Vectorize/VPlanPatternMatch.h"
|
|
#include "../lib/Transforms/Vectorize/LoopVectorizationPlanner.h"
|
|
#include "../lib/Transforms/Vectorize/VPlan.h"
|
|
#include "../lib/Transforms/Vectorize/VPlanHelpers.h"
|
|
#include "VPlanTestBase.h"
|
|
#include "llvm/IR/Instruction.h"
|
|
#include "llvm/IR/Instructions.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace llvm {
|
|
|
|
namespace {
|
|
using VPPatternMatchTest = VPlanTestBase;
|
|
|
|
TEST_F(VPPatternMatchTest, ScalarIVSteps) {
|
|
VPlan &Plan = getPlan();
|
|
VPBasicBlock *VPBB = Plan.createVPBasicBlock("");
|
|
VPBuilder Builder(VPBB);
|
|
|
|
IntegerType *I64Ty = IntegerType::get(C, 64);
|
|
VPValue *StartV = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 0));
|
|
auto *CanonicalIVPHI = new VPCanonicalIVPHIRecipe(StartV, DebugLoc());
|
|
Builder.insert(CanonicalIVPHI);
|
|
|
|
VPValue *Inc = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 1));
|
|
VPValue *VF = &Plan.getVF();
|
|
VPValue *Steps = Builder.createScalarIVSteps(
|
|
Instruction::Add, nullptr, CanonicalIVPHI, Inc, VF, DebugLoc());
|
|
|
|
VPValue *Inc2 = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 2));
|
|
VPValue *Steps2 = Builder.createScalarIVSteps(
|
|
Instruction::Add, nullptr, CanonicalIVPHI, Inc2, VF, DebugLoc());
|
|
|
|
using namespace VPlanPatternMatch;
|
|
|
|
ASSERT_TRUE(match(Steps, m_ScalarIVSteps(m_Specific(CanonicalIVPHI),
|
|
m_SpecificInt(1), m_Specific(VF))));
|
|
ASSERT_FALSE(
|
|
match(Steps2, m_ScalarIVSteps(m_Specific(CanonicalIVPHI),
|
|
m_SpecificInt(1), m_Specific(VF))));
|
|
ASSERT_TRUE(match(Steps2, m_ScalarIVSteps(m_Specific(CanonicalIVPHI),
|
|
m_SpecificInt(2), m_Specific(VF))));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace llvm
|