[DAGCombiner] Fix a case of 1 in non-splat vector pow2 divisor
authorHeejin Ahn <aheejin@gmail.com>
Fri, 27 Apr 2018 22:23:11 +0000 (22:23 +0000)
committerHeejin Ahn <aheejin@gmail.com>
Fri, 27 Apr 2018 22:23:11 +0000 (22:23 +0000)
commitd20d0648ed65eb13a133ae871a649a28add04717
tree94e9c1de92045c41eff9aac17b388f8fe1658b02
parentd656410293d4aacd2dad3e0038032b03d84eb140
[DAGCombiner] Fix a case of 1 in non-splat vector pow2 divisor

Summary:
D42479 (rL329525) enabled SDIV combine for pow2 non-splat vector
dividers. But when there is a 1 in a vector, the instruction sequence to
be generated involves shifting a value by the number of its bit widths,
which is undefined
(https://github.com/llvm-mirror/llvm/blob/c64f4dbfe31e509f9c1092b951e524b056245af8/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L6000-L6006).

Especially, in architectures that do not support vector instructions,
each of element in a vector will be computed separately using scalar
operations, and then the resulting value will be undef for '1' values
in a vector.

(All 1's vector is fine; only vectors mixed with 1 and others will be
affected.)

Reviewers: RKSimon, jgravelle-google

Subscribers: jfb, dschuff, sbc100, jgravelle-google, llvm-commits

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

llvm-svn: 331092
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/WebAssembly/vector_sdiv.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/combine-sdiv.ll