@@ -1994,6 +1994,26 @@ static ValueDecl *getInsertElementOperation(ASTContext &Context, Identifier Id,
19941994 return getBuiltinFunction (Id, ArgElts, VecTy);
19951995}
19961996
1997+ static ValueDecl *getSelectOperation (ASTContext &Context, Identifier Id,
1998+ Type PredTy, Type ValueTy) {
1999+ // Check for (NxInt1, NxTy, NxTy) -> NxTy
2000+ auto VecPredTy = PredTy->getAs <BuiltinVectorType>();
2001+ if (VecPredTy) {
2002+ // ValueTy must also be vector type with matching element count.
2003+ auto VecValueTy = ValueTy->getAs <BuiltinVectorType>();
2004+ if (!VecValueTy ||
2005+ VecPredTy->getNumElements () != VecValueTy->getNumElements ())
2006+ return nullptr ;
2007+ } else {
2008+ // Type is (Int1, Ty, Ty) -> Ty
2009+ auto IntTy = PredTy->getAs <BuiltinIntegerType>();
2010+ if (!IntTy || !IntTy->isFixedWidth () || IntTy->getFixedWidth () != 1 )
2011+ return nullptr ;
2012+ }
2013+ Type ArgElts[] = { PredTy, ValueTy, ValueTy };
2014+ return getBuiltinFunction (Id, ArgElts, ValueTy);
2015+ }
2016+
19972017static ValueDecl *getShuffleVectorOperation (ASTContext &Context, Identifier Id,
19982018 Type FirstTy, Type SecondTy) {
19992019 // (Vector<N, T>, Vector<N, T>, Vector<M, Int32) -> Vector<M, T>
@@ -3132,6 +3152,10 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
31323152 case BuiltinValueKind::InsertElement:
31333153 if (Types.size () != 3 ) return nullptr ;
31343154 return getInsertElementOperation (Context, Id, Types[0 ], Types[1 ], Types[2 ]);
3155+
3156+ case BuiltinValueKind::Select:
3157+ if (Types.size () != 2 ) return nullptr ;
3158+ return getSelectOperation (Context, Id, Types[0 ], Types[1 ]);
31353159
31363160 case BuiltinValueKind::ShuffleVector:
31373161 if (Types.size () != 2 ) return nullptr ;
0 commit comments