This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add DAG combine to combine a v8i32->v8i16 truncate with a packuswb that truncates v8i16->v8i8.
ClosedPublic

Authored by craig.topper on Nov 22 2018, 11:57 AM.

Details

Summary

Under -x86-experimental-vector-widening-legalization, fp_to_uint/fp_to_sint with a smaller than 128 bit vector type results are custom type legalized by promoting the result to a 128 bit vector by promoting the elements, inserting an assertzext/assertsext, then truncating back to original type. The truncate will be further legalizdd to a pack shuffle. In the case of a v8i8 result type, we'll end up with a v8i16 fp_to_sint. This will need to be further legalized during vector op legalization by promoting to v8i32 and then truncating again. Under avx2 this produces good code with two pack instructions, but Under avx512 this will result in a truncate instruction and a packuswb instruction. But we should be able to get away with a single truncate instruction.

The other option is to promote all the way to vXi32 result type during the first type legalization. But in some experimentation that seemed to require more work to produce good code for other configurations.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Nov 22 2018, 11:57 AM

Add a DAG combine to avoid this failing after r347593. Since we now have an AssertSExt and a stronger AssertZExt sandwiched around the truncate.

craig.topper marked an inline comment as done.Nov 26 2018, 2:19 PM
craig.topper added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
9082 ↗(On Diff #175340)

I wonder if we could just float all Asserts above truncates? And more aggressively merge adjacent asserts?

RKSimon added inline comments.Dec 2 2018, 2:32 AM
lib/Target/X86/X86ISelLowering.cpp
35383 ↗(On Diff #175340)

Can the PACKSS equivalent occur as well?

craig.topper marked an inline comment as done.Dec 2 2018, 11:11 AM
craig.topper added inline comments.
lib/Target/X86/X86ISelLowering.cpp
35383 ↗(On Diff #175340)

It doesn't occur in any of our lit tests so I'm not sure.

RKSimon accepted this revision.Dec 3 2018, 12:00 AM

LGTM with one minor, cheers.

lib/Target/X86/X86ISelLowering.cpp
35383 ↗(On Diff #175340)

OK - please can you add a TODO comment for now?

This revision is now accepted and ready to land.Dec 3 2018, 12:00 AM
This revision was automatically updated to reflect the committed changes.