[PATCH] D32260: [TBAA] Vector types should (only) alias with their element types

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 17:14:20 PDT 2017


hfinkel created this revision.
Herald added a subscriber: mcrosier.

Currently, all of our builtin vector types are equivalent to char for TBAA purposes. It would be useful to make this less conservative. This patch makes vector types equivalent to their element types for type-aliasing purposes. I think it's common for programmers to assume that they can cast freely between the vector types and the scalar types (so long as they're being sufficiently careful about alignments), and we should certainly preserve that model. Given that we assume that int* and float* don't alias, I don't think we need to assume that int* and vec_of_float* alias or vec_of_int* and vec_of_float* alias.

The cases I've seen where I know this would be helpful involve integral scalar pointers and floating-point vector pointers, so I'm generalizing a bit here. If this would break too much code, one option is fall back to doing this only for floating-point types. That having been said, I know that it is common on some platforms to case between floating-point vectors and integer vectors in order to implement operations like fabs, and maybe that makes this untenable on those platforms?

Thoughts?


https://reviews.llvm.org/D32260

Files:
  lib/CodeGen/CodeGenTBAA.cpp
  test/CodeGen/tbaa-vector.cpp


Index: test/CodeGen/tbaa-vector.cpp
===================================================================
--- /dev/null
+++ test/CodeGen/tbaa-vector.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+
+typedef double __m256d __attribute__((__vector_size__(32)));
+__m256d foo(double *x, __m256d *y) {
+  *x = 0.0;
+  return *y;
+
+// CHECK-LABEL: define <4 x double> @_Z3fooPdPDv4_d
+// CHECK: store double 0.000000e+00, double* %{{.*}}, align 8, !tbaa [[TAG_double:!.*]]
+// CHECK: load <4 x double>, <4 x double>* %{{.*}}, align {{.*}}, !tbaa [[TAG_double]]
+}
+
+// CHECK: [[TYPE_char:!.*]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
+// CHECK: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
+// CHECK: [[TAG_double]] = !{[[TYPE_double:!.*]], [[TYPE_double]], i64 0}
+// CHECK: [[TYPE_double]] = !{!"double", [[TYPE_char]],
+
Index: lib/CodeGen/CodeGenTBAA.cpp
===================================================================
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -101,6 +101,10 @@
   if (TypeHasMayAlias(QTy))
     return getChar();
 
+  // Vector types should alias with their element types.
+  if (auto *VT = QTy->getAs<VectorType>())
+    QTy = VT->getElementType();
+
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
 
   if (llvm::MDNode *N = MetadataCache[Ty])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32260.95860.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170420/4fabe10a/attachment-0001.bin>


More information about the cfe-commits mailing list