[all-commits] [llvm/llvm-project] 9b2fec: [BuildLibCalls][RISCV] Sign extend return value of...

Craig Topper via All-commits all-commits at lists.llvm.org
Tue Dec 20 11:47:39 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9b2fecec406d6a6bcda9fbb9251db2ae202c7400
      https://github.com/llvm/llvm-project/commit/9b2fecec406d6a6bcda9fbb9251db2ae202c7400
  Author: Craig Topper <craig.topper at sifive.com>
  Date:   2022-12-20 (Tue, 20 Dec 2022)

  Changed paths:
    M llvm/include/llvm/Analysis/TargetLibraryInfo.h
    M llvm/lib/Analysis/TargetLibraryInfo.cpp
    M llvm/lib/Transforms/Utils/BuildLibCalls.cpp
    A llvm/test/Transforms/InstCombine/RISCV/memcmp.ll

  Log Message:
  -----------
  [BuildLibCalls][RISCV] Sign extend return value of bcmp on riscv64.

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 signext attribute that
would have been present on the memcmp. 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.

See also the discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D139901




More information about the All-commits mailing list