Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -362,6 +362,14 @@ return nullptr; } + // If the select condition is a vector, the operands of the original select's + // operands also must be vectors. This may not be the case for getelementptr + // for example. + 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: llvm/trunk/test/Transforms/InstCombine/select-gep.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/select-gep.ll +++ llvm/trunk/test/Transforms/InstCombine/select-gep.ll @@ -136,3 +136,17 @@ ret i32* %select } +; We cannot create a select with a vector condition but scalar operands. + +define <2 x i64*> @test5(i64* %p1, i64* %p2, <2 x i64> %idx, <2 x i1> %cc) { +; CHECK-LABEL: @test5( +; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, i64* %p1, <2 x i64> %idx +; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i64, i64* %p2, <2 x i64> %idx +; CHECK-NEXT: [[SELECT:%.*]] = select <2 x i1> %cc, <2 x i64*> [[GEP1]], <2 x i64*> [[GEP2]] +; CHECK-NEXT: ret <2 x i64*> [[SELECT]] +; + %gep1 = getelementptr i64, i64* %p1, <2 x i64> %idx + %gep2 = getelementptr i64, i64* %p2, <2 x i64> %idx + %select = select <2 x i1> %cc, <2 x i64*> %gep1, <2 x i64*> %gep2 + ret <2 x i64*> %select +}