This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG][X86] Teach promotion legalization for fp_to_sint/fp_to_uint to insert an assertsext/assertzext based on the original type
ClosedPublic

Authored by craig.topper on Nov 28 2017, 5:15 PM.

Details

Summary

If we put in an assertsext/zext here, we're able to generate better truncate code using pack on pre-avx512 targets.

Similar is already done during type legalization. This is the equivalent for op legalization

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Nov 28 2017, 5:15 PM
RKSimon added inline comments.Nov 29 2017, 5:40 AM
lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
523 ↗(On Diff #124674)

Replace all the SDLoc(Op) cases with loc?

RKSimon edited edge metadata.Nov 29 2017, 12:21 PM

Just to double check - are we happy with the undefined behaviour here?

I'm wondering if out of range float2int could be a problem (e.g. f32 -> i8, but with a value of -512.0f) - yes its UB but does assertsext expect to still guarantee the sign/zero bits? I don't think so but wanted to be sure.

Here's the comment from the existing code

// Assert that the converted value fits in the original type.  If it doesn't
// (eg: because the value being converted is too big), then the result of the
// original operation was undefined anyway, so the assert is still correct.
//
// NOTE: fp-to-uint to fp-to-sint promotion guarantees zero extend. For example:
//   before legalization: fp-to-uint16, 65534. -> 0xfffe
//   after legalization: fp-to-sint32, 65534. -> 0x0000fffe
return DAG.getNode(N->getOpcode() == ISD::FP_TO_UINT ?
                   ISD::AssertZext : ISD::AssertSext, dl, NVT, Res,
                   DAG.getValueType(N->getValueType(0).getScalarType()));
RKSimon accepted this revision.Nov 29 2017, 2:02 PM

Thanks, I missed that. LGTM with the SDLoc cleanup

This revision is now accepted and ready to land.Nov 29 2017, 2:02 PM
This revision was automatically updated to reflect the committed changes.