<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 9, 2016 at 11:33 AM Kit Barton via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kbarton<br>
Date: Wed Mar  9 13:28:31 2016<br>
New Revision: 263051<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=263051&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=263051&view=rev</a><br>
Log:<br>
[PPC] FE support for generating VSX [negated] absolute value instructions<br>
<br>
Includes new built-in, conversion of built-in to target-independent intrinsic<br>
and update in the header file. Tests are also updated. There is a second part in<br>
the backend for which I will post a separate code-review. BACKEND PART SHOULD BE<br>
COMMITTED FIRST.<br>
<br></blockquote><div><br></div><div>Did you mean to commit this? Or just forget to edit your commit message?</div><div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Phabricator: <a href="http://reviews.llvm.org/D17816" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17816</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/BuiltinsPPC.def<br>
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
    cfe/trunk/lib/Headers/altivec.h<br>
    cfe/trunk/test/CodeGen/builtins-ppc-altivec.c<br>
    cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c<br>
    cfe/trunk/test/CodeGen/builtins-ppc-vsx.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/BuiltinsPPC.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/BuiltinsPPC.def (original)<br>
+++ cfe/trunk/include/clang/Basic/BuiltinsPPC.def Wed Mar  9 13:28:31 2016<br>
@@ -336,6 +336,9 @@ BUILTIN(__builtin_vsx_xxleqv, "V4UiV4UiV<br>
 BUILTIN(__builtin_vsx_xvcpsgndp, "V2dV2dV2d", "")<br>
 BUILTIN(__builtin_vsx_xvcpsgnsp, "V4fV4fV4f", "")<br>
<br>
+BUILTIN(__builtin_vsx_xvabssp, "V4fV4f", "")<br>
+BUILTIN(__builtin_vsx_xvabsdp, "V2dV2d", "")<br>
+<br>
 // HTM builtins<br>
 BUILTIN(__builtin_tbegin, "UiUIi", "")<br>
 BUILTIN(__builtin_tend, "UiUIi", "")<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar  9 13:28:31 2016<br>
@@ -6992,6 +6992,16 @@ Value *CodeGenFunction::EmitPPCBuiltinEx<br>
     llvm::Function *F = CGM.getIntrinsic(ID, ResultType);<br>
     return Builder.CreateCall(F, X);<br>
   }<br>
+<br>
+  // Absolute value<br>
+  case PPC::BI__builtin_vsx_xvabsdp:<br>
+  case PPC::BI__builtin_vsx_xvabssp: {<br>
+    llvm::Type *ResultType = ConvertType(E->getType());<br>
+    Value *X = EmitScalarExpr(E->getArg(0));<br>
+    llvm::Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType);<br>
+    return Builder.CreateCall(F, X);<br>
+  }<br>
+<br>
   // FMA variations<br>
   case PPC::BI__builtin_vsx_xvmaddadp:<br>
   case PPC::BI__builtin_vsx_xvmaddasp:<br>
<br>
Modified: cfe/trunk/lib/Headers/altivec.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Headers/altivec.h (original)<br>
+++ cfe/trunk/lib/Headers/altivec.h Wed Mar  9 13:28:31 2016<br>
@@ -124,16 +124,18 @@ vec_abs(vector signed long long __a) {<br>
 #endif<br>
<br>
 static vector float __ATTRS_o_ai vec_abs(vector float __a) {<br>
+#ifdef __VSX__<br>
+  return __builtin_vsx_xvabssp(__a);<br>
+#else<br>
   vector unsigned int __res =<br>
       (vector unsigned int)__a & (vector unsigned int)(0x7FFFFFFF);<br>
   return (vector float)__res;<br>
+#endif<br>
 }<br>
<br>
 #if defined(__POWER8_VECTOR__) && defined(__powerpc64__)<br>
 static vector double __ATTRS_o_ai vec_abs(vector double __a) {<br>
-  vector unsigned long long __res = { 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF };<br>
-  __res &= (vector unsigned int)__a;<br>
-  return (vector double)__res;<br>
+  return __builtin_vsx_xvabsdp(__a);<br>
 }<br>
 #endif<br>
<br>
<br>
Modified: cfe/trunk/test/CodeGen/builtins-ppc-altivec.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-altivec.c?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-altivec.c?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/builtins-ppc-altivec.c (original)<br>
+++ cfe/trunk/test/CodeGen/builtins-ppc-altivec.c Wed Mar  9 13:28:31 2016<br>
@@ -1,7 +1,13 @@<br>
 // REQUIRES: powerpc-registered-target<br>
-// RUN: %clang_cc1 -faltivec -triple powerpc-unknown-unknown -emit-llvm %s -o - | FileCheck %s<br>
-// RUN: %clang_cc1 -faltivec -triple powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s<br>
-// RUN: %clang_cc1 -faltivec -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-LE<br>
+// RUN: %clang_cc1 -faltivec -triple powerpc-unknown-unknown -emit-llvm %s \<br>
+// RUN:            -o - | FileCheck %s<br>
+// RUN: %clang_cc1 -faltivec -triple powerpc64-unknown-unknown -emit-llvm %s \<br>
+// RUN:            -o - | FileCheck %s<br>
+// RUN: %clang_cc1 -faltivec -triple powerpc64le-unknown-unknown -emit-llvm %s \<br>
+// RUN:            -o - | FileCheck %s -check-prefix=CHECK-LE<br>
+// RUN: not %clang_cc1 -triple powerpc64le-unknown-unknown -emit-llvm %s \<br>
+// RUN:            -ferror-limit 0 -o - 2>&1 \<br>
+// RUN:            | FileCheck %s -check-prefix=CHECK-NOALTIVEC<br>
<br>
 vector bool char vbc = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };<br>
 vector signed char vsc = { 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16 };<br>
@@ -27,6 +33,8 @@ vector int res_vi;<br>
 vector unsigned int res_vui;<br>
 vector float res_vf;<br>
<br>
+// CHECK-NOALTIVEC: error: unknown type name 'vector'<br>
+<br>
 signed char param_sc;<br>
 unsigned char param_uc;<br>
 short param_s;<br>
@@ -66,8 +74,16 @@ void test1() {<br>
 // CHECK-LE: @llvm.ppc.altivec.vmaxsw<br>
<br>
   vf = vec_abs(vf);<br>
-// CHECK: and <4 x i32><br>
-// CHECK-LE: and <4 x i32><br>
+// CHECK: bitcast <4 x float> %{{.*}} to <4 x i32><br>
+// CHECK: and <4 x i32> {{.*}}, <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647><br>
+// CHECK: bitcast <4 x i32> %{{.*}} to <4 x float><br>
+// CHECK: store <4 x float> %{{.*}}, <4 x float>* @vf<br>
+// CHECK-LE: bitcast <4 x float> %{{.*}} to <4 x i32><br>
+// CHECK-LE: and <4 x i32> {{.*}}, <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647><br>
+// CHECK-LE: bitcast <4 x i32> %{{.*}} to <4 x float><br>
+// CHECK-LE: store <4 x float> %{{.*}}, <4 x float>* @vf<br>
+// CHECK-NOALTIVEC: error: use of undeclared identifier 'vf'<br>
+// CHECK-NOALTIVEC: vf = vec_abs(vf)<br>
<br>
   /* vec_abs */<br>
   vsc = vec_abss(vsc);<br>
<br>
Modified: cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c (original)<br>
+++ cfe/trunk/test/CodeGen/builtins-ppc-p8vector.c Wed Mar  9 13:28:31 2016<br>
@@ -73,10 +73,10 @@ void test1() {<br>
 // CHECK-PPC: error: call to 'vec_abs' is ambiguous<br>
<br>
   res_vd = vec_abs(vda);<br>
-// CHECK: store <2 x i64> <i64 9223372036854775807, i64 9223372036854775807>, <2 x i64>*<br>
-// CHECK: and <2 x i64><br>
-// CHECK-LE: store <2 x i64> <i64 9223372036854775807, i64 9223372036854775807>, <2 x i64>*<br>
-// CHECK-LE: and <2 x i64><br>
+// CHECK: call <2 x double> @llvm.fabs.v2f64(<2 x double> %{{.*}})<br>
+// CHECK: store <2 x double> %{{.*}}, <2 x double>* @res_vd<br>
+// CHECK-LE: call <2 x double> @llvm.fabs.v2f64(<2 x double> %{{.*}})<br>
+// CHECK-LE: store <2 x double> %{{.*}}, <2 x double>* @res_vd<br>
 // CHECK-PPC: error: call to 'vec_abs' is ambiguous<br>
<br>
   /* vec_add */<br>
<br>
Modified: cfe/trunk/test/CodeGen/builtins-ppc-vsx.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-vsx.c?rev=263051&r1=263050&r2=263051&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-vsx.c?rev=263051&r1=263050&r2=263051&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/builtins-ppc-vsx.c (original)<br>
+++ cfe/trunk/test/CodeGen/builtins-ppc-vsx.c Wed Mar  9 13:28:31 2016<br>
@@ -51,6 +51,14 @@ void test1() {<br>
 // CHECK-LABEL: define void @test1<br>
 // CHECK-LE-LABEL: define void @test1<br>
<br>
+  res_vf = vec_abs(vf);<br>
+// CHECK: call <4 x float> @llvm.fabs.v4f32(<4 x float> %{{[0-9]*}})<br>
+// CHECK-LE: call <4 x float> @llvm.fabs.v4f32(<4 x float> %{{[0-9]*}})<br>
+<br>
+  dummy();<br>
+// CHECK: call void @dummy()<br>
+// CHECK-LE: call void @dummy()<br>
+<br>
   res_vd = vec_add(vd, vd);<br>
 // CHECK: fadd <2 x double><br>
 // CHECK-LE: fadd <2 x double><br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>