Skip to content

Commit cbf36e2

Browse files
committed
[VPlan/PatternMatch] Fix m_GetElementPtr (NFC)
The m_GetElementPtr matcher is incorrect and incomplete. Fix it to match all possible GEPs to avoid misleading users. It currently just has one use, and the change is non-functional for that use.
1 parent 9e1d656 commit cbf36e2

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,9 @@ class LLVM_ABI_FOR_TEST VPWidenGEPRecipe : public VPRecipeWithIRFlags {
17991799

18001800
VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
18011801

1802+
/// This recipe generates a GEP instruction.
1803+
unsigned getOpcode() const { return Instruction::GetElementPtr; }
1804+
18021805
/// Generate the gep nodes.
18031806
void execute(VPTransformState &State) override;
18041807

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ struct Recipe_match {
252252
static bool matchRecipeAndOpcode(const VPRecipeBase *R) {
253253
auto *DefR = dyn_cast<RecipeTy>(R);
254254
// Check for recipes that do not have opcodes.
255-
if constexpr (std::is_same<RecipeTy, VPScalarIVStepsRecipe>::value ||
256-
std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
257-
std::is_same<RecipeTy, VPDerivedIVRecipe>::value ||
258-
std::is_same<RecipeTy, VPWidenGEPRecipe>::value)
255+
if constexpr (std::is_same_v<RecipeTy, VPScalarIVStepsRecipe> ||
256+
std::is_same_v<RecipeTy, VPCanonicalIVPHIRecipe> ||
257+
std::is_same_v<RecipeTy, VPDerivedIVRecipe> ||
258+
std::is_same_v<RecipeTy, VPVectorPointerRecipe>)
259259
return DefR;
260260
else
261261
return DefR && DefR->getOpcode() == Opcode;
@@ -524,15 +524,25 @@ m_SpecificCmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
524524
}
525525

526526
template <typename Op0_t, typename Op1_t>
527-
using GEPLikeRecipe_match =
527+
using GEPLikeRecipe_match = match_combine_or<
528528
Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
529-
/*Commutative*/ false, VPWidenRecipe, VPReplicateRecipe,
530-
VPWidenGEPRecipe, VPInstruction>;
529+
/*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe,
530+
VPVectorPointerRecipe>,
531+
match_combine_or<
532+
VPInstruction_match<VPInstruction::PtrAdd, Op0_t, Op1_t>,
533+
VPInstruction_match<VPInstruction::WidePtrAdd, Op0_t, Op1_t>>>;
531534

532535
template <typename Op0_t, typename Op1_t>
533536
inline GEPLikeRecipe_match<Op0_t, Op1_t> m_GetElementPtr(const Op0_t &Op0,
534537
const Op1_t &Op1) {
535-
return GEPLikeRecipe_match<Op0_t, Op1_t>(Op0, Op1);
538+
return m_CombineOr(
539+
Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
540+
/*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe,
541+
VPVectorPointerRecipe>(Op0, Op1),
542+
m_CombineOr(
543+
VPInstruction_match<VPInstruction::PtrAdd, Op0_t, Op1_t>(Op0, Op1),
544+
VPInstruction_match<VPInstruction::WidePtrAdd, Op0_t, Op1_t>(Op0,
545+
Op1)));
536546
}
537547

538548
template <typename Op0_t, typename Op1_t, typename Op2_t>

0 commit comments

Comments
 (0)