From 5b56244be35fb5c7666bf4c06dfb5ba4a7dd7028 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Wed, 4 Sep 2019 14:01:47 +0000 Subject: [PATCH] [PowerPC][Altivec] Fix constant argument for vec_dss Summary: This is similar to vec_ct* in https://reviews.llvm.org/rL304205. The argument must be a constant, otherwise instruction selection will fail. always_inline is not enough for isel to always fold everything away at -O0. The fix is to turn the function into macros in altivec.h. Fixes https://bugs.llvm.org/show_bug.cgi?id=43072 Reviewers: nemanjai, hfinkel, #powerpc, wuzish Reviewed By: #powerpc, wuzish Subscribers: wuzish, kbarton, MaskRay, shchenz, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66699 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370902 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/BuiltinsPPC.def | 2 +- lib/Headers/altivec.h | 4 +--- lib/Sema/SemaChecking.cpp | 2 ++ test/CodeGen/altivec-dss.c | 11 +++++++++++ test/CodeGen/builtins-ppc-error.c | 5 +++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/altivec-dss.c diff --git a/include/clang/Basic/BuiltinsPPC.def b/include/clang/Basic/BuiltinsPPC.def index 3b6348ad7d..249e38cb15 100644 --- a/include/clang/Basic/BuiltinsPPC.def +++ b/include/clang/Basic/BuiltinsPPC.def @@ -55,7 +55,7 @@ BUILTIN(__builtin_altivec_vcfux, "V4fV4iIi", "") BUILTIN(__builtin_altivec_vctsxs, "V4SiV4fIi", "") BUILTIN(__builtin_altivec_vctuxs, "V4UiV4fIi", "") -BUILTIN(__builtin_altivec_dss, "vUi", "") +BUILTIN(__builtin_altivec_dss, "vUIi", "") BUILTIN(__builtin_altivec_dssall, "v", "") BUILTIN(__builtin_altivec_dst, "vvC*iUi", "") BUILTIN(__builtin_altivec_dstt, "vvC*iUi", "") diff --git a/lib/Headers/altivec.h b/lib/Headers/altivec.h index 4008440b2b..a7f480e45d 100644 --- a/lib/Headers/altivec.h +++ b/lib/Headers/altivec.h @@ -3286,9 +3286,7 @@ static __inline__ vector double __ATTRS_o_ai vec_div(vector double __a, /* vec_dss */ -static __inline__ void __attribute__((__always_inline__)) vec_dss(int __a) { - __builtin_altivec_dss(__a); -} +#define vec_dss __builtin_altivec_dss /* vec_dssall */ diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index f6a705a70a..bb06517ad5 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3220,6 +3220,8 @@ bool Sema::CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { case PPC::BI__builtin_altivec_crypto_vshasigmad: return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) || SemaBuiltinConstantArgRange(TheCall, 2, 0, 15); + case PPC::BI__builtin_altivec_dss: + return SemaBuiltinConstantArgRange(TheCall, 0, 0, 3); case PPC::BI__builtin_tbegin: case PPC::BI__builtin_tend: i = 0; l = 0; u = 1; break; case PPC::BI__builtin_tsr: i = 0; l = 0; u = 7; break; diff --git a/test/CodeGen/altivec-dss.c b/test/CodeGen/altivec-dss.c new file mode 100644 index 0000000000..e1b277791d --- /dev/null +++ b/test/CodeGen/altivec-dss.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple powerpc-linux-gnu -S -O0 -o - %s -target-feature +altivec | FileCheck %s + +// REQUIRES: powerpc-registered-target + +#include + +// CHECK-LABEL: test1 +// CHECK: dss +void test1() { + vec_dss(1); +} diff --git a/test/CodeGen/builtins-ppc-error.c b/test/CodeGen/builtins-ppc-error.c index a50dc2cba0..067f6b4970 100644 --- a/test/CodeGen/builtins-ppc-error.c +++ b/test/CodeGen/builtins-ppc-error.c @@ -73,3 +73,8 @@ void testUnpack128(int index) { __builtin_unpack_vector_int128(vsllli, index); //expected-error {{argument to '__builtin_unpack_vector_int128' must be a constant integer}} __builtin_unpack_vector_int128(vsllli, 5); //expected-error {{argument value 5 is outside the valid range [0, 1]}} } + +void testDSS(int index) { + vec_dss(index); //expected-error {{argument to '__builtin_altivec_dss' must be a constant integer}} + vec_dss(5); //expected-error {{argument value 5 is outside the valid range [0, 3]}} +} -- 2.40.0