mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-06 12:04:52 +00:00
[InstCombine] clean up foldICmpTruncConstant(); NFCI
1. Fix variable names 2. Add local variables to reduce code git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279132 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
175a34b53e
commit
f17a9b62af
@ -1534,39 +1534,42 @@ Instruction *InstCombiner::foldICmpCstShlConst(ICmpInst &I, Value *Op, Value *A,
|
|||||||
return getConstant(false);
|
return getConstant(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::foldICmpTruncConstant(ICmpInst &ICI,
|
/// Fold icmp (trunc X, Y), C.
|
||||||
Instruction *LHSI,
|
Instruction *InstCombiner::foldICmpTruncConstant(ICmpInst &Cmp,
|
||||||
const APInt *RHSV) {
|
Instruction *Trunc,
|
||||||
|
const APInt *C) {
|
||||||
// FIXME: This check restricts all folds under here to scalar types.
|
// FIXME: This check restricts all folds under here to scalar types.
|
||||||
ConstantInt *RHS = dyn_cast<ConstantInt>(ICI.getOperand(1));
|
ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
|
||||||
if (!RHS)
|
if (!RHS)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (RHS->isOne() && RHSV->getBitWidth() > 1) {
|
ICmpInst::Predicate Pred = Cmp.getPredicate();
|
||||||
|
Value *X = Trunc->getOperand(0);
|
||||||
|
if (RHS->isOne() && C->getBitWidth() > 1) {
|
||||||
// icmp slt trunc(signum(V)) 1 --> icmp slt V, 1
|
// icmp slt trunc(signum(V)) 1 --> icmp slt V, 1
|
||||||
Value *V = nullptr;
|
Value *V = nullptr;
|
||||||
if (ICI.getPredicate() == ICmpInst::ICMP_SLT &&
|
if (Pred == ICmpInst::ICMP_SLT && match(X, m_Signum(m_Value(V))))
|
||||||
match(LHSI->getOperand(0), m_Signum(m_Value(V))))
|
|
||||||
return new ICmpInst(ICmpInst::ICMP_SLT, V,
|
return new ICmpInst(ICmpInst::ICMP_SLT, V,
|
||||||
ConstantInt::get(V->getType(), 1));
|
ConstantInt::get(V->getType(), 1));
|
||||||
}
|
}
|
||||||
if (ICI.isEquality() && LHSI->hasOneUse()) {
|
|
||||||
|
if (Cmp.isEquality() && Trunc->hasOneUse()) {
|
||||||
// Simplify icmp eq (trunc x to i8), 42 -> icmp eq x, 42|highbits if all
|
// Simplify icmp eq (trunc x to i8), 42 -> icmp eq x, 42|highbits if all
|
||||||
// of the high bits truncated out of x are known.
|
// of the high bits truncated out of x are known.
|
||||||
unsigned DstBits = LHSI->getType()->getPrimitiveSizeInBits(),
|
unsigned DstBits = Trunc->getType()->getPrimitiveSizeInBits(),
|
||||||
SrcBits = LHSI->getOperand(0)->getType()->getPrimitiveSizeInBits();
|
SrcBits = X->getType()->getPrimitiveSizeInBits();
|
||||||
APInt KnownZero(SrcBits, 0), KnownOne(SrcBits, 0);
|
APInt KnownZero(SrcBits, 0), KnownOne(SrcBits, 0);
|
||||||
computeKnownBits(LHSI->getOperand(0), KnownZero, KnownOne, 0, &ICI);
|
computeKnownBits(X, KnownZero, KnownOne, 0, &Cmp);
|
||||||
|
|
||||||
// If all the high bits are known, we can do this xform.
|
// If all the high bits are known, we can do this xform.
|
||||||
if ((KnownZero | KnownOne).countLeadingOnes() >= SrcBits - DstBits) {
|
if ((KnownZero | KnownOne).countLeadingOnes() >= SrcBits - DstBits) {
|
||||||
// Pull in the high bits from known-ones set.
|
// Pull in the high bits from known-ones set.
|
||||||
APInt NewRHS = RHS->getValue().zext(SrcBits);
|
APInt NewRHS = C->zext(SrcBits);
|
||||||
NewRHS |= KnownOne & APInt::getHighBitsSet(SrcBits, SrcBits - DstBits);
|
NewRHS |= KnownOne & APInt::getHighBitsSet(SrcBits, SrcBits - DstBits);
|
||||||
return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
|
return new ICmpInst(Pred, X, Builder->getInt(NewRHS));
|
||||||
Builder->getInt(NewRHS));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user