diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-12-04 18:53:27 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-12-04 18:53:27 +0000 |
commit | 3d5bb15a1dd26adacd155369363e96b96e61eefd (patch) | |
tree | 9e85fcb2d5c6308a2c6f7eeb84f8cd26beafe46b | |
parent | a592aeb35a4fc4d52dcb1a67d410dc756f12d3ea (diff) | |
download | bcm5719-llvm-3d5bb15a1dd26adacd155369363e96b96e61eefd.tar.gz bcm5719-llvm-3d5bb15a1dd26adacd155369363e96b96e61eefd.zip |
[CmpInstAnalysis] fix function signature for ICmp code to predicate; NFC
The old function underspecified the return type, took an unused parameter,
and had a misleading name.
llvm-svn: 348292
-rw-r--r-- | llvm/include/llvm/Analysis/CmpInstAnalysis.h | 15 | ||||
-rw-r--r-- | llvm/lib/Analysis/CmpInstAnalysis.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 18 |
3 files changed, 26 insertions, 27 deletions
diff --git a/llvm/include/llvm/Analysis/CmpInstAnalysis.h b/llvm/include/llvm/Analysis/CmpInstAnalysis.h index d3f29501110..0e9c6a96b0f 100644 --- a/llvm/include/llvm/Analysis/CmpInstAnalysis.h +++ b/llvm/include/llvm/Analysis/CmpInstAnalysis.h @@ -46,15 +46,14 @@ namespace llvm { /// unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred = false); - /// This is the complement of getICmpCode, which turns an opcode and two - /// operands into either a constant true or false, or the predicate for a new - /// ICmp instruction. The sign is passed in to determine which kind of - /// predicate to use in the new icmp instruction. + /// This is the complement of getICmpCode. It turns a predicate code into + /// either a constant true or false or the predicate for a new ICmp. + /// The sign is passed in to determine which kind of predicate to use in the + /// new ICmp instruction. /// Non-NULL return value will be a true or false constant. - /// NULL return means a new ICmp is needed. The predicate for which is output - /// in NewICmpPred. - Value *getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, - CmpInst::Predicate &NewICmpPred); + /// NULL return means a new ICmp is needed. The predicate is output in Pred. + Constant *getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, + CmpInst::Predicate &Pred); /// Return true if both predicates match sign or if at least one of them is an /// equality comparison (which is signless). diff --git a/llvm/lib/Analysis/CmpInstAnalysis.cpp b/llvm/lib/Analysis/CmpInstAnalysis.cpp index 42471fe0f14..27071babec5 100644 --- a/llvm/lib/Analysis/CmpInstAnalysis.cpp +++ b/llvm/lib/Analysis/CmpInstAnalysis.cpp @@ -40,20 +40,20 @@ unsigned llvm::getICmpCode(const ICmpInst *ICI, bool InvertPred) { } } -Value *llvm::getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, - CmpInst::Predicate &NewICmpPred) { +Constant *llvm::getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, + CmpInst::Predicate &Pred) { switch (Code) { default: llvm_unreachable("Illegal ICmp code!"); case 0: // False. - return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0); - case 1: NewICmpPred = Sign ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; - case 2: NewICmpPred = ICmpInst::ICMP_EQ; break; - case 3: NewICmpPred = Sign ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; - case 4: NewICmpPred = Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; - case 5: NewICmpPred = ICmpInst::ICMP_NE; break; - case 6: NewICmpPred = Sign ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; + return ConstantInt::get(CmpInst::makeCmpResultType(OpTy), 0); + case 1: Pred = Sign ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; + case 2: Pred = ICmpInst::ICMP_EQ; break; + case 3: Pred = Sign ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; + case 4: Pred = Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; + case 5: Pred = ICmpInst::ICMP_NE; break; + case 6: Pred = Sign ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; case 7: // True. - return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 1); + return ConstantInt::get(CmpInst::makeCmpResultType(OpTy), 1); } return nullptr; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 282498e98a4..24a82ba9ae4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -53,11 +53,11 @@ static unsigned getFCmpCode(FCmpInst::Predicate CC) { /// operands into either a constant true or false, or a brand new ICmp /// instruction. The sign is passed in to determine which kind of predicate to /// use in the new icmp instruction. -static Value *getNewICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, +static Value *getNewICmpValue(unsigned Code, bool Sign, Value *LHS, Value *RHS, InstCombiner::BuilderTy &Builder) { ICmpInst::Predicate NewPred; - if (Value *NewConstant = getICmpValue(Sign, Code, LHS, RHS, NewPred)) - return NewConstant; + if (Constant *TorF = getPredForICmpCode(Code, Sign, LHS->getType(), NewPred)) + return TorF; return Builder.CreateICmp(NewPred, LHS, RHS); } @@ -1041,8 +1041,8 @@ Value *InstCombiner::foldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS, LHS->getOperand(1) == RHS->getOperand(1)) { Value *Op0 = LHS->getOperand(0), *Op1 = LHS->getOperand(1); unsigned Code = getICmpCode(LHS) & getICmpCode(RHS); - bool isSigned = LHS->isSigned() || RHS->isSigned(); - return getNewICmpValue(isSigned, Code, Op0, Op1, Builder); + bool IsSigned = LHS->isSigned() || RHS->isSigned(); + return getNewICmpValue(Code, IsSigned, Op0, Op1, Builder); } } @@ -1984,8 +1984,8 @@ Value *InstCombiner::foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, LHS->getOperand(1) == RHS->getOperand(1)) { Value *Op0 = LHS->getOperand(0), *Op1 = LHS->getOperand(1); unsigned Code = getICmpCode(LHS) | getICmpCode(RHS); - bool isSigned = LHS->isSigned() || RHS->isSigned(); - return getNewICmpValue(isSigned, Code, Op0, Op1, Builder); + bool IsSigned = LHS->isSigned() || RHS->isSigned(); + return getNewICmpValue(Code, IsSigned, Op0, Op1, Builder); } } @@ -2471,8 +2471,8 @@ Value *InstCombiner::foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS) { // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B) Value *Op0 = LHS->getOperand(0), *Op1 = LHS->getOperand(1); unsigned Code = getICmpCode(LHS) ^ getICmpCode(RHS); - bool isSigned = LHS->isSigned() || RHS->isSigned(); - return getNewICmpValue(isSigned, Code, Op0, Op1, Builder); + bool IsSigned = LHS->isSigned() || RHS->isSigned(); + return getNewICmpValue(Code, IsSigned, Op0, Op1, Builder); } } |