[llvm] [RISCV] Expand memcmp/bcmp for statically-aligned pointers on strict-align targets (PR #209738)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 03:45:01 PDT 2026


================
@@ -860,6 +860,31 @@ static bool expandMemCmp(CallInst *CI, const TargetTransformInfo *TTI,
   if (!OptForSize && MaxLoadsPerMemcmp.getNumOccurrences())
     Options.MaxNumLoads = MaxLoadsPerMemcmp;
 
+  if (Options.RequireNaturalAlignment) {
+    // The target can only perform naturally aligned loads. Keep the load sizes
+    // that are powers of two and no larger than the statically known alignment
+    // of both pointers. Because the greedy load sequence only places a load of
+    // size S at an offset that is a multiple of S, a power-of-two load that
+    // does not exceed the base alignment is guaranteed to be naturally aligned.
+    // Overlapping loads and merged tail expansions can produce unaligned or
+    // non-power-of-two accesses, so they are not used in this mode.
+    Options.AllowOverlappingLoads = false;
+    Options.AllowedTailExpansions.clear();
+    const Align LhsAlign = CI->getArgOperand(0)->getPointerAlignment(*DL);
+    const Align RhsAlign = CI->getArgOperand(1)->getPointerAlignment(*DL);
----------------
wangpc-pp wrote:

Done in https://github.com/llvm/llvm-project/pull/209738/commits/6807271d08c27a22974891d67f85faefb968172f.

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


More information about the llvm-commits mailing list