[PATCH] D132960: [InstCombine] Transform small unaligned memcmp calls used in zero equality tests

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 11:00:35 PDT 2022


msebor created this revision.
msebor added reviewers: nikic, spatel, mcrosier.
Herald added subscribers: luke957, s.egerton, PkmX, atanasyan, simoncook, fedor.sergeev, hiraditya, arichardson, sdardis, jyknight.
Herald added a project: All.
msebor requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

The `memcmp` transformation of calls used in equality tests with zero is restricted to arrays of a power-of-two alignment and size, even though the middle end is capable of emitting efficient code for arrays that don't satisfy this restriction.  As a result, some `memcmp` calls result in less than optimal code for strictly aligned targets even with the subsequent optimization in `ExpandMemCmp.cpp`.

The proposed change relaxes the restriction in the simplifier, letting even calls with unaligned arrays whose size is not a power of two expand to a series of loads followed by a single comparison (up to the maximum scalar register size).  This might come with a small increase in the size of the emitted code, but in my testing with targets like `mips64`, `riscv64` and `sparcv9` the increase didn't seem excessive.  The change might also results in slightly different code for targets that don't penalize unaligned accesses (because it preempts the transformation in `ExpandMemCmp.cpp`) but based on inspection the resulting object code appears comparably optimal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132960

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/memcmp-9.ll
  llvm/test/Transforms/InstCombine/memcmp-constant-fold.ll
  llvm/test/Transforms/InstCombine/simplify-libcalls.ll
  llvm/test/Transforms/InstCombine/strcmp-memcmp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132960.456717.patch
Type: text/x-patch
Size: 51987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220830/00e6e7ce/attachment.bin>


More information about the llvm-commits mailing list