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

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 03:39:24 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Luke Lau (lukel97)

<details>
<summary>Changes</summary>

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
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);

``````````

</details>


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


More information about the llvm-commits mailing list