diff options
author | Heejin Ahn <aheejin@gmail.com> | 2018-04-27 22:23:11 +0000 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2018-04-27 22:23:11 +0000 |
commit | d20d0648ed65eb13a133ae871a649a28add04717 (patch) | |
tree | 94e9c1de92045c41eff9aac17b388f8fe1658b02 /llvm/lib/CodeGen | |
parent | d656410293d4aacd2dad3e0038032b03d84eb140 (diff) | |
download | bcm5719-llvm-d20d0648ed65eb13a133ae871a649a28add04717.tar.gz bcm5719-llvm-d20d0648ed65eb13a133ae871a649a28add04717.zip |
[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
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9558cb8ee00..aefccd2e365 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2887,6 +2887,13 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) { unsigned Idx = EltIndex++; if (C->isNullValue() || C->isOpaque()) return false; + // The instruction sequence to be generated contains shifting C by (op size + // in bits - # of trailing zeros in C), which results in an undef value when + // C == 1. (e.g. if the op size in bits is 32, it will be (sra x , 32) if C + // == 1) + if (C->getAPIntValue().isOneValue()) + return false; + if (C->getAPIntValue().isPowerOf2()) return true; if ((-C->getAPIntValue()).isPowerOf2()) { |