diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -3069,7 +3069,8 @@ // ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits) Constant *C; if (match(NotVal, m_AShr(m_Constant(C), m_Value(Y))) && - match(C, m_Negative())) + match(C, m_Negative()) && + (!C->getType()->isVectorTy() || !C->containsUndefElement())) return BinaryOperator::CreateLShr(ConstantExpr::getNot(C), Y); // ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits) diff --git a/llvm/test/Transforms/InstCombine/vector-xor.ll b/llvm/test/Transforms/InstCombine/vector-xor.ll --- a/llvm/test/Transforms/InstCombine/vector-xor.ll +++ b/llvm/test/Transforms/InstCombine/vector-xor.ll @@ -140,8 +140,9 @@ define <4 x i32> @test_v4i32_not_ashr_negative_const_undef(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_undef( -; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> , [[A0:%.*]] -; CHECK-NEXT: ret <4 x i32> [[TMP1]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> , [[A0:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], +; CHECK-NEXT: ret <4 x i32> [[TMP2]] ; %1 = ashr <4 x i32> , %a0 %2 = xor <4 x i32> , %1