Index: lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineSelect.cpp +++ lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -362,6 +362,12 @@ return nullptr; } + // If the select condition is a vector, the operands also must be vectors. + if (SI.getCondition()->getType()->isVectorTy() && + (!OtherOpT->getType()->isVectorTy() || + !OtherOpF->getType()->isVectorTy())) + return nullptr; + // If we reach here, they do have operations in common. Value *NewSI = Builder.CreateSelect(SI.getCondition(), OtherOpT, OtherOpF, SI.getName() + ".v", &SI); Index: test/Transforms/InstCombine/select-gep.ll =================================================================== --- test/Transforms/InstCombine/select-gep.ll +++ test/Transforms/InstCombine/select-gep.ll @@ -136,3 +136,21 @@ ret i32* %select } +; We cannot turn create a select with a vector condition but scalar operands. + +define <2 x i64*> @test5(i64* %p, <2 x i1> %cc) { +; CHECK-LABEL: @test5( +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, i64* [[P:%.*]], i64 -1 +; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i64, i64* [[P]], i64 1 +; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i64, i64* [[GEP1]], <2 x i64> undef +; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i64, i64* [[GEP2]], <2 x i64> undef +; CHECK-NEXT: [[SELECT:%.*]] = select <2 x i1> [[CC:%.*]], <2 x i64*> [[GEP3]], <2 x i64*> [[GEP4]] +; CHECK-NEXT: ret <2 x i64*> [[SELECT]] +; + %gep1 = getelementptr i64, i64* %p, i64 -1 + %gep2 = getelementptr i64, i64* %p, i64 1 + %gep3 = getelementptr i64, i64* %gep1, <2 x i64> undef + %gep4 = getelementptr i64, i64* %gep2, <2 x i64> undef + %select = select <2 x i1> %cc, <2 x i64*> %gep3, <2 x i64*> %gep4 + ret <2 x i64*> %select +}