[llvm] [VPlan] Handle calls in VPInstruction:opcodeMayReadOrWriteFromMemory. (PR #190681)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 13:49:21 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/190681
Retrieve the called function and check its memory attributes, to determine if a VPInstruction calling a function reads or writes memory.
Use it to strengthen assert in areAllLoadsDereferenceable.
>From 568c2b78bfd9ec56ee876aa0536001c54e34fcf8 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Mon, 6 Apr 2026 21:45:27 +0100
Subject: [PATCH] [VPlan] Handle calls in
VPInstruction:opcodeMayReadOrWriteFromMemory.
Retrieve the called function and check its memory attributes, to
determine if a VPInstruction calling a function reads or writes memory.
Use it to strengthen assert in areAllLoadsDereferenceable.
---
llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp | 6 ++++--
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index c1df51841076f..2895d93c031ea 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -951,12 +951,14 @@ static bool areAllLoadsDereferenceable(VPBasicBlock *HeaderVPBB,
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_shallow(HeaderVPBB))) {
// Skip blocks outside the loop (exit blocks and their successors).
- if (VPBB == MiddleVPBB)
+ if (VPBB == MiddleVPBB || isa<VPIRBasicBlock>(VPBB))
continue;
for (VPRecipeBase &R : *VPBB) {
auto *VPI = dyn_cast<VPInstructionWithType>(&R);
- if (!VPI || VPI->getOpcode() != Instruction::Load)
+ if (!VPI || VPI->getOpcode() != Instruction::Load) {
+ assert(!R.mayReadFromMemory() && "unexpected recipe accessing memory");
continue;
+ }
// Get the pointer SCEV for dereferenceability checking.
VPValue *Ptr = VPI->getOperand(0);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index b496278ebd6ec..c584ecf39f797 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -1373,6 +1373,10 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
case VPInstruction::VScale:
case VPInstruction::Unpack:
return false;
+ case Instruction::Call:
+ return !cast<Function>(
+ cast<VPIRValue>(getOperand(getNumOperands() - 1))->getValue())
+ ->doesNotAccessMemory();
default:
return true;
}
More information about the llvm-commits
mailing list