Skip to content

Commit e800df8

Browse files
committedJun 22, 2017
[InstCombine] add peekThroughBitcast() helper; NFC
This is an NFC portion of D33517. We have similar helpers in the backend. llvm-svn: 306008
1 parent 636851b commit e800df8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1615,12 +1615,8 @@ static Value *matchSelectFromAndOr(Value *A, Value *C, Value *B, Value *D,
16151615
// The potential condition of the select may be bitcasted. In that case, look
16161616
// through its bitcast and the corresponding bitcast of the 'not' condition.
16171617
Type *OrigType = A->getType();
1618-
Value *SrcA, *SrcB;
1619-
if (match(A, m_OneUse(m_BitCast(m_Value(SrcA)))) &&
1620-
match(B, m_OneUse(m_BitCast(m_Value(SrcB))))) {
1621-
A = SrcA;
1622-
B = SrcB;
1623-
}
1618+
A = peekThroughBitcast(A, true);
1619+
B = peekThroughBitcast(B, true);
16241620

16251621
if (Value *Cond = getSelectCondition(A, B, Builder)) {
16261622
// ((bc Cond) & C) | ((bc ~Cond) & D) --> bc (select Cond, (bc C), (bc D))

‎llvm/lib/Transforms/InstCombine/InstCombineInternal.h

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ static inline bool isCanonicalPredicate(CmpInst::Predicate Pred) {
9595
}
9696
}
9797

98+
/// Return the source operand of a potentially bitcasted value while optionally
99+
/// checking if it has one use. If there is no bitcast or the one use check is
100+
/// not met, return the input value itself.
101+
static inline Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
102+
if (auto *BitCast = dyn_cast<BitCastInst>(V))
103+
if (!OneUseOnly || BitCast->hasOneUse())
104+
return BitCast->getOperand(0);
105+
106+
// V is not a bitcast or V has more than one use and OneUseOnly is true.
107+
return V;
108+
}
109+
98110
/// \brief Add one to a Constant
99111
static inline Constant *AddOne(Constant *C) {
100112
return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));

0 commit comments

Comments
 (0)
Please sign in to comment.