Skip to content

[VPlan] Fix MayReadFromMemory/MayWriteToMemory on VPWidenIntrinsicRecipe #136684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Apr 22, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Apr 22, 2025

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Luke Lau (lukel97)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/136684.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+2-2)
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);

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@lukel97 lukel97 merged commit 980531c into llvm:main Apr 22, 2025
14 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ipe (llvm#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.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ipe (llvm#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.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ipe (llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants