From 231bebb2d6a872cf72165e796d351cdc8006b1c9 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Thu, 24 Jun 2021 16:19:29 -0400 Subject: [PATCH 1/4] Test case for SIMD --- clang/test/3C/simd1.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 clang/test/3C/simd1.c diff --git a/clang/test/3C/simd1.c b/clang/test/3C/simd1.c new file mode 100644 index 000000000000..120c145a7707 --- /dev/null +++ b/clang/test/3C/simd1.c @@ -0,0 +1,13 @@ +// Simple SIMD program that involves no pointers, we just want this to not crash +// RUN: rm -rf %t* +// RUN: 3c -base-dir=%S -alltypes -addcr %s + +typedef int v4si __attribute__ ((vector_size(16))); + +int main(void) { + v4si x = {1,2,3,4}; + v4si y = {1,2,3,4}; + v4si z = x + y; + + return (z[0] + z[1] + z[3] + z[4]); +} From ecdc51e8cf71c96318b70c25696aeb8353ebb7c6 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Thu, 24 Jun 2021 16:41:51 -0400 Subject: [PATCH 2/4] Seperated concerns in test cases --- clang/test/3C/simd1.c | 3 +-- clang/test/3C/simd2.c | 12 ++++++++++++ clang/test/3C/simd3.c | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 clang/test/3C/simd2.c create mode 100644 clang/test/3C/simd3.c diff --git a/clang/test/3C/simd1.c b/clang/test/3C/simd1.c index 120c145a7707..cac5c67b0eee 100644 --- a/clang/test/3C/simd1.c +++ b/clang/test/3C/simd1.c @@ -4,10 +4,9 @@ typedef int v4si __attribute__ ((vector_size(16))); -int main(void) { +void main(void) { v4si x = {1,2,3,4}; v4si y = {1,2,3,4}; v4si z = x + y; - return (z[0] + z[1] + z[3] + z[4]); } diff --git a/clang/test/3C/simd2.c b/clang/test/3C/simd2.c new file mode 100644 index 000000000000..244d615c70f4 --- /dev/null +++ b/clang/test/3C/simd2.c @@ -0,0 +1,12 @@ +// Simple SIMD program that derefs and involves no pointers, we just want this to not crash, +// RUN: rm -rf %t* +// RUN: 3c -base-dir=%S -alltypes -addcr %s +typedef int v4si __attribute__ ((vector_size(16))); + +int main(void) { + v4si x = {1,2,3,4}; + v4si y = {1,2,3,4}; + v4si z = x + y; + + return (z[0] + z[1] + z[3] + z[4]); +} diff --git a/clang/test/3C/simd3.c b/clang/test/3C/simd3.c new file mode 100644 index 000000000000..2a69bc936fcd --- /dev/null +++ b/clang/test/3C/simd3.c @@ -0,0 +1,7 @@ +// Original minimized failing simd program +// RUN: rm -rf %t* +// RUN: 3c -base-dir=%S -alltypes -addcr %s + +__attribute__((__vector_size__(2 * sizeof(long)))) int a() { + return (__attribute__((__vector_size__(2 * sizeof(long))))int){}; +} From 1328da6dd8e2cab78cb3fa4ec5c584bf42446716 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Thu, 24 Jun 2021 16:45:04 -0400 Subject: [PATCH 3/4] 3c no longer crashes in presence of intrinsics --- clang/lib/3C/ConstraintResolver.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clang/lib/3C/ConstraintResolver.cpp b/clang/lib/3C/ConstraintResolver.cpp index fea3f8c8f407..3d3cc36cfa39 100644 --- a/clang/lib/3C/ConstraintResolver.cpp +++ b/clang/lib/3C/ConstraintResolver.cpp @@ -164,7 +164,7 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) { E = E->IgnoreParens(); // Non-pointer (int, char, etc.) types have a special base PVConstraint. - if (TypE->isRecordType() || TypE->isArithmeticType()) { + if (TypE->isRecordType() || TypE->isArithmeticType() || TypE->isVectorType()) { if (DeclRefExpr *DRE = dyn_cast(E)) { // If we have a DeclRef, the PVC can get a meaningful name return pairWithEmptyBkey(getBaseVarPVConstraint(DRE)); @@ -552,6 +552,7 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) { // In particular, structure initialization should not reach here, // as that caught by the non-pointer check at the top of this // method. + ILE->getType()->dump(); assert("InitlistExpr of type other than array or pointer in " "getExprConstraintVars" && ILE->getType()->isPointerType()); @@ -694,7 +695,7 @@ CVarSet ConstraintResolver::pvConstraintFromType(QualType TypE) { assert("Pointer type CVs should be obtained through getExprConstraintVars." && !TypE->isPointerType()); CVarSet Ret; - if (TypE->isRecordType() || TypE->isArithmeticType()) + if (TypE->isRecordType() || TypE->isArithmeticType() || TypE->isVectorType()) Ret.insert(PVConstraint::getNonPtrPVConstraint(Info.getConstraints())); else llvm::errs() << "Warning: Returning non-base, non-wild type"; @@ -706,7 +707,8 @@ CVarSet ConstraintResolver::getBaseVarPVConstraint(DeclRefExpr *Decl) { return Info.getPersistentConstraintsSet(Decl, Context); assert(Decl->getType()->isRecordType() || - Decl->getType()->isArithmeticType()); + Decl->getType()->isArithmeticType() || + Decl->getType()->isVectorType()); CVarSet Ret; auto DN = Decl->getDecl()->getName(); From 73544c5321541a39808e52f4b2c1adbd62f7c620 Mon Sep 17 00:00:00 2001 From: Aaron Eline Date: Fri, 25 Jun 2021 12:09:54 -0400 Subject: [PATCH 4/4] Fixing minor comments from john --- clang/include/clang/3C/ConstraintResolver.h | 4 ++++ clang/lib/3C/ConstraintResolver.cpp | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/3C/ConstraintResolver.h b/clang/include/clang/3C/ConstraintResolver.h index 6b98441333a1..79f5225f53ff 100644 --- a/clang/include/clang/3C/ConstraintResolver.h +++ b/clang/include/clang/3C/ConstraintResolver.h @@ -78,6 +78,10 @@ class ConstraintResolver { CVarSet getBaseVarPVConstraint(DeclRefExpr *Decl); PVConstraint *getRewritablePVConstraint(Expr *E); + + + bool isNonPtrType(QualType &TE); + }; #endif // LLVM_CLANG_3C_CONSTRAINTRESOLVER_H diff --git a/clang/lib/3C/ConstraintResolver.cpp b/clang/lib/3C/ConstraintResolver.cpp index 3d3cc36cfa39..f1c278dbe997 100644 --- a/clang/lib/3C/ConstraintResolver.cpp +++ b/clang/lib/3C/ConstraintResolver.cpp @@ -164,7 +164,7 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) { E = E->IgnoreParens(); // Non-pointer (int, char, etc.) types have a special base PVConstraint. - if (TypE->isRecordType() || TypE->isArithmeticType() || TypE->isVectorType()) { + if (isNonPtrType(TypE)) { if (DeclRefExpr *DRE = dyn_cast(E)) { // If we have a DeclRef, the PVC can get a meaningful name return pairWithEmptyBkey(getBaseVarPVConstraint(DRE)); @@ -552,7 +552,6 @@ CSetBkeyPair ConstraintResolver::getExprConstraintVars(Expr *E) { // In particular, structure initialization should not reach here, // as that caught by the non-pointer check at the top of this // method. - ILE->getType()->dump(); assert("InitlistExpr of type other than array or pointer in " "getExprConstraintVars" && ILE->getType()->isPointerType()); @@ -691,11 +690,15 @@ void ConstraintResolver::constrainLocalAssign(Stmt *TSt, DeclaratorDecl *D, } } +bool ConstraintResolver::isNonPtrType(QualType &TE) { + return TE->isRecordType() || TE->isArithmeticType() || TE->isVectorType(); +} + CVarSet ConstraintResolver::pvConstraintFromType(QualType TypE) { assert("Pointer type CVs should be obtained through getExprConstraintVars." && !TypE->isPointerType()); CVarSet Ret; - if (TypE->isRecordType() || TypE->isArithmeticType() || TypE->isVectorType()) + if (isNonPtrType(TypE)) Ret.insert(PVConstraint::getNonPtrPVConstraint(Info.getConstraints())); else llvm::errs() << "Warning: Returning non-base, non-wild type"; @@ -706,9 +709,8 @@ CVarSet ConstraintResolver::getBaseVarPVConstraint(DeclRefExpr *Decl) { if (Info.hasPersistentConstraints(Decl, Context)) return Info.getPersistentConstraintsSet(Decl, Context); - assert(Decl->getType()->isRecordType() || - Decl->getType()->isArithmeticType() || - Decl->getType()->isVectorType()); + auto T = Decl->getType(); + assert(isNonPtrType(T)); CVarSet Ret; auto DN = Decl->getDecl()->getName();