[PATCH] D139901: [BuildLibCalls] Sign extend return value of bcmp on riscv64.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 17:44:42 PST 2022


craig.topper created this revision.
craig.topper added reviewers: efriedma, jyknight, asb, luismarques, reames, kito-cheng, jonpa.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

riscv64 wants callees to sign extend signed and unsigned int returns.

The caller can use this to avoid a sign extend if the result is
used by a comparison since riscv64 only has 64-bit compares.

InstCombine/SimplifyLibCalls aggressively turn memcmps that are only
used by an icmp eq 0 into bcmp, but we lose the sext attribute that
would have been present on the bcmp. This causes an unneeded sext.w
in the generated assembly.

This looks even sillier if bcmp is implemented alias to memcmp. In
that case, not only did we not get any savings by using bcmp, we added
an instruction.

This probably applies to other functions, this just happens to be
the one I noticed so far.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139901

Files:
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/test/Transforms/InstCombine/RISCV/memcmp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139901.482325.patch
Type: text/x-patch
Size: 6138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221213/5f05a043/attachment.bin>


More information about the llvm-commits mailing list