diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -4014,8 +4014,13 @@ return BestValue; }; - if (match(Op0, m_Undef())) + if (match(Op0, m_Undef())) { + for (const auto *U : I.users()) { + if (match(U, m_Shuffle(m_Value(), m_Specific(&I)))) + return nullptr; + } return replaceInstUsesWith(I, getUndefReplacement(I.getType())); + } Constant *C; if (match(Op0, m_Constant(C)) && C->containsUndefOrPoisonElement()) {