[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-24 Thread Tony Jiang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jtony marked 2 inline comments as done.
Closed by commit rL303760: [PowerPC] Implement vec_xxpermdi builtin. (authored 
by jtony).

Changed prior to commit:
  https://reviews.llvm.org/D33053?vs=99966&id=100093#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33053

Files:
  cfe/trunk/include/clang/Basic/BuiltinsPPC.def
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Headers/altivec.h
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/CodeGen/builtins-ppc-error.c
  cfe/trunk/test/CodeGen/builtins-ppc-vsx.c

Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1696,6 +1696,8 @@
   case PPC::BI__builtin_tabortdci:
 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) ||
SemaBuiltinConstantArgRange(TheCall, 2, 0, 31);
+  case PPC::BI__builtin_vsx_xxpermdi:
+return SemaBuiltinVSX(TheCall);
   }
   return SemaBuiltinConstantArgRange(TheCall, i, l, u);
 }
@@ -3892,6 +3894,65 @@
   return false;
 }
 
+// Customized Sema Checking for VSX builtins that have the following signature:
+// vector [...] builtinName(vector [...], vector [...], const int);
+// Which takes the same type of vectors (any legal vector type) for the first
+// two arguments and takes compile time constant for the third argument.
+// Example builtins are :
+// vector double vec_xxpermdi(vector double, vector double, int);
+// vector short vec_xxsldwi(vector short, vector short, int);
+bool Sema::SemaBuiltinVSX(CallExpr *TheCall) {
+  unsigned ExpectedNumArgs = 3;
+  if (TheCall->getNumArgs() < ExpectedNumArgs)
+return Diag(TheCall->getLocEnd(),
+diag::err_typecheck_call_too_few_args_at_least)
+   << 0 /*function call*/ <<  ExpectedNumArgs << TheCall->getNumArgs()
+   << TheCall->getSourceRange();
+
+  if (TheCall->getNumArgs() > ExpectedNumArgs)
+return Diag(TheCall->getLocEnd(),
+diag::err_typecheck_call_too_many_args_at_most)
+   << 0 /*function call*/ << ExpectedNumArgs << TheCall->getNumArgs()
+   << TheCall->getSourceRange();
+
+  // Check the third argument is a compile time constant
+  llvm::APSInt Value;
+  if(!TheCall->getArg(2)->isIntegerConstantExpr(Value, Context))
+return Diag(TheCall->getLocStart(),
+diag::err_vsx_builtin_nonconstant_argument)
+   << 3 /* argument index */ << TheCall->getDirectCallee()
+   << SourceRange(TheCall->getArg(2)->getLocStart(),
+  TheCall->getArg(2)->getLocEnd());
+
+  QualType Arg1Ty = TheCall->getArg(0)->getType();
+  QualType Arg2Ty = TheCall->getArg(1)->getType();
+
+  // Check the type of argument 1 and argument 2 are vectors.
+  SourceLocation BuiltinLoc = TheCall->getLocStart();
+  if ((!Arg1Ty->isVectorType() && !Arg1Ty->isDependentType()) ||
+  (!Arg2Ty->isVectorType() && !Arg2Ty->isDependentType())) {
+return Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
+   << TheCall->getDirectCallee()
+   << SourceRange(TheCall->getArg(0)->getLocStart(),
+  TheCall->getArg(1)->getLocEnd());
+  }
+
+  // Check the first two arguments are the same type.
+  if (!Context.hasSameUnqualifiedType(Arg1Ty, Arg2Ty)) {
+return Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
+   << TheCall->getDirectCallee()
+   << SourceRange(TheCall->getArg(0)->getLocStart(),
+  TheCall->getArg(1)->getLocEnd());
+  }
+
+  // When default clang type checking is turned off and the customized type
+  // checking is used, the returning type of the function must be explicitly
+  // set. Otherwise it is _Bool by default.
+  TheCall->setType(Arg1Ty);
+
+  return false;
+}
+
 /// SemaBuiltinShuffleVector - Handle __builtin_shufflevector.
 // This is declared to take (...), so we have to check everything.
 ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
Index: cfe/trunk/lib/Headers/altivec.h
===
--- cfe/trunk/lib/Headers/altivec.h
+++ cfe/trunk/lib/Headers/altivec.h
@@ -12156,6 +12156,10 @@
 
 #endif
 
+#ifdef __VSX__
+#define vec_xxpermdi __builtin_vsx_xxpermdi
+#endif
+
 /* vec_xor */
 
 #define __builtin_altivec_vxor vec_xor
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -8442,6 +8442,39 @@
   return Builder.CreateCall(F, Ops);
 }
   }
+
+  case PPC::BI__builtin_vsx_xxpermdi: {
+ConstantInt *ArgCI = dyn_cast(Ops[2]);
+assert(ArgCI && "Third arg must be constant integer!");
+
+unsigned Index = ArgCI->getZExtValue();
+Ops[0

[PATCH] D39376: [PowerPC] Add implementation for -msave-toc-indirect option - clang portion

2017-11-28 Thread Tony Jiang via Phabricator via cfe-commits
jtony added inline comments.



Comment at: test/Driver/ppc-features.cpp:140
+
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-htm -### -o %t.o 
2>&1 | FileCheck -check-prefix=CHECK-NOHTM %s
 // CHECK-NOHTM: "-target-feature" "-htm"

We probably need to add test  for mno_save_toc_indirect also once you add it 
according to Hal's suggestion.


https://reviews.llvm.org/D39376



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27872: [APFloat] Switch from (PPCDoubleDoubleImpl, IEEEdouble) layout to (IEEEdouble, IEEEdouble)

2016-12-16 Thread Tony Jiang via Phabricator via cfe-commits
jtony added inline comments.



Comment at: llvm/include/llvm/ADT/APFloat.h:800
 
-  void makeLargest(bool Neg) { getIEEE().makeLargest(Neg); }
+  void makeLargest(bool Neg) {
+if (usesLayout(getSemantics())) {

I know it is allowed to return a void function call inside a void function, but 
I think this reduces the code readability in general and causes some confusing 
to some people. Maybe it is better to avoid using this kind of coding style. I 
think we can simply call each function in each branch without the 'return' 
keyword, by default, the program will reach the end of function and return.  

One possible equivalent code:

void makeNaN(bool SNaN, bool Neg, const APInt *fill) {
if (usesLayout(getSemantics())) {
  U.IEEE.makeNaN(SNaN, Neg, fill);
} else if (usesLayout(getSemantics())) {
  U.Double.makeNaN(SNaN, Neg, fill);
} else {
  llvm_unreachable("Unexpected semantics");
}
  }



Comment at: llvm/include/llvm/ADT/APFloat.h:811
+  void makeSmallest(bool Neg) {
+if (usesLayout(getSemantics())) {
+  return U.IEEE.makeSmallest(Neg);

Same here.



Comment at: llvm/include/llvm/ADT/APFloat.h:821
   void makeSmallestNormalized(bool Neg) {
-getIEEE().makeSmallestNormalized(Neg);
+if (usesLayout(getSemantics())) {
+  return U.IEEE.makeSmallestNormalized(Neg);

Same here.



Comment at: llvm/include/llvm/ADT/APFloat.h:1100
 
-  void changeSign() { getIEEE().changeSign(); }
-  void clearSign() { getIEEE().clearSign(); }
-  void copySign(const APFloat &RHS) { getIEEE().copySign(RHS.getIEEE()); }
+  void changeSign() {
+if (usesLayout(getSemantics())) {

Same here.


https://reviews.llvm.org/D27872



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28528: [PowerPC] [PowerPC] Fix the wrong implementation of builtin vec_rlnm.

2017-01-10 Thread Tony Jiang via Phabricator via cfe-commits
jtony created this revision.
jtony added reviewers: nemanjai, kbarton, sfertile, lei, syzaara.
jtony added subscribers: llvm-commits, cfe-commits, hfinkel, echristo.

vec_rlnm was implemented according to the old ABI, which was wrong. The ABI 
team have fixed the issue (although not published yet). We need to re-implement 
these builtins according to the new ABI.

From (old implementation):
__builtin_altivec_vrlwnm(__a, __b) & __c;

To (new implementation):
vector unsigned int OneByte = { 0x8, 0x8, 0x8, 0x8 };
__builtin_altivec_vrlwnm(a, ((c << OneByte) | b));


https://reviews.llvm.org/D28528

Files:
  lib/Headers/altivec.h
  test/CodeGen/builtins-ppc-p9vector.c


Index: test/CodeGen/builtins-ppc-p9vector.c
===
--- test/CodeGen/builtins-ppc-p9vector.c
+++ test/CodeGen/builtins-ppc-p9vector.c
@@ -868,20 +868,24 @@
   return vec_rlmi(vula, vula, vula);
 }
 vector unsigned int test77(void) {
+// CHECK-BE: %shl.i = shl <4 x i32
+// CHECK-BE: %or.i = or <4 x i32> %shl.i
 // CHECK-BE: @llvm.ppc.altivec.vrlwnm(<4 x i32
-// CHECK-BE: and <4 x i32
 // CHECK-BE: ret <4 x i32>
+// CHECK: %shl.i = shl <4 x i32
+// CHECK: %or.i = or <4 x i32> %shl.i
 // CHECK: @llvm.ppc.altivec.vrlwnm(<4 x i32
-// CHECK: and <4 x i32
 // CHECK: ret <4 x i32>
   return vec_rlnm(vuia, vuia, vuia);
 }
 vector unsigned long long test78(void) {
+// CHECK-BE: %shl.i = shl <2 x i64
+// CHECK-BE: %or.i = or <2 x i64> %shl.i
 // CHECK-BE: @llvm.ppc.altivec.vrldnm(<2 x i64
-// CHECK-BE: and <2 x i64
 // CHECK-BE-NEXT: ret <2 x i64>
+// CHECK: %shl.i = shl <2 x i64
+// CHECK: %or.i = or <2 x i64> %shl.i
 // CHECK: @llvm.ppc.altivec.vrldnm(<2 x i64
-// CHECK: and <2 x i64
 // CHECK-NEXT: ret <2 x i64>
   return vec_rlnm(vula, vula, vula);
 }
Index: lib/Headers/altivec.h
===
--- lib/Headers/altivec.h
+++ lib/Headers/altivec.h
@@ -7664,13 +7664,15 @@
 static __inline__ vector unsigned int __ATTRS_o_ai
 vec_rlnm(vector unsigned int __a, vector unsigned int __b,
  vector unsigned int __c) {
-  return __builtin_altivec_vrlwnm(__a, __b) & __c;
+  vector unsigned int OneByte = { 0x8, 0x8, 0x8, 0x8 };
+  return __builtin_altivec_vrlwnm(__a, ((__c << OneByte) | __b));
 }
 
 static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_rlnm(vector unsigned long long __a, vector unsigned long long __b,
  vector unsigned long long __c) {
-  return __builtin_altivec_vrldnm(__a, __b) & __c;
+  vector unsigned long long OneByte = { 0x8, 0x8 };
+  return __builtin_altivec_vrldnm(__a, ((__c << OneByte) | __b));
 }
 #endif
 


Index: test/CodeGen/builtins-ppc-p9vector.c
===
--- test/CodeGen/builtins-ppc-p9vector.c
+++ test/CodeGen/builtins-ppc-p9vector.c
@@ -868,20 +868,24 @@
   return vec_rlmi(vula, vula, vula);
 }
 vector unsigned int test77(void) {
+// CHECK-BE: %shl.i = shl <4 x i32
+// CHECK-BE: %or.i = or <4 x i32> %shl.i
 // CHECK-BE: @llvm.ppc.altivec.vrlwnm(<4 x i32
-// CHECK-BE: and <4 x i32
 // CHECK-BE: ret <4 x i32>
+// CHECK: %shl.i = shl <4 x i32
+// CHECK: %or.i = or <4 x i32> %shl.i
 // CHECK: @llvm.ppc.altivec.vrlwnm(<4 x i32
-// CHECK: and <4 x i32
 // CHECK: ret <4 x i32>
   return vec_rlnm(vuia, vuia, vuia);
 }
 vector unsigned long long test78(void) {
+// CHECK-BE: %shl.i = shl <2 x i64
+// CHECK-BE: %or.i = or <2 x i64> %shl.i
 // CHECK-BE: @llvm.ppc.altivec.vrldnm(<2 x i64
-// CHECK-BE: and <2 x i64
 // CHECK-BE-NEXT: ret <2 x i64>
+// CHECK: %shl.i = shl <2 x i64
+// CHECK: %or.i = or <2 x i64> %shl.i
 // CHECK: @llvm.ppc.altivec.vrldnm(<2 x i64
-// CHECK: and <2 x i64
 // CHECK-NEXT: ret <2 x i64>
   return vec_rlnm(vula, vula, vula);
 }
Index: lib/Headers/altivec.h
===
--- lib/Headers/altivec.h
+++ lib/Headers/altivec.h
@@ -7664,13 +7664,15 @@
 static __inline__ vector unsigned int __ATTRS_o_ai
 vec_rlnm(vector unsigned int __a, vector unsigned int __b,
  vector unsigned int __c) {
-  return __builtin_altivec_vrlwnm(__a, __b) & __c;
+  vector unsigned int OneByte = { 0x8, 0x8, 0x8, 0x8 };
+  return __builtin_altivec_vrlwnm(__a, ((__c << OneByte) | __b));
 }
 
 static __inline__ vector unsigned long long __ATTRS_o_ai
 vec_rlnm(vector unsigned long long __a, vector unsigned long long __b,
  vector unsigned long long __c) {
-  return __builtin_altivec_vrldnm(__a, __b) & __c;
+  vector unsigned long long OneByte = { 0x8, 0x8 };
+  return __builtin_altivec_vrldnm(__a, ((__c << OneByte) | __b));
 }
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27251: [PPC] some bugs mainly about sign problem fixed in altivec.h

2016-11-30 Thread Tony Jiang via Phabricator via cfe-commits
jtony added inline comments.



Comment at: lib/Headers/altivec.h:16456
 
 #ifdef __VSX__
 static __inline__ vector signed long long __ATTRS_o_ai

Thanks  a lot for your good catch for the macro issue in vec_xst_be, that's a 
good catch. BTW, Can you move this up also like vec_xst_be?



Comment at: test/CodeGen/builtins-ppc-vsx.c:1696
+
+signed char param_sc;
+unsigned char param_uc;

I would prefer these definitions occur at the beginning of the file like 
before. 



Comment at: test/CodeGen/builtins-ppc-vsx.c:1706
+/* - vec_xl_be -- 
*/
+void test2() {
+  // CHECK-LABEL: define void @test2

These test cases should be grouped together with the test  cases from 1663 - 
1683. Put the vec_xl_be overloads together,  and the vec_xst_be together (maybe 
after vec_xl_be). I am OK with either put these test2 and test3 into test 1, or 
make them stand-alone, as long as these overloaded test cases for vec_xst_be 
and vec_xl_be are put together seperately. Thanks for you good catch, this 
problem is not found in our previous code review.


https://reviews.llvm.org/D27251



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-10 Thread Tony Jiang via Phabricator via cfe-commits
jtony created this revision.

The vec_xxpermdi builtin is missing from altivec.h. This has been requested by 
developers working on libvpx for VP9 support for Google.  Initially, I tried to 
define a new intrinsic to map it to the corresponding PowerPC hard instruction 
(XXPERMDI) directly. But there was feedback from the community that this can be 
done without introducing new intrinsic.  This patch re-implement the 
vec_xxpermdi builtin by using the existing shuffleVector instruction just in 
the FE.


https://reviews.llvm.org/D33053

Files:
  include/clang/Basic/BuiltinsPPC.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/altivec.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-ppc-error.c
  test/CodeGen/builtins-ppc-vsx.c

Index: test/CodeGen/builtins-ppc-vsx.c
===
--- test/CodeGen/builtins-ppc-vsx.c
+++ test/CodeGen/builtins-ppc-vsx.c
@@ -1691,4 +1691,44 @@
   res_vd = vec_neg(vd);
 // CHECK: fsub <2 x double> , {{%[0-9]+}}
 // CHECK-LE: fsub <2 x double> , {{%[0-9]+}}
+
+res_vd = vec_xxpermdi(vd, vd, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vf = vec_xxpermdi(vf, vf, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsll = vec_xxpermdi(vsll, vsll, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vull = vec_xxpermdi(vull, vull, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsi = vec_xxpermdi(vsi, vsi, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vui = vec_xxpermdi(vui, vui, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vss = vec_xxpermdi(vss, vss, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vus = vec_xxpermdi(vus, vus, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsc = vec_xxpermdi(vsc, vsc, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vuc = vec_xxpermdi(vuc, vuc, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
 }
Index: test/CodeGen/builtins-ppc-error.c
===
--- test/CodeGen/builtins-ppc-error.c
+++ test/CodeGen/builtins-ppc-error.c
@@ -13,8 +13,17 @@
 extern vector signed int vsi;
 extern vector unsigned char vuc;
 
-void testInsertWord1(void) {
+void testInsertWord(void) {
   int index = 5;
   vector unsigned char v1 = vec_insert4b(vsi, vuc, index); // expected-error {{argument to '__builtin_vsx_insertword' must be a constant integer}}
   vector unsigned long long v2 = vec_extract4b(vuc, index);   // expected-error {{argument to '__builtin_vsx_extractuword' must be a constant integer}}
 }
+
+void testXXPERMDI(void) {
+  int index = 5;
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
+  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxpermdi(vsi, vsi, index); //expected-error {{third argument to '__builtin_vsx_xxpermdi' must be a constant integer between 0-3}}
+  vec_xxpermdi(vsi, vsi, -1); //expected-error {{third argument to '__builtin_vsx_xxpermdi' must be a constant integer between 0-3}}
+  vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must be the same type}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1696,6 +1696,8 @@
   case PPC::BI__builtin_tabortdci:
 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) ||
SemaBuiltinConstantArgRange(TheCall, 2, 0, 31);
+  case PPC::BI__builtin_vsx_xxpermdi:
+return SemaBuiltinVSX(TheCall, 3);
   }
   return SemaBuiltinConstantArgRange(TheCall, i, l, u

[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-16 Thread Tony Jiang via Phabricator via cfe-commits
jtony marked 6 inline comments as done.
jtony added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:8433
+if (getTarget().isLittleEndian()) {
+  switch (Index) {
+  case 0:

nemanjai wrote:
> The switch is overkill. You should just implement this in an obvious way 
> (i.e. the same way as described in the ISA).
> For big endian:
> `ElemIdx0 = (Index & 2;) >> 1`
> `ElemIdx1 = 2 + (Index & 1)`
> 
> For little endian:
> `ElemIdx0 = (~Index & 1) + 2;`
> `ElemIdx1 = ~Index & 2 >> 1;`
> 
> (of course, please verify the expressions).
Good call, fixed as suggested.


https://reviews.llvm.org/D33053



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-17 Thread Tony Jiang via Phabricator via cfe-commits
jtony updated this revision to Diff 99292.
jtony added a comment.

Address all the comments from Nemanja.


https://reviews.llvm.org/D33053

Files:
  include/clang/Basic/BuiltinsPPC.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/altivec.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-ppc-error.c
  test/CodeGen/builtins-ppc-vsx.c

Index: test/CodeGen/builtins-ppc-vsx.c
===
--- test/CodeGen/builtins-ppc-vsx.c
+++ test/CodeGen/builtins-ppc-vsx.c
@@ -1691,4 +1691,60 @@
   res_vd = vec_neg(vd);
 // CHECK: fsub <2 x double> , {{%[0-9]+}}
 // CHECK-LE: fsub <2 x double> , {{%[0-9]+}}
+
+res_vd = vec_xxpermdi(vd, vd, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vf = vec_xxpermdi(vf, vf, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsll = vec_xxpermdi(vsll, vsll, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vull = vec_xxpermdi(vull, vull, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsi = vec_xxpermdi(vsi, vsi, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vui = vec_xxpermdi(vui, vui, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vss = vec_xxpermdi(vss, vss, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vus = vec_xxpermdi(vus, vus, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsc = vec_xxpermdi(vsc, vsc, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vuc = vec_xxpermdi(vuc, vuc, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+}
+
+// The return type of the call expression may be different from the return type of the shufflevector.
+// Wrong implementation could crash the compiler, add this test case to check that and avoid ICE.
+vector int should_not_assert(vector int a, vector int b) {
+  return vec_xxpermdi(a, b, 0);
+// CHECK-LABEL: should_not_assert
+// CHECK:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
+
+// CHECK-LE:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
 }
Index: test/CodeGen/builtins-ppc-error.c
===
--- test/CodeGen/builtins-ppc-error.c
+++ test/CodeGen/builtins-ppc-error.c
@@ -13,8 +13,16 @@
 extern vector signed int vsi;
 extern vector unsigned char vuc;
 
-void testInsertWord1(void) {
+void testInsertWord(void) {
   int index = 5;
   vector unsigned char v1 = vec_insert4b(vsi, vuc, index); // expected-error {{argument to '__builtin_vsx_insertword' must be a constant integer}}
   vector unsigned long long v2 = vec_extract4b(vuc, index);   // expected-error {{argument to '__builtin_vsx_extractuword' must be a constant integer}}
 }
+
+void testXXPERMDI(void) {
+  int index = 5;
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
+  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxpermdi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxpermdi' must be a 2-bit unsigned literal (i.e. 0,1,2 or 3)}}
+  vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must have the same type}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp

[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-23 Thread Tony Jiang via Phabricator via cfe-commits
jtony added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:3900
+// vector short vec_xxsldwi(vector short, vector short, int);
+bool Sema::SemaBuiltinVSX(CallExpr *TheCall, unsigned NumArgs) {
+  if (TheCall->getNumArgs() < NumArgs)

nemanjai wrote:
> I assume that we won't even need this at all if we're not diagnosing the 
> range of the third argument.
Changed to just check it is Compile Time constant without check the range.



Comment at: test/CodeGen/builtins-ppc-error.c:23
+void testXXPERMDI(void) {
+  int index = 5;
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, 
expected at least 3, have 1}}

inouehrs wrote:
> I am not sure we can assure that clang always do a constant propagation to 
> resolve `index` as a compile time constant. But it seems that an existing 
> test case above already assumes clang does it. 
> IMO, `const unsigned index = 5;` is a little better.
Hi Hiroshi, the index is used as a non-constant variable test input to test the 
diagnostic message. We want it to be a variable here. But I guess I can leave 
it uninitialized to be clear.


https://reviews.llvm.org/D33053



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-23 Thread Tony Jiang via Phabricator via cfe-commits
jtony updated this revision to Diff 99955.
jtony marked 6 inline comments as done.
jtony added a comment.

Address more comments from Nemanja and Hiroshi.


https://reviews.llvm.org/D33053

Files:
  include/clang/Basic/BuiltinsPPC.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/altivec.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-ppc-error.c
  test/CodeGen/builtins-ppc-vsx.c

Index: test/CodeGen/builtins-ppc-vsx.c
===
--- test/CodeGen/builtins-ppc-vsx.c
+++ test/CodeGen/builtins-ppc-vsx.c
@@ -1691,4 +1691,60 @@
   res_vd = vec_neg(vd);
 // CHECK: fsub <2 x double> , {{%[0-9]+}}
 // CHECK-LE: fsub <2 x double> , {{%[0-9]+}}
+
+res_vd = vec_xxpermdi(vd, vd, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vf = vec_xxpermdi(vf, vf, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsll = vec_xxpermdi(vsll, vsll, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vull = vec_xxpermdi(vull, vull, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsi = vec_xxpermdi(vsi, vsi, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vui = vec_xxpermdi(vui, vui, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vss = vec_xxpermdi(vss, vss, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vus = vec_xxpermdi(vus, vus, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsc = vec_xxpermdi(vsc, vsc, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vuc = vec_xxpermdi(vuc, vuc, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+}
+
+// The return type of the call expression may be different from the return type of the shufflevector.
+// Wrong implementation could crash the compiler, add this test case to check that and avoid ICE.
+vector int xxpermdi_should_not_assert(vector int a, vector int b) {
+  return vec_xxpermdi(a, b, 0);
+// CHECK-LABEL: xxpermdi_should_not_assert
+// CHECK:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
+
+// CHECK-LE:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
 }
Index: test/CodeGen/builtins-ppc-error.c
===
--- test/CodeGen/builtins-ppc-error.c
+++ test/CodeGen/builtins-ppc-error.c
@@ -13,8 +13,16 @@
 extern vector signed int vsi;
 extern vector unsigned char vuc;
 
-void testInsertWord1(void) {
+void testInsertWord(void) {
   int index = 5;
   vector unsigned char v1 = vec_insert4b(vsi, vuc, index); // expected-error {{argument to '__builtin_vsx_insertword' must be a constant integer}}
   vector unsigned long long v2 = vec_extract4b(vuc, index);   // expected-error {{argument to '__builtin_vsx_extractuword' must be a constant integer}}
 }
+
+void testXXPERMDI(int index) {
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
+  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxpermdi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxpermdi' must be a 2-bit unsigned literal (i.e. 0,1,2 or 3)}}
+  vec_xxpermdi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must be vectors}}
+  vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpe

[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-23 Thread Tony Jiang via Phabricator via cfe-commits
jtony updated this revision to Diff 99966.

https://reviews.llvm.org/D33053

Files:
  include/clang/Basic/BuiltinsPPC.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/altivec.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins-ppc-error.c
  test/CodeGen/builtins-ppc-vsx.c

Index: test/CodeGen/builtins-ppc-vsx.c
===
--- test/CodeGen/builtins-ppc-vsx.c
+++ test/CodeGen/builtins-ppc-vsx.c
@@ -1691,4 +1691,60 @@
   res_vd = vec_neg(vd);
 // CHECK: fsub <2 x double> , {{%[0-9]+}}
 // CHECK-LE: fsub <2 x double> , {{%[0-9]+}}
+
+res_vd = vec_xxpermdi(vd, vd, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vf = vec_xxpermdi(vf, vf, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsll = vec_xxpermdi(vsll, vsll, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vull = vec_xxpermdi(vull, vull, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsi = vec_xxpermdi(vsi, vsi, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vui = vec_xxpermdi(vui, vui, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vss = vec_xxpermdi(vss, vss, 2);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vus = vec_xxpermdi(vus, vus, 3);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vsc = vec_xxpermdi(vsc, vsc, 0);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+
+res_vuc = vec_xxpermdi(vuc, vuc, 1);
+// CHECK: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE: shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+}
+
+// The return type of the call expression may be different from the return type of the shufflevector.
+// Wrong implementation could crash the compiler, add this test case to check that and avoid ICE.
+vector int xxpermdi_should_not_assert(vector int a, vector int b) {
+  return vec_xxpermdi(a, b, 0);
+// CHECK-LABEL: xxpermdi_should_not_assert
+// CHECK:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
+
+// CHECK-LE:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  bitcast <4 x i32> %{{[0-9]+}} to <2 x i64>
+// CHECK-LE-NEXT:  shufflevector <2 x i64> %{{[0-9]+}}, <2 x i64> %{{[0-9]+}}, <2 x i32> 
+// CHECK-LE-NEXT:  bitcast <2 x i64> %{{[0-9]+}} to <4 x i32>
 }
Index: test/CodeGen/builtins-ppc-error.c
===
--- test/CodeGen/builtins-ppc-error.c
+++ test/CodeGen/builtins-ppc-error.c
@@ -13,8 +13,16 @@
 extern vector signed int vsi;
 extern vector unsigned char vuc;
 
-void testInsertWord1(void) {
+void testInsertWord(void) {
   int index = 5;
   vector unsigned char v1 = vec_insert4b(vsi, vuc, index); // expected-error {{argument to '__builtin_vsx_insertword' must be a constant integer}}
   vector unsigned long long v2 = vec_extract4b(vuc, index);   // expected-error {{argument to '__builtin_vsx_extractuword' must be a constant integer}}
 }
+
+void testXXPERMDI(int index) {
+  vec_xxpermdi(vsi); //expected-error {{too few arguments to function call, expected at least 3, have 1}}
+  vec_xxpermdi(vsi, vsi, 2, 4); //expected-error {{too many arguments to function call, expected at most 3, have 4}}
+  vec_xxpermdi(vsi, vsi, index); //expected-error {{argument 3 to '__builtin_vsx_xxpermdi' must be a 2-bit unsigned literal (i.e. 0,1,2 or 3)}}
+  vec_xxpermdi(1, 2, 3); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must be vectors}}
+  vec_xxpermdi(vsi, vuc, 2); //expected-error {{first two arguments to '__builtin_vsx_xxpermdi' must have the same type}}
+}
Index: lib/Sema/SemaChecking.cpp
=