[DAGCombiner] Try to use SelectionDAG::isKnownToBeAPowerOfTwo instead of just APInt...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 14 Dec 2016 15:08:13 +0000 (15:08 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 14 Dec 2016 15:08:13 +0000 (15:08 +0000)
commit05ab8ffc7ec8124fd612ba13d93c58951bff4a0c
tree756ff63bd1b696eda59597aabb02baeebbfb7b09
parent1ce2a23a1e22b7ceded0c989fc7b79da05cfe9bb
[DAGCombiner] Try to use SelectionDAG::isKnownToBeAPowerOfTwo instead of just APInt::isPowerOf2

Generalize sdiv/udiv/srem/urem combines using APInt::isPowerOf2, which only works for const/splat-const values, to call SelectionDAG::isKnownToBeAPowerOfTwo instead which recognises many more cases.

Added a DAGCombiner::BuildLogBase2 helper since PowerOf2 combines often involve taking the log2 of such a value.

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

llvm-svn: 289654
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/combine-sdiv.ll
llvm/test/CodeGen/X86/combine-srem.ll
llvm/test/CodeGen/X86/combine-udiv.ll
llvm/test/CodeGen/X86/combine-urem.ll
llvm/test/CodeGen/X86/urem-power-of-two.ll