This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Codesize: don't expand SHIFT to SHIFT_PARTS
ClosedPublic

Authored by SjoerdMeijer on Jan 29 2019, 7:27 AM.

Details

Summary

And instead just generate a libcall. My motivating example on ARM was a simple:

  
shl i64 %A, %B

for which the code bloat is quite significant. For other targets that also
accept __int128/i128 such as AArch64 and X86, it also seems beneficial for these
cases to generate a libcall when optimising for minsize. On these 64-bit targets,
the 64-bits shifts are of course unaffected because the SHIFT/SHIFT_PARTS
lowering operation action is not set to custom/expand.

Diff Detail

Repository
rL LLVM

Event Timeline

SjoerdMeijer created this revision.Jan 29 2019, 7:27 AM
efriedma added inline comments.Jan 29 2019, 12:46 PM
lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
2775 ↗(On Diff #184085)

The optForMinSize check should probably be in target-specific code; yes, the call is smaller on all the popular targets I can think of, but that's a function of the specific opcodes available, not a general rule.

Thanks for reviewing!

The optForMinSize check should probably be in target-specific code

Agreed. I have created TLI.expandShift() to allow target-specific decision making.

lebedev.ri added inline comments.
include/llvm/CodeGen/TargetLowering.h
648 ↗(On Diff #184278)

It probably should be shouldExpandShift or something?
Just expandShift reads as "call this function to expand the shift operation"

It probably should be shouldExpandShift or something?

Yep, thanks, done.

This revision is now accepted and ready to land.Jan 30 2019, 11:28 AM
This revision was automatically updated to reflect the committed changes.
tcwang added a subscriber: tcwang.Mar 8 2019, 10:57 AM

Hi, we recently found this revision breaks Linux kernel (https://bugs.chromium.org/p/chromium/issues/detail?id=938985). Please advise us how to solve it. Thanks!

Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2019, 10:57 AM

We generally expect that code built using clang will link against compiler-rt or libgcc, even when targeting a freestanding environment. We aren't going to restrict that to only use the subset of compiler-rt functions Linux 4.4 built with some other compiler would use.