[llvm] [VPlan] Fix MayReadFromMemory/MayWriteToMemory on VPWidenIntrinsicRecipe (PR #136684)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 03:38:53 PDT 2025


https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/136684

These seem to be the wrong way round, e.g. see the definition at Instruction::mayReadFromMemory().
If an instruction only writes to memory then it's known to not read memory, and so on.

Only noticed this when using VPWidenIntrinsicRecipe in a local patch and wondered why it kept on getting DCEd despite the intrinsic writing to memory.


>From 5a33d2e1a8688ba53ac58449f0d42e09ae098c45 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Tue, 22 Apr 2025 18:33:59 +0800
Subject: [PATCH] [VPlan] Fix MayReadFromMemory/MayWriteToMemory on
 VPWidenIntrinsicRecipe

These seem to be the wrong way round, e.g. see the definition at Instruction::mayReadFromMemory().
If an instruction only writes to memory then it's known to not read memory, and so on.

Only noticed this when using VPWidenIntrinsicRecipe in a local patch and wondered why it kept on getting DCEd despite the intrinsic writing to memory.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 7084676af6d5b..1958502e5f8d3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1322,8 +1322,8 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
     LLVMContext &Ctx = Ty->getContext();
     AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
     MemoryEffects ME = Attrs.getMemoryEffects();
-    MayReadFromMemory = ME.onlyWritesMemory();
-    MayWriteToMemory = ME.onlyReadsMemory();
+    MayReadFromMemory = !ME.onlyWritesMemory();
+    MayWriteToMemory = !ME.onlyReadsMemory();
     MayHaveSideEffects = MayWriteToMemory ||
                          !Attrs.hasAttribute(Attribute::NoUnwind) ||
                          !Attrs.hasAttribute(Attribute::WillReturn);



More information about the llvm-commits mailing list