[PATCH] D129593: [InstCombine] Enable strtol folding with nonnull enptr

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 14:04:01 PDT 2022


msebor created this revision.
msebor added reviewers: efriedma, xbolva00, nikic.
Herald added subscribers: jsji, pengfei, hiraditya.
Herald added a project: All.
msebor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The `strtol` folding is conditional on the second argument, `endptr`, being a constant null pointer. However, since the idiomatic use case is to pass the function the address of a local `end` pointer as `endptr`, this restriction prevents the folding from taking place in the common case when the pointer is known not to be null.

Not having been able to find a rationale for this decision in D45418 <https://reviews.llvm.org/D45418> (only tests), this change enables the folding also for `endptr` that's known to be nonnull by having the folder store the address of the nul character in `*endptr`.  It stops short of attempting to handle arbitrary pointers since I suspect the cases where nothing is known about the pointer are rare.

Tested on x86_64-linux.

(This patch will need to be rebased on top of D129224 <https://reviews.llvm.org/D129224> once it's committed.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129593

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/str-int-2.ll
  llvm/test/Transforms/InstCombine/str-int.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129593.444052.patch
Type: text/x-patch
Size: 5446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220712/15c78962/attachment.bin>


More information about the llvm-commits mailing list