@@ -1994,6 +1994,26 @@ static ValueDecl *getInsertElementOperation(ASTContext &Context, Identifier Id,
1994
1994
return getBuiltinFunction (Id, ArgElts, VecTy);
1995
1995
}
1996
1996
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
+
1997
2017
static ValueDecl *getShuffleVectorOperation (ASTContext &Context, Identifier Id,
1998
2018
Type FirstTy, Type SecondTy) {
1999
2019
// (Vector<N, T>, Vector<N, T>, Vector<M, Int32) -> Vector<M, T>
@@ -3132,6 +3152,10 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
3132
3152
case BuiltinValueKind::InsertElement:
3133
3153
if (Types.size () != 3 ) return nullptr ;
3134
3154
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 ]);
3135
3159
3136
3160
case BuiltinValueKind::ShuffleVector:
3137
3161
if (Types.size () != 2 ) return nullptr ;
0 commit comments