diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-11-09 00:13:11 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-11-09 00:13:11 +0000 |
commit | 4e9d6cd35404b8804150c43ea7a8375f398664f4 (patch) | |
tree | 30319fc59d401c82f6b9355ed032d3a49017ef50 /llvm/lib | |
parent | 99dc5feff144a4183a67d66833c51fc7f2444ff9 (diff) | |
download | bcm5719-llvm-4e9d6cd35404b8804150c43ea7a8375f398664f4.tar.gz bcm5719-llvm-4e9d6cd35404b8804150c43ea7a8375f398664f4.zip |
[InstCombine] fix profitability equation for max-of-nots transform
As the test change shows, we can increase the critical path by adding
a 'not' instruction, so make sure that we're actually removing an
instruction if we do this transform.
This transform could also cause us to miss folds of min/max pairs.
llvm-svn: 286315
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 6bee87c5d10..06b769bc05a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1308,15 +1308,14 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { if ((SPF == SPF_SMAX || SPF == SPF_UMAX) && IsFreeToInvert(LHS, LHS->hasNUses(2)) && IsFreeToInvert(RHS, RHS->hasNUses(2))) { - // This transform adds a not operation, and that extra cost needs to be - // justified. We look for simplifications that will result from applying - // this rule: - bool Profitable = - (LHS->hasNUses(2) && match(LHS, m_Not(m_Value()))) || - (RHS->hasNUses(2) && match(RHS, m_Not(m_Value()))) || + // For this transform to be profitable, we need to eliminate at least two + // 'not' instructions if we're going to add one 'not' instruction. + int NumberOfNots = + (LHS->hasNUses(2) && match(LHS, m_Not(m_Value()))) + + (RHS->hasNUses(2) && match(RHS, m_Not(m_Value()))) + (SI.hasOneUse() && match(*SI.user_begin(), m_Not(m_Value()))); - if (Profitable) { + if (NumberOfNots >= 2) { Value *NewLHS = Builder->CreateNot(LHS); Value *NewRHS = Builder->CreateNot(RHS); Value *NewCmp = SPF == SPF_SMAX |