This is an archive of the discontinued LLVM Phabricator instance.

Adding support for TargetLoweringBase::LibCall
ClosedPublic

Authored by tyomitch on Oct 19 2015, 5:49 AM.

Details

Summary

TargetLoweringBase::Expand is defined as "Try to expand this to other ops,
otherwise use a libcall." For ISD::UDIV and ISD::SDIV, the choice between
the two possibilities was defined in a rather convoluted way:

  • if DIVREM is legal, expand to DIVREM
  • if DIVREM has a custom lowering, expand to DIVREM
  • if DIVREM libcall is defined and a remainder from the same division is computed elsewhere, expand to a DIVREM libcall
  • else, expand to a DIV libcall

This had the undesirable effect that if both DIV and DIVREM are implemented
as libcalls, then ISD::UDIV and ISD::SDIV are expanded to the heavier DIVREM
libcall, even when the remainder isn't used.

The new code adds a new LegalizeAction, TargetLoweringBase::LibCall, so that
backends can directly control whether they prefer an expansion or a conversion
to a libcall. This makes the generic lowering code even more generic,
allowing its reuse in a wider range of target-specific configurations.

The useful effect is that ARM backend will now generate a call
to aeabi_{i,u}div rather than aeabi_{i,u}divmod in cases where
it doesn't need the remainder. There's no functional change outside
the ARM backend.

Diff Detail

Repository
rL LLVM

Event Timeline

tyomitch updated this revision to Diff 37743.Oct 19 2015, 5:49 AM
tyomitch retitled this revision from to Adding support for TargetLoweringBase::LibCall.
tyomitch updated this object.
tyomitch added a reviewer: rengolin.
tyomitch added a subscriber: llvm-commits.
t.p.northover accepted this revision.Oct 19 2015, 2:58 PM
t.p.northover added a reviewer: t.p.northover.
t.p.northover added a subscriber: t.p.northover.

This looks reasonable to me.

Tim.

This revision is now accepted and ready to land.Oct 19 2015, 2:58 PM
rengolin edited edge metadata.Oct 20 2015, 4:58 AM

Hi Artyom,

I like this idea a lot. It allows for more flexibility and explicitly states the hierarchy we want, Legal > Expand > Libcall.

LGTM, too. Thanks!

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
150 ↗(On Diff #37743)

These two are intrinsically related in the lowering phase, and would be good to have some comments to that effect here, so people can understand without searching for the implementation details.

This revision was automatically updated to reflect the committed changes.