Skip to content

Commit

Permalink
[InstCombine] Make the context instruction parameter of foldOrOfICmps…
Browse files Browse the repository at this point in the history
… a reference to discourage passing nullptr and to remove the '&' from all of the call sites. NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305493 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Jun 15, 2017
1 parent ccc684d commit f82d26a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ Instruction *InstCombiner::foldCastedBitwiseLogic(BinaryOperator &I) {
ICmpInst *ICmp1 = dyn_cast<ICmpInst>(Cast1Src);
if (ICmp0 && ICmp1) {
Value *Res = LogicOpc == Instruction::And ? foldAndOfICmps(ICmp0, ICmp1)
: foldOrOfICmps(ICmp0, ICmp1, &I);
: foldOrOfICmps(ICmp0, ICmp1, I);
if (Res)
return CastInst::Create(CastOpcode, Res, DestTy);
return nullptr;
Expand Down Expand Up @@ -1591,7 +1591,7 @@ static Value *matchSelectFromAndOr(Value *A, Value *C, Value *B, Value *D,

/// Fold (icmp)|(icmp) if possible.
Value *InstCombiner::foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
Instruction *CxtI) {
Instruction &CxtI) {
ICmpInst::Predicate PredL = LHS->getPredicate(), PredR = RHS->getPredicate();

// Fold (iszero(A & K1) | iszero(A & K2)) -> (A & (K1 | K2)) != (K1 | K2)
Expand All @@ -1612,8 +1612,8 @@ Value *InstCombiner::foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
std::swap(A, B);

if (A == C &&
isKnownToBeAPowerOfTwo(B, false, 0, CxtI) &&
isKnownToBeAPowerOfTwo(D, false, 0, CxtI)) {
isKnownToBeAPowerOfTwo(B, false, 0, &CxtI) &&
isKnownToBeAPowerOfTwo(D, false, 0, &CxtI)) {
Value *Mask = Builder->CreateOr(B, D);
Value *Masked = Builder->CreateAnd(A, Mask);
return Builder->CreateICmp(ICmpInst::ICMP_NE, Masked, Mask);
Expand Down Expand Up @@ -2188,26 +2188,26 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
ICmpInst *LHS = dyn_cast<ICmpInst>(Op0);
ICmpInst *RHS = dyn_cast<ICmpInst>(Op1);
if (LHS && RHS)
if (Value *Res = foldOrOfICmps(LHS, RHS, &I))
if (Value *Res = foldOrOfICmps(LHS, RHS, I))
return replaceInstUsesWith(I, Res);

// TODO: Make this recursive; it's a little tricky because an arbitrary
// number of 'or' instructions might have to be created.
Value *X, *Y;
if (LHS && match(Op1, m_OneUse(m_Or(m_Value(X), m_Value(Y))))) {
if (auto *Cmp = dyn_cast<ICmpInst>(X))
if (Value *Res = foldOrOfICmps(LHS, Cmp, &I))
if (Value *Res = foldOrOfICmps(LHS, Cmp, I))
return replaceInstUsesWith(I, Builder->CreateOr(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldOrOfICmps(LHS, Cmp, &I))
if (Value *Res = foldOrOfICmps(LHS, Cmp, I))
return replaceInstUsesWith(I, Builder->CreateOr(Res, X));
}
if (RHS && match(Op0, m_OneUse(m_Or(m_Value(X), m_Value(Y))))) {
if (auto *Cmp = dyn_cast<ICmpInst>(X))
if (Value *Res = foldOrOfICmps(Cmp, RHS, &I))
if (Value *Res = foldOrOfICmps(Cmp, RHS, I))
return replaceInstUsesWith(I, Builder->CreateOr(Res, Y));
if (auto *Cmp = dyn_cast<ICmpInst>(Y))
if (Value *Res = foldOrOfICmps(Cmp, RHS, &I))
if (Value *Res = foldOrOfICmps(Cmp, RHS, I))
return replaceInstUsesWith(I, Builder->CreateOr(Res, X));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/InstCombine/InstCombineInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner

Value *foldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS);
Value *foldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
Value *foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI);
Value *foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction &CxtI);
Value *foldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
Value *foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS);

Expand Down

0 comments on commit f82d26a

Please sign in to comment.