[llvm] [ExpandMemCmp][RISCV] Expand memcmp/bcmp for aligned pointers on strict-align targets (PR #209738)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 01:53:20 PDT 2026
================
@@ -3630,23 +3630,30 @@ bool RISCVTTIImpl::isProfitableToSinkOperands(
RISCVTTIImpl::TTI::MemCmpExpansionOptions
RISCVTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
TTI::MemCmpExpansionOptions Options;
- // TODO: Enable expansion when unaligned access is not supported after we fix
- // issues in ExpandMemcmp.
- if (!ST->enableUnalignedScalarMem())
- return Options;
if (!ST->hasStdExtZbb() && !ST->hasStdExtZbkb() && !IsZeroCmp)
return Options;
- Options.AllowOverlappingLoads = true;
+ // Even if the target does not support unaligned scalar memory access,
+ // expansion is still possible when both pointers are statically known to be
+ // sufficiently aligned. ExpandMemCmp queries the target for each load size
+ // and keeps only the ones the target can actually access at the known
+ // per-call-site alignment, falling back to the libcall when none fits.
+ // Overlapping loads and merged tail expansions produce accesses that need
+ // not be naturally aligned, so they are only offered when unaligned scalar
+ // access is supported.
+ bool UnalignedScalar = ST->enableUnalignedScalarMem();
+ Options.AllowOverlappingLoads = UnalignedScalar;
----------------
wangpc-pp wrote:
Yeah I agree. I did a quick fix and it is more complicated than I thought. I can fix it in a follow-up.
https://github.com/llvm/llvm-project/pull/209738
More information about the llvm-commits
mailing list