Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -283,10 +283,9 @@ // The select condition may be a vector. We may only change the operand // type if the vector width remains the same (and matches the condition). if (auto *CondVTy = dyn_cast(CondTy)) { - if (!FIOpndTy->isVectorTy()) - return nullptr; - if (cast(CondVTy)->getNumElements() != - cast(FIOpndTy)->getNumElements()) + if (!FIOpndTy->isVectorTy() || + CondVTy->getElementCount() != + cast(FIOpndTy)->getElementCount()) return nullptr; // TODO: If the backend knew how to deal with casts better, we could Index: llvm/test/Transforms/InstCombine/select.ll =================================================================== --- llvm/test/Transforms/InstCombine/select.ll +++ llvm/test/Transforms/InstCombine/select.ll @@ -68,6 +68,15 @@ ret <2 x i1> %R } +define @test8vvec( %C, %X) { +; CHECK-LABEL: @test8vvec( +; CHECK-NEXT: [[R:%.*]] = and [[C:%.*]], [[X:%.*]] +; CHECK-NEXT: ret [[R]] +; + %R = select %C, %X, zeroinitializer + ret %R +} + define i1 @test9(i1 %C, i1 %X) { ; CHECK-LABEL: @test9( ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true @@ -88,6 +97,16 @@ ret <2 x i1> %R } +define @test9vvec( %C, %X) { +; CHECK-LABEL: @test9vvec( +; CHECK-NEXT: [[NOT_C:%.*]] = xor [[C:%.*]], shufflevector ( insertelement ( undef, i1 true, i32 0), undef, zeroinitializer) +; CHECK-NEXT: [[R:%.*]] = and [[NOT_C]], [[X:%.*]] +; CHECK-NEXT: ret [[R]] +; + %R = select %C, zeroinitializer, %X + ret %R +} + define i1 @test10(i1 %C, i1 %X) { ; CHECK-LABEL: @test10( ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true