[llvm] [SelectionDAG] Update MemOp to distinguish memmove from memcpy (PR #206005)
Ömer Sinan Ağacan via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 01:30:12 PDT 2026
================
@@ -168,19 +182,25 @@ struct MemOp {
return DstAlign;
}
bool isFixedDstAlign() const { return !DstAlignCanChange; }
- bool allowOverlap() const { return AllowOverlap; }
- bool isMemset() const { return IsMemset; }
- bool isMemcpy() const { return !IsMemset; }
- bool isMemcpyWithFixedDstAlign() const {
- return isMemcpy() && !DstAlignCanChange;
+ bool allowOverlap() const { return !IsVolatile; }
+ bool isMemset() const {
+ return Kind == MemOpKind::Memset || Kind == MemOpKind::MemsetWithZero;
+ }
+ bool isMemcpy() const {
+ return Kind == MemOpKind::Memcpy || Kind == MemOpKind::MemcpyStrSrc;
+ }
+ bool isMemmove() const { return Kind == MemOpKind::Memmove; }
+ bool isMemcpyOrMemmove() const { return isMemcpy() || isMemmove(); }
+ bool isMemcpyOrMemmoveWithFixedDstAlign() const {
+ return isMemcpyOrMemmove() && !DstAlignCanChange;
}
- bool isZeroMemset() const { return isMemset() && ZeroMemset; }
+ bool isZeroMemset() const { return Kind == MemOpKind::MemsetWithZero; }
bool isMemcpyStrSrc() const {
- assert(isMemcpy() && "Must be a memcpy");
- return MemcpyStrSrc;
+ assert(isMemcpyOrMemmove() && "Must be a memcpy or memmove");
+ return Kind == MemOpKind::MemcpyStrSrc;
----------------
osa1 wrote:
I think it makes sense to keep the assertion unless we fully understand what it's protecting against and we know it's no longer necessary.
It's also not causing any issues currently and if it does in the future, it's easy to just remove them. OTOH adding it back can be more difficult if we remove it now (as it can break users and require refactoring).
Also the enum part of this PR is really an internal change, the API of the `MemOp` is still the same: you have constructors for the operations and the `is...` methods, just with more details now. So you use it similarly and you can misuse it the same way as before (e.g. create a `MemOp` for a `memset` and ask whether it's copying from a constant with `isMemcpyStrSrc`). So it makes sense to keep the assertions in the public methods of the type as it can be misused the same way as before.
https://github.com/llvm/llvm-project/pull/206005
More information about the llvm-commits
mailing list