This is an archive of the discontinued LLVM Phabricator instance.

Optimize printf calls that don't use 128-bit floating-point values
AcceptedPublic

Authored by sunfish on Feb 1 2019, 2:24 PM.

Details

Reviewers
sbc100
Summary

lib/Transforms/Utils/SimplifyLibCalls.cpp currently contains an optimization where it converts calls to printf that don't have any floating-point arguments into calls to iprintf, on targets which have it, which is like printf except without support for floating-point numbers. This allows programs that don't need floating-point formatting to avoid linking in the floating-point formatting code, which can save several thousands of bytes.

This patch adds a similar optimization for when there are floating-point arguments, but no 128-bit floating-point arguments, transforming such calls to printf_no_Lf (though I'm more than happy to accept suggestions for better names). Since 128-bit floats are implemented in software, printf_no_Lf can't be quite as small as iprintf, but it still can be significantly smaller than the full printf.

Diff Detail

Repository
rL LLVM

Event Timeline

sunfish created this revision.Feb 1 2019, 2:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2019, 2:24 PM
sbc100 added inline comments.Feb 1 2019, 3:13 PM
lib/Analysis/TargetLibraryInfo.cpp
157

This part is a separate and can be split out?

lib/Transforms/Utils/SimplifyLibCalls.cpp
2035

.. along with this?

sunfish planned changes to this revision.Feb 4 2019, 5:31 PM
sunfish marked 4 inline comments as done.
sunfish added inline comments.
lib/Analysis/TargetLibraryInfo.cpp
157

Ok.

lib/Transforms/Utils/SimplifyLibCalls.cpp
2035

Yes, this was a cleanup that isn't strictly required by the rest of the patch. I've now reverted these cleanups.

sunfish updated this revision to Diff 185203.Feb 4 2019, 5:33 PM
sunfish marked 2 inline comments as done.
  • Rename printf_no_Lf to __small_printf.
  • Add more tests.
  • Split out enabling the iprintf optimization for WASI, to be submitted in a separate patch later.
sbc100 added inline comments.Feb 5 2019, 5:08 AM
test/Transforms/InstCombine/fprintf-1.ll
5

Do we need signal that this test now requires the webassembly target?

sunfish marked 2 inline comments as done.Feb 5 2019, 5:57 AM
sunfish added inline comments.
test/Transforms/InstCombine/fprintf-1.ll
5

I don't think so; it doesn't need the whole target, just the triple. I assume this is why the test doesn't signal it needs XCore either, despite using it in the same way here.

sbc100 accepted this revision.Mar 25 2019, 3:24 PM
This revision is now accepted and ready to land.Mar 25 2019, 3:24 PM