This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Enable strtol folding with nonnull endptr
ClosedPublic

Authored by msebor on Jul 12 2022, 2:03 PM.

Details

Summary

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 (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 once it's committed.)

Diff Detail

Event Timeline

msebor created this revision.Jul 12 2022, 2:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2022, 2:03 PM
msebor requested review of this revision.Jul 12 2022, 2:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2022, 2:04 PM
nikic accepted this revision.Jul 13 2022, 12:52 AM

LG

llvm/test/Transforms/InstCombine/str-int-2.ll
43

enptr -> endptr

52

i8** nonnull %pend would be more obvious?

This revision is now accepted and ready to land.Jul 13 2022, 12:52 AM
msebor retitled this revision from [InstCombine] Enable strtol folding with nonnull enptr to [InstCombine] Enable strtol folding with nonnull endptr.Jul 13 2022, 8:25 AM
msebor marked 2 inline comments as done.
This revision was landed with ongoing or failed builds.Jul 13 2022, 8:27 AM
This revision was automatically updated to reflect the committed changes.