Skip to content

Commit

Permalink
[instcombine] Cleanup foldAllocaCmp slightly [NFC]
Browse files Browse the repository at this point in the history
  • Loading branch information
preames committed Feb 19, 2022
1 parent 8e7247a commit 6f9d557
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
14 changes: 6 additions & 8 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Expand Up @@ -1006,8 +1006,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
}

Instruction *InstCombinerImpl::foldAllocaCmp(ICmpInst &ICI,
const AllocaInst *Alloca,
const Value *Other) {
const AllocaInst *Alloca) {
assert(ICI.isEquality() && "Cannot fold non-equality comparison.");

// It would be tempting to fold away comparisons between allocas and any
Expand Down Expand Up @@ -1076,10 +1075,9 @@ Instruction *InstCombinerImpl::foldAllocaCmp(ICmpInst &ICI,
}
}

Type *CmpTy = CmpInst::makeCmpResultType(Other->getType());
return replaceInstUsesWith(
ICI,
ConstantInt::get(CmpTy, !CmpInst::isTrueWhenEqual(ICI.getPredicate())));
auto *Res = ConstantInt::get(ICI.getType(),
!CmpInst::isTrueWhenEqual(ICI.getPredicate()));
return replaceInstUsesWith(ICI, Res);
}

/// Fold "icmp pred (X+C), X".
Expand Down Expand Up @@ -6061,10 +6059,10 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Op0->getType()->isPointerTy() && I.isEquality()) {
assert(Op1->getType()->isPointerTy() && "Comparing pointer with non-pointer?");
if (auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject(Op0)))
if (Instruction *New = foldAllocaCmp(I, Alloca, Op1))
if (Instruction *New = foldAllocaCmp(I, Alloca))
return New;
if (auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject(Op1)))
if (Instruction *New = foldAllocaCmp(I, Alloca, Op0))
if (Instruction *New = foldAllocaCmp(I, Alloca))
return New;
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Expand Up @@ -650,8 +650,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final

Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
ICmpInst::Predicate Cond, Instruction &I);
Instruction *foldAllocaCmp(ICmpInst &ICI, const AllocaInst *Alloca,
const Value *Other);
Instruction *foldAllocaCmp(ICmpInst &ICI, const AllocaInst *Alloca);
Instruction *foldCmpLoadFromIndexedGlobal(LoadInst *LI,
GetElementPtrInst *GEP,
GlobalVariable *GV, CmpInst &ICI,
Expand Down

0 comments on commit 6f9d557

Please sign in to comment.