[llvm] [Hexagon] Do not promote unaligned loop access to memmove. (PR #223936)
Nathan Corbyn via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 03:17:42 PDT 2026
================
@@ -231,6 +235,35 @@ InstructionCost HexagonTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
OpInfo, I);
}
+/* Do not promote loop access to memmove if source or destination
+ * array cannot be aligned to 8 byte boundary. memmove is beneficial
+ * only if source and destination are 8 byte aligned or memmove
+ * supports unaligned accesses. For example
+ * char a[100] ;
+ * for(i=n; i> 0; i--)
+ * a[i] = a[i-1];
+ * We can never align source and destination simultaneously at
+ * 8 byte boundary. If we convert this loop to memmove then
+ * memmove will do alignment checks and it fails so eventually
+ * do copy byte by byte. As a result, memmove will be relatively
+ * slow (due to call overhead and checks inside memmove)
+ * as compared to the loop access for unaligned accesses.*/
+
+bool HexagonTTIImpl::isMemmoveProfitable(
+ const std::optional<APInt> &PtrDiff) const {
+ if (HexagonEnableMemmove)
+ return true;
+
+ // Conservatively return false if we can't reason the difference between the
+ // pointers.
+ if (!PtrDiff)
+ return false;
+
+ // If the difference is not a multiple of 8, the pointers can never be
+ // simultaneously aligned to an 8-byte boundary.
+ return PtrDiff->getSExtValue() % 8 == 0;
----------------
cofibrant wrote:
Right, I was going to say. Checking the difference tells you essentially nothing about alignment. Not to mention, as this is a generic TTI hook, other platforms may be more interested in other properties of the actual pointers themselves (e.g., what address space they live in).
https://github.com/llvm/llvm-project/pull/223936
More information about the llvm-commits
mailing list