[llvm] [VPlan] Compute SCEV for ptrtoaddr. (PR #219848)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 13:49:35 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/219848
SCEV models ptrtoaddr via getPtrToAddrExpr. Mirror that in getSCEVExprForVPValue. ptrtoint stays unmodelled, as createSCEV returns an unknown for it.
Adds m_PtrToAddr to VPlanPatternMatch.
>From 13ceb15559c7fc3ee63463d2c1ebe5f0ed26ab0e Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Sun, 30 Aug 2026 19:49:48 +0100
Subject: [PATCH] [VPlan] Compute SCEV for ptrtoaddr.
SCEV models ptrtoaddr via getPtrToAddrExpr. Mirror that in
getSCEVExprForVPValue. ptrtoint stays unmodelled, as createSCEV returns an
unknown for it.
getPtrToAddrExpr returns CouldNotCompute for address spaces with an unstable
pointer representation, which propagates out of this helper unchanged and
leaves the access scalarized.
Adds m_PtrToAddr to VPlanPatternMatch.
---
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 6 ++++++
llvm/lib/Transforms/Vectorize/VPlanUtils.cpp | 5 +++++
2 files changed, 11 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index edfa29e5c625d..28b8f5e9429ed 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -559,6 +559,12 @@ inline AllRecipe_match<Instruction::FPExt, Op0_t> m_FPExt(const Op0_t &Op0) {
return m_Unary<Instruction::FPExt, Op0_t>(Op0);
}
+template <typename Op0_t>
+inline AllRecipe_match<Instruction::PtrToAddr, Op0_t>
+m_PtrToAddr(const Op0_t &Op0) {
+ return m_Unary<Instruction::PtrToAddr, Op0_t>(Op0);
+}
+
template <typename Op0_t>
inline AllRecipe_match<Instruction::FNeg, Op0_t> m_FNeg(const Op0_t &Op0) {
return m_Unary<Instruction::FNeg, Op0_t>(Op0);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 58e221765b7b7..f9550ebaf15a8 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -232,6 +232,11 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
return SE.getURemExpr(Ops[0], SE.getConstant(*Mask + 1));
});
+ // SCEV models ptrtoaddr, but not ptrtoint, mirroring createSCEV.
+ if (match(V, m_PtrToAddr(m_VPValue(LHSVal))))
+ return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
+ return SE.getPtrToAddrExpr(Ops[0]);
+ });
if (match(V, m_Trunc(m_VPValue(LHSVal)))) {
Type *DestTy = V->getScalarType();
return CreateSCEV({LHSVal}, [&](ArrayRef<SCEVUse> Ops) {
More information about the llvm-commits
mailing list