diff options
author | Craig Topper <craig.topper@intel.com> | 2017-08-14 19:09:32 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2017-08-14 19:09:32 +0000 |
commit | 69fa8e0d99177045e5ad3bef42360c635736c428 (patch) | |
tree | e2950fb3e5fe4cd4229e6d01624f82b80cdd8937 /llvm/lib/Analysis | |
parent | 9c7b881677f65fce8cfbc6ec70c44790576b6ea5 (diff) | |
download | bcm5719-llvm-69fa8e0d99177045e5ad3bef42360c635736c428.tar.gz bcm5719-llvm-69fa8e0d99177045e5ad3bef42360c635736c428.zip |
Revert r310869 "[InstSimplify][InstCombine] Modify the interface of decomposeBitTestICmp and use it in the InstSimplify"
Failed to add the two files that moved. And then added an extra change I didn't mean to while trying to fix that. Reverting everything.
llvm-svn: 310873
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 52 |
2 files changed, 31 insertions, 22 deletions
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt index 45268dd5c76..161709a4846 100644 --- a/llvm/lib/Analysis/CMakeLists.txt +++ b/llvm/lib/Analysis/CMakeLists.txt @@ -18,7 +18,6 @@ add_llvm_library(LLVMAnalysis CallGraphSCCPass.cpp CallPrinter.cpp CaptureTracking.cpp - CmpInstAnalysis.cpp CostModel.cpp CodeMetrics.cpp ConstantFolding.cpp diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index d155f6b4803..9729629b167 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -23,7 +23,6 @@ #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/CaptureTracking.h" -#include "llvm/Analysis/CmpInstAnalysis.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/Analysis/MemoryBuiltins.h" @@ -3621,29 +3620,32 @@ static Value *simplifySelectBitTest(Value *TrueVal, Value *FalseVal, Value *X, /// An alternative way to test if a bit is set or not uses sgt/slt instead of /// eq/ne. -static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *CmpRHS, - ICmpInst::Predicate Pred, - Value *TrueVal, Value *FalseVal) { - Value *X; - APInt Mask; - if (!decomposeBitTestICmp(CmpLHS, CmpRHS, Pred, X, Mask)) - return nullptr; - +static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *TrueVal, + Value *FalseVal, + bool TrueWhenUnset) { unsigned BitWidth = TrueVal->getType()->getScalarSizeInBits(); if (!BitWidth) return nullptr; - Value *ExtX; - if (match(X, m_Trunc(m_Value(ExtX))) && - (ExtX == TrueVal || ExtX == FalseVal)) { + APInt MinSignedValue; + Value *X; + if (match(CmpLHS, m_Trunc(m_Value(X))) && (X == TrueVal || X == FalseVal)) { // icmp slt (trunc X), 0 <--> icmp ne (and X, C), 0 // icmp sgt (trunc X), -1 <--> icmp eq (and X, C), 0 - X = ExtX; - Mask = Mask.zext(BitWidth); + unsigned DestSize = CmpLHS->getType()->getScalarSizeInBits(); + MinSignedValue = APInt::getSignedMinValue(DestSize).zext(BitWidth); + } else { + // icmp slt X, 0 <--> icmp ne (and X, C), 0 + // icmp sgt X, -1 <--> icmp eq (and X, C), 0 + X = CmpLHS; + MinSignedValue = APInt::getSignedMinValue(BitWidth); } - return simplifySelectBitTest(TrueVal, FalseVal, X, &Mask, - Pred == ICmpInst::ICMP_EQ); + if (Value *V = simplifySelectBitTest(TrueVal, FalseVal, X, &MinSignedValue, + TrueWhenUnset)) + return V; + + return nullptr; } /// Try to simplify a select instruction when its condition operand is an @@ -3656,6 +3658,9 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, if (!match(CondVal, m_ICmp(Pred, m_Value(CmpLHS), m_Value(CmpRHS)))) return nullptr; + // FIXME: This code is nearly duplicated in InstCombine. Using/refactoring + // decomposeBitTestICmp() might help. + // FIXME this should support ICMP_SLE/SGE forms as well if (ICmpInst::isEquality(Pred) && match(CmpRHS, m_Zero())) { Value *X; const APInt *Y; @@ -3663,13 +3668,18 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, if (Value *V = simplifySelectBitTest(TrueVal, FalseVal, X, Y, Pred == ICmpInst::ICMP_EQ)) return V; + } else if (Pred == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero())) { + // Comparing signed-less-than 0 checks if the sign bit is set. + if (Value *V = simplifySelectWithFakeICmpEq(CmpLHS, TrueVal, FalseVal, + false)) + return V; + } else if (Pred == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes())) { + // Comparing signed-greater-than -1 checks if the sign bit is not set. + if (Value *V = simplifySelectWithFakeICmpEq(CmpLHS, TrueVal, FalseVal, + true)) + return V; } - // Check for other compares that behave like bit test. - if (Value *V = simplifySelectWithFakeICmpEq(CmpLHS, CmpRHS, Pred, - TrueVal, FalseVal)) - return V; - if (CondVal->hasOneUse()) { const APInt *C; if (match(CmpRHS, m_APInt(C))) { |