This is an archive of the discontinued LLVM Phabricator instance.

[X86] Use a shorter sequence to implement FLT_ROUNDS
ClosedPublic

Authored by craig.topper on Jan 28 2020, 5:50 PM.

Details

Summary

This code needs to map from the FPCW 2-bit encoding for rounding mode to the 2-bit encoding defined for FLT_ROUNDS. The previous implementation did some clever swapping of bits and adding 1 modulo 4 to do the mapping.

This patch instead uses an 8-bit immediate as a lookup table of four 2-bit values. Then we use the 2-bit FPCW encoding to index the lookup table by using a right shift and an AND. This requires extracting the 2-bit value from FPCW and multipying it by 2 to make it usable as a shift amount. But still results in less code.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 28 2020, 5:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2020, 5:50 PM
Herald added a subscriber: hiraditya. · View Herald Transcript

Use MVT::i8 for a shift amount instead of MVT::i16. The DAG legalizer was fixing it anyway, but using MVT::i8 is more correct.

spatel accepted this revision.Jan 29 2020, 5:31 AM

LGTM

llvm/lib/Target/X86/X86ISelLowering.cpp
25430–25434

Nice hack. :)
We could use a code comment to explain this better:
0x2d --> (0b00,10,11,01) --> (0,2,3,1) >> FPSR[11:10]

This revision is now accepted and ready to land.Jan 29 2020, 5:31 AM
This revision was automatically updated to reflect the committed changes.