This is an archive of the discontinued LLVM Phabricator instance.

[X86][SSE] Reimplement SSE fp2si conversion intrinsics instead of using generic IR
ClosedPublic

Authored by RKSimon on Jul 7 2016, 11:50 AM.

Details

Summary

D20859 and D20860 attempted to replace the SSE (V)CVTTPS2DQ and VCVTTPD2DQ truncating conversions with generic IR instead.

It turns out that the behaviour of these intrinsics is different enough from generic IR that this will cause problems, INF/NAN/out of range values are guaranteed to result in a 0x80000000 value - which plays havoc with constant folding which converts them to either zero or UNDEF. This is also an issue with the scalar implementations (which were already generic IR and what I was trying to match).

This patch changes both scalar and packed versions back to using x86-specific builtins.

It also deals with the other scalar conversion cases that are runtime rounding mode dependent and can have similar issues with constant folding.

A companion llvm patch will be submitted shortly.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 63108.Jul 7 2016, 11:50 AM
RKSimon retitled this revision from to [X86][SSE] Reimplement SSE fp2si conversion intrinsics instead of using generic IR.
RKSimon updated this object.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added a subscriber: cfe-commits.
eli.friedman edited edge metadata.Jul 19 2016, 10:16 AM

I don't think we need to use x86-specific operations for sitofp-like conversions; the C cast is equivalent given that a 32 or 64-bit integer is always in within the range of a 32-bit float.

I don't think we need to use x86-specific operations for sitofp-like conversions; the C cast is equivalent given that a 32 or 64-bit integer is always in within the range of a 32-bit float.

I think the only situation that lossless conversion occurs is i32->f64, every other sitofp conversion could be affected by the rounding control no?

The x86-specific operation is affected by the rounding mode... but so is a C cast. This is specified by Annex F in the C standard.

Of course, you're going to end up with undefined behavior if you actually modify the rounding mode because LLVM and clang don't support FENV_ACCESS at the moment.

The x86-specific operation is affected by the rounding mode... but so is a C cast. This is specified by Annex F in the C standard.

Of course, you're going to end up with undefined behavior if you actually modify the rounding mode because LLVM and clang don't support FENV_ACCESS at the moment.

OK I'm going to pull the sitofp conversions from this patch - I have other concerns about them (i.e. we don't treat scalar + vector the same) that will need to be looked at as well.

RKSimon updated this revision to Diff 64534.Jul 19 2016, 11:57 AM
RKSimon edited edge metadata.

Removed sitofp conversion changes

eli.friedman accepted this revision.Jul 19 2016, 12:13 PM
eli.friedman edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Jul 19 2016, 12:13 PM
This revision was automatically updated to reflect the committed changes.