forked from OSchip/llvm-project
[InstCombine] add peekThroughBitcast() helper; NFC
This is an NFC portion of D33517. We have similar helpers in the backend. llvm-svn: 306008
This commit is contained in:
parent
636851b845
commit
e800df8eac
|
@ -1615,12 +1615,8 @@ static Value *matchSelectFromAndOr(Value *A, Value *C, Value *B, Value *D,
|
|||
// The potential condition of the select may be bitcasted. In that case, look
|
||||
// through its bitcast and the corresponding bitcast of the 'not' condition.
|
||||
Type *OrigType = A->getType();
|
||||
Value *SrcA, *SrcB;
|
||||
if (match(A, m_OneUse(m_BitCast(m_Value(SrcA)))) &&
|
||||
match(B, m_OneUse(m_BitCast(m_Value(SrcB))))) {
|
||||
A = SrcA;
|
||||
B = SrcB;
|
||||
}
|
||||
A = peekThroughBitcast(A, true);
|
||||
B = peekThroughBitcast(B, true);
|
||||
|
||||
if (Value *Cond = getSelectCondition(A, B, Builder)) {
|
||||
// ((bc Cond) & C) | ((bc ~Cond) & D) --> bc (select Cond, (bc C), (bc D))
|
||||
|
|
|
@ -95,6 +95,18 @@ static inline bool isCanonicalPredicate(CmpInst::Predicate Pred) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the source operand of a potentially bitcasted value while optionally
|
||||
/// checking if it has one use. If there is no bitcast or the one use check is
|
||||
/// not met, return the input value itself.
|
||||
static inline Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
|
||||
if (auto *BitCast = dyn_cast<BitCastInst>(V))
|
||||
if (!OneUseOnly || BitCast->hasOneUse())
|
||||
return BitCast->getOperand(0);
|
||||
|
||||
// V is not a bitcast or V has more than one use and OneUseOnly is true.
|
||||
return V;
|
||||
}
|
||||
|
||||
/// \brief Add one to a Constant
|
||||
static inline Constant *AddOne(Constant *C) {
|
||||
return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));
|
||||
|
|
Loading…
Reference in New Issue