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.00e+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())
+QTy = VT->getElementType();
+
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
if (llvm::MDNode *N = MetadataCache[Ty])
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.00e+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())
+QTy = VT->getElementType();
+
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
if (llvm::MDNode *N = MetadataCache[Ty])
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits