[SimplifyLibCalls] Use inbounds GEP
authorNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:27:38 +0000 (14:27 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:31:44 +0000 (14:31 +0200)
commitfabe915705472e2c06ed1aa9a90620462594e82f
treeb81d9cad2b8ee9f11e162c04f0d1423965822611
parentab372cdd6ff4e6ccb1fdd83a421914cddfb30e58
[SimplifyLibCalls] Use inbounds GEP

When converting strchr(p, '\0') to p + strlen(p) we know that
strlen() must return an offset that is inbounds of the allocated
object (otherwise it would be UB), so we can use an inbounds GEP.
An equivalent argument can be made for the other cases.
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/memrchr-4.ll
llvm/test/Transforms/InstCombine/memset_chk-1.ll
llvm/test/Transforms/InstCombine/snprintf.ll
llvm/test/Transforms/InstCombine/sprintf-1.ll
llvm/test/Transforms/InstCombine/strchr-1.ll
llvm/test/Transforms/InstCombine/strncat-2.ll