summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaExpr.cpp6
-rw-r--r--clang/test/CodeGenCXX/vector-splat-conversion.cpp11
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a941d524b7f..620ec30b128 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8973,6 +8973,12 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar,
return true;
ScalarCast = CK_IntegralCast;
+ } else if (VectorEltTy->isIntegralType(S.Context) &&
+ ScalarTy->isRealFloatingType()) {
+ if (S.Context.getTypeSize(VectorEltTy) == S.Context.getTypeSize(ScalarTy))
+ ScalarCast = CK_FloatingToIntegral;
+ else
+ return true;
} else if (VectorEltTy->isRealFloatingType()) {
if (ScalarTy->isRealFloatingType()) {
diff --git a/clang/test/CodeGenCXX/vector-splat-conversion.cpp b/clang/test/CodeGenCXX/vector-splat-conversion.cpp
index 805f9f5bab1..618ad76ce69 100644
--- a/clang/test/CodeGenCXX/vector-splat-conversion.cpp
+++ b/clang/test/CodeGenCXX/vector-splat-conversion.cpp
@@ -49,3 +49,14 @@ void BoolConversion() {
// CHECK: store <4 x i128> zeroinitializer
constexpr bigint4 cBigintsF = (bigint4)false;
}
+
+typedef __attribute__((vector_size(8))) int gcc_int_2;
+gcc_int_2 FloatToIntConversion(gcc_int_2 Int2, float f) {
+ return Int2 + f;
+ // CHECK: %[[LOAD_INT:.+]] = load <2 x i32>
+ // CHECK: %[[LOAD:.+]] = load float, float*
+ // CHECK: %[[CONV:.+]] = fptosi float %[[LOAD]] to i32
+ // CHECK: %[[INSERT:.+]] = insertelement <2 x i32> undef, i32 %[[CONV]], i32 0
+ // CHECK: %[[SPLAT:.+]] = shufflevector <2 x i32> %[[INSERT]], <2 x i32> undef, <2 x i32> zeroinitializer
+ // CHECK: add <2 x i32> %[[LOAD_INT]], %[[SPLAT]]
+}
OpenPOWER on IntegriCloud