This is an archive of the discontinued LLVM Phabricator instance.

[X86][SSE] Enable SMIN/SMAX/UMIN/UMAX custom lowering for all legal types
ClosedPublic

Authored by RKSimon on Feb 7 2018, 4:28 AM.

Details

Summary

This allows us to recognise more saturation patterns and also simplify some MINMAX codegen that was failing to simplify CMPGE comparisons to a legal CMPGT.

An alternative would be to allow SelectionDAGBuilder to always create MINMAX ops and improve the legalizers vector support - is an all-target solution something we'd want?

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Feb 7 2018, 4:28 AM
craig.topper added inline comments.Feb 8 2018, 10:25 PM
lib/Target/X86/X86ISelLowering.cpp
22023 ↗(On Diff #133196)

What if we can prove the sign bit is 0? Or do we already do that in some DAG combine?

RKSimon added inline comments.Feb 9 2018, 5:22 AM
lib/Target/X86/X86ISelLowering.cpp
22023 ↗(On Diff #133196)

We currently don't (we don't do much to combine integer MINMAX functions at all), but it's an easy fix in DAGCombine.

RKSimon updated this revision to Diff 133771.Feb 10 2018, 3:08 PM

Added UMIN/UMAX -> SMIN/SMAX combine

craig.topper added inline comments.Feb 10 2018, 3:17 PM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
3354 ↗(On Diff #133771)

Can we do this in reverse too? SMIN/SMAX->UMIN/UMAX?

RKSimon updated this revision to Diff 133777.Feb 10 2018, 4:31 PM

Added SMIN/SMAX -> UMIN/UMAX combine as well

RKSimon marked an inline comment as done.Feb 10 2018, 4:32 PM
craig.topper accepted this revision.Feb 10 2018, 6:32 PM

LGTM other than that question about MVT::v16i8

lib/Target/X86/X86ISelLowering.cpp
22023 ↗(On Diff #133196)

Does this trick also work in reverse for MVT::v16i8?

This revision is now accepted and ready to land.Feb 10 2018, 6:32 PM
RKSimon added inline comments.Feb 11 2018, 2:26 AM
lib/Target/X86/X86ISelLowering.cpp
22023 ↗(On Diff #133196)

Technically yes - but the current codegen of PCMPGTB/AND/ANDN/OR gives the same number of instructions and avoids the signmask constant. The main use of this sign flip trick is that it removes the unsigned integer compare.

This revision was automatically updated to reflect the committed changes.
llvm/trunk/test/CodeGen/X86/vector-trunc-ssat.ll