This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes] Avoid promotion of exponent in FPOWI
ClosedPublic

Authored by bjope on May 21 2021, 3:26 PM.

Details

Summary

The FPOWI DAG node is normally lowered to a libcall to one of the
RTLIB::POWI* runtime functions and the exponent should normally
have a type matching sizeof(int) when making the call. Thus,
type promotion of the exponent could lead to an FPOWI with a type
for the second operand that would be incorrect when doing the
libcall (a situation which would be hard to detect post-legalization
if we allow such FPOWI nodes).

This patch is changing DAGTypeLegalizer::PromoteIntOp_FPOWI to
do the rewrite into a libcall directly instead of promoting the
operand. This way we can check that the exponent is smaller than
sizeof(int) and we can let TargetLowering handle promotion as
part of making the libcall. It could be noticed here that makeLibCall
has some knowledge about targets such as 64-bit RISCV, for which the
libcall argument should be extended to a type larger than sizeof(int).

Diff Detail

Event Timeline

bjope created this revision.May 21 2021, 3:26 PM
bjope requested review of this revision.May 21 2021, 3:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2021, 3:26 PM

Yes, this is what I was looking for.

Can we share the code for computing the fpowi libcall name etc. with DAGTypeLegalizer::SoftenFloatRes_FPOWI?

craig.topper added inline comments.May 21 2021, 3:48 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
1990–2027

Can you add an assert that N->getOpcode() is FPOWI and add a FIXME that we need to support STRICT_FPOWI? RISCV doesn't support strict FP yet.

bjope updated this revision to Diff 347509.May 24 2021, 2:43 PM

Added assert related to lack of support to promote int op for STRICT_FPOWI
in PromoteIntOp_FPOWI.

bjope added a comment.May 24 2021, 2:46 PM

Yes, this is what I was looking for.

Can we share the code for computing the fpowi libcall name etc. with DAGTypeLegalizer::SoftenFloatRes_FPOWI?

Made some refactoring in a separate commit: https://reviews.llvm.org/D103050 (If you rather think I should squash it into this patch I can do that.)

efriedma accepted this revision.Jun 1 2021, 7:11 AM

LGTM

This revision is now accepted and ready to land.Jun 1 2021, 7:11 AM
This revision was landed with ongoing or failed builds.Jun 2 2021, 2:42 AM
This revision was automatically updated to reflect the committed changes.