[InstCombine] Transform strrchr to memrchr for constant strings
authorMartin Sebor <msebor@redhat.com>
Fri, 1 Jul 2022 16:09:42 +0000 (10:09 -0600)
committerMartin Sebor <msebor@redhat.com>
Fri, 1 Jul 2022 17:10:00 +0000 (11:10 -0600)
commit0d68ff87d2b03522ac43646a491d731586518e4c
tree9f2e7c47b9550a87413668ceb6a3b30e8e548b8c
parent554aea52d79ebd9353911ecf2ffe14aca132f452
[InstCombine] Transform strrchr to memrchr for constant strings

Add an emitter for the memrchr common extension and simplify the strrchr
call handler to use it. This enables transforming calls with the empty
string to the test C ? S : 0.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D128954
llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/strcall-no-nul.ll
llvm/test/Transforms/InstCombine/strrchr-1.ll
llvm/test/Transforms/InstCombine/strrchr-3.ll [new file with mode: 0644]