diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 378682b7b9cdaf..72008dfa3b2872 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -497,7 +497,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) { Type *Ty = II.getType(); unsigned BitWidth = Ty->getScalarSizeInBits(); Value *Op0 = II.getArgOperand(0); - Value *X; + Value *X, *Y; // ctpop(bitreverse(x)) -> ctpop(x) // ctpop(bswap(x)) -> ctpop(x) @@ -505,8 +505,9 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) { return IC.replaceOperand(II, 0, X); // ctpop(rot(x)) -> ctpop(x) - if (match(Op0, m_FShl(m_Value(X), m_Specific(X), m_Value())) || - match(Op0, m_FShr(m_Value(X), m_Specific(X), m_Value()))) + if ((match(Op0, m_FShl(m_Value(X), m_Value(Y), m_Value())) || + match(Op0, m_FShr(m_Value(X), m_Value(Y), m_Value()))) && + X == Y) return IC.replaceOperand(II, 0, X); // ctpop(x | -x) -> bitwidth - cttz(x, false)