[X86] Type legalize v2i32 div/rem by scalarizing rather than promoting
authorCraig Topper <craig.topper@intel.com>
Thu, 13 Sep 2018 06:13:37 +0000 (06:13 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 13 Sep 2018 06:13:37 +0000 (06:13 +0000)
commitf107123a88fe010ad2695676278fc82668da7034
tree449a7b996fbf9c928ae9fdba5e2c8146af2a7651
parent091df9744ad6c9b26a88801c820fcd4ea58922ae
[X86] Type legalize v2i32 div/rem by scalarizing rather than promoting

Summary:
Previously we type legalized v2i32 div/rem by promoting to v2i64. But we don't support div/rem of vectors so op legalization would then scalarize it using i64 scalar ops since it doesn't know about the original promotion. 64-bit scalar divides on Intel hardware are known to be slow and in 32-bit mode they require a libcall.

This patch switches type legalization to do the scalarizing itself using i32.

It looks like the division by power of 2 optimization is still kicking in and leaving the code as a vector. The division by other constant optimization doesn't kick in pre type legalization since it ignores illegal types. And previously, after type legalization we scalarized the v2i64 since we don't have v2i64 MULHS/MULHU support.

Another option might be to widen v2i32 to v4i32 so we could do division by constant optimizations, but we'd have to be careful to only do that for constant divisors or we risk scalaring to 4 scalar divides.

Reviewers: RKSimon, spatel

Reviewed By: spatel

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D51325

llvm-svn: 342114
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/scalar_widen_div.ll
llvm/test/CodeGen/X86/vector-idiv-v2i32.ll