Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TBAA] Emit distinct TBAA tags for pointers with different depths,types. #76612

Merged
merged 7 commits into from
Jul 12, 2024

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Dec 30, 2023

This patch extends Clang's TBAA generation code to emit distinct tags for incompatible pointer types.

Pointers with different element types are incompatible if the pointee types are also incompatible (modulo sugar/modifiers).

Express this in TBAA by generating different tags for pointers based on the pointer depth and pointee type. To get the TBAA tag for the pointee type it uses getTypeInfoHelper on the pointee type.

(Moved from https://reviews.llvm.org/D122573)

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Dec 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 30, 2023

@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-backend-amdgpu
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Florian Hahn (fhahn)

Changes

This patch extends Clang's TBAA generation code to emit distinct tags for incompatible pointer types.

Pointers with different element types are incompatible if the pointee types are also incompatible (modulo sugar/modifiers).

Express this in TBAA by generating different tags for pointers based on the pointer depth and pointee type. To get the TBAA tag for the pointee type it uses getTypeInfoHelper on the pointee type.

(Moved from https://reviews.llvm.org/D122573)


Full diff: https://github.com/llvm/llvm-project/pull/76612.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenTBAA.cpp (+25-4)
  • (modified) clang/test/CodeGen/tbaa-pointers.c (+42-30)
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp
index dc288bc3f6157a..b96f9d28c45530 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -184,10 +184,31 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
     return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-    return createScalarTypeNode("any pointer", getChar(), Size);
+  if (Ty->isPointerType() || Ty->isReferenceType()) {
+    llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
+    // Compute the depth of the pointer and generate a tag of the form "p<depth>
+    // <base type tag>".
+    unsigned PtrDepth = 0;
+    do {
+      PtrDepth++;
+      Ty = Ty->getPointeeType().getTypePtr();
+    } while (Ty->isPointerType() || Ty->isReferenceType());
+    // TODO: Implement C++'s type "similarity" and consider dis-"similar"
+    // pointers distinct for non-builtin types.
+    if (isa<BuiltinType>(Ty)) {
+      llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
+      StringRef Name =
+          cast<llvm::MDString>(
+              ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0))
+              ->getString();
+      SmallString<256> OutName("p");
+      OutName += std::to_string(PtrDepth);
+      OutName += " ";
+      OutName += Name;
+      return createScalarTypeNode(OutName, AnyPtr, Size);
+    }
+    return AnyPtr;
+  }
 
   // Accesses to arrays are accesses to objects of their element types.
   if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
diff --git a/clang/test/CodeGen/tbaa-pointers.c b/clang/test/CodeGen/tbaa-pointers.c
index b9ebe879820012..a3a7aa0d66473e 100644
--- a/clang/test/CodeGen/tbaa-pointers.c
+++ b/clang/test/CodeGen/tbaa-pointers.c
@@ -4,9 +4,9 @@ void p2unsigned(unsigned **ptr) {
   // CHECK-LABEL: define void @p2unsigned(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:  %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:  store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0:!.+]]
-  // CHECK-NEXT:  [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:  store ptr null, ptr [[BASE]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:  store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0:!.+]]
+  // CHECK-NEXT:  [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]]
+  // CHECK-NEXT:  store ptr null, ptr [[BASE]], align 8, !tbaa [[P1INT_0:!.+]]
   // CHECK-NEXT:  ret void
   //
   *ptr = 0;
@@ -16,9 +16,9 @@ void p2unsigned_volatile(unsigned *volatile *ptr) {
   // CHECK-LABEL: define void @p2unsigned_volatile(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store volatile ptr null, ptr [[BASE]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]]
+  // CHECK-NEXT:   [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P2INT_0]]
+  // CHECK-NEXT:   store volatile ptr null, ptr [[BASE]], align 8, !tbaa [[P1INT_0]]
   // CHECK-NEXT:   ret void
   //
   *ptr = 0;
@@ -28,10 +28,10 @@ void p3int(int ***ptr) {
   // CHECK-LABEL: define void @p3int(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store ptr null, ptr [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P3INT_0:!.+]]
+  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P3INT_0]]
+  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[P2INT_0]]
+  // CHECK-NEXT:   store ptr null, ptr [[BASE_1]], align 8, !tbaa [[P1INT_0]]
   // CHECK-NEXT:   ret void
   //
   **ptr = 0;
@@ -41,11 +41,11 @@ void p4char(char ****ptr) {
   // CHECK-LABEL: define void @p4char(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0:!.+]]
+  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0]]
+  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[P3CHAR_0:!.+]]
+  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[P2CHAR_0:!.+]]
+  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[P1CHAR_0:!.+]]
   // CHECK-NEXT:   ret void
   //
   ***ptr = 0;
@@ -55,11 +55,11 @@ void p4char_const1(const char ****ptr) {
   // CHECK-LABEL: define void @p4char_const1(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0]]
+  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0]]
+  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[P3CHAR_0]]
+  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[P2CHAR_0]]
+  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[P1CHAR_0]]
   // CHECK-NEXT:   ret void
   //
   ***ptr = 0;
@@ -69,11 +69,11 @@ void p4char_const2(const char **const **ptr) {
   // CHECK-LABEL: define void @p4char_const2(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0]]
+  // CHECK-NEXT:   [[BASE_0:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P4CHAR_0]]
+  // CHECK-NEXT:   [[BASE_1:%.+]] = load ptr, ptr [[BASE_0]], align 8, !tbaa [[P3CHAR_0]]
+  // CHECK-NEXT:   [[BASE_2:%.+]] = load ptr, ptr [[BASE_1]], align 8, !tbaa [[P2CHAR_0]]
+  // CHECK-NEXT:   store ptr null, ptr [[BASE_2]], align 8, !tbaa [[P1CHAR_0]]
   // CHECK-NEXT:   ret void
   //
   ***ptr = 0;
@@ -88,16 +88,28 @@ void p2struct(struct S1 **ptr) {
   // CHECK-LABEL: define void @p2struct(ptr noundef %ptr)
   // CHECK-NEXT: entry:
   // CHECK-NEXT:   %ptr.addr = alloca ptr, align 8
-  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[ANY_POINTER_0]]
-  // CHECK-NEXT:   store ptr null, ptr [[BASE]], align 8, !tbaa [[ANY_POINTER_0]]
+  // CHECK-NEXT:   store ptr %ptr, ptr %ptr.addr, align 8, !tbaa [[P2S1_0:!.+]]
+  // CHECK-NEXT:   [[BASE:%.+]] = load ptr, ptr %ptr.addr, align 8, !tbaa [[P2S1_0]]
+  // CHECK-NEXT:   store ptr null, ptr [[BASE]], align 8, !tbaa [[P1S1_:!.+]]
   // CHECK-NEXT:   ret void
   //
   *ptr = 0;
 }
 
-// CHECK: [[ANY_POINTER_0]] = !{[[ANY_POINTER:!.+]], [[ANY_POINTER]], i64 0}
+// CHECK: [[P2INT_0]] = !{[[P2INT:!.+]], [[P2INT]], i64 0}
+// CHECK: [[P2INT]] = !{!"p2 int", [[ANY_POINTER:!.+]], i64 0}
 // CHECK: [[ANY_POINTER]] = !{!"any pointer", [[CHAR:!.+]], i64 0}
 // CHECK: [[CHAR]] = !{!"omnipotent char", [[TBAA_ROOT:!.+]], i64 0}
 // CHECK: [[TBAA_ROOT]] = !{!"Simple C/C++ TBAA"}
-//
+// CHECK: [[P1INT_0]] = !{[[P1INT:!.+]], [[P1INT]], i64 0}
+// CHECK: [[P1INT]] = !{!"p1 int", [[ANY_POINTER]], i64 0}
+// CHECK: [[P3INT_0]] = !{[[P3INT:!.+]], [[P3INT]], i64 0}
+// CHECK: [[P3INT]] = !{!"p3 int", [[ANY_POINTER]], i64 0}
+// CHECK: [[P4CHAR_0]] = !{[[P4CHAR:!.+]], [[P4CHAR]], i64 0}
+// CHECK: [[P4CHAR]] = !{!"p4 omnipotent char", [[ANY_POINTER]], i64 0}
+// CHECK: [[P3CHAR_0]] = !{[[P3CHAR:!.+]], [[P3CHAR]], i64 0}
+// CHECK: [[P3CHAR]] = !{!"p3 omnipotent char", [[ANY_POINTER]], i64 0}
+// CHECK: [[P2CHAR_0]] = !{[[P2CHAR:!.+]], [[P2CHAR]], i64 0}
+// CHECK: [[P2CHAR]] = !{!"p2 omnipotent char", [[ANY_POINTER]], i64 0}
+// CHECK: [[P1CHAR_0]] = !{[[P1CHAR:!.+]], [[P1CHAR]], i64 0}
+// CHECK: [[P1CHAR]] = !{!"p1 omnipotent char", [[ANY_POINTER]], i64 0}

@fhahn
Copy link
Contributor Author

fhahn commented Dec 30, 2023

Move this over from Phabricator, see https://reviews.llvm.org/D122573 http://108.170.204.19/D122573 for context.

Type sanitizer patches have been moved to GH as well: #76259, #76260, #76261

https://discourse.llvm.org/t/reviving-typesanitizer-a-sanitizer-to-catch-type-based-aliasing-violations/66092/

@thesamesam thesamesam added the TBAA Type-Based Alias Analysis / Strict Aliasing label Jan 18, 2024
@fhahn fhahn force-pushed the clang-pointer-tbaa branch from 18f45a0 to 61c94b8 Compare June 11, 2024 11:15
@fhahn fhahn force-pushed the clang-pointer-tbaa branch from 61c94b8 to b45b5b0 Compare June 25, 2024 21:43
@fhahn fhahn requested a review from Endilll as a code owner June 25, 2024 21:43
@llvmbot llvmbot added backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels Jun 25, 2024
@fhahn
Copy link
Contributor Author

fhahn commented Jun 25, 2024

Rebased, updated and added option to disable this (-fno-pointer-tbaa). I think this would be ready for a review now :)

@fhahn fhahn force-pushed the clang-pointer-tbaa branch from b45b5b0 to 95973d3 Compare June 26, 2024 08:49
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looking good.

do {
PtrDepth++;
Ty = Ty->getPointeeType().getTypePtr();
} while (Ty->isPointerType() || Ty->isReferenceType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reference type is impossible in these nested positions; you can never have references/pointers to references. I believe it is possible in the original position because we can use this when building aggregate TBAA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted, thanks!

@@ -185,10 +185,33 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
return getChar();

// Handle pointers and references.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth putting standard citations here:

Suggested change
// Handle pointers and references.
// Handle pointers and references.
//
// C has a very strict rule for pointer aliasing. C23 6.7.6.1p2:
// For two pointer types to be compatible, both shall be identically
// qualified and both shall be pointers to compatible types.
//
// This rule is impractically strict; we want to at least ignore CVR
// qualifiers. Distinguishing by CVR qualifiers would make it UB to
// e.g. cast a `char **` to `const char * const *` and dereference it,
// which is too common and useful to invalidate. C++'s similar types
// rule permits qualifier differences in these nested positions; in fact,
// C++ even allows that cast as an implicit conversion.
//
// Other qualifiers could theoretically be distinguished, especially if
// they involve a significant representation difference. We don't
// currently do so, however.
//
// Computing the pointee type string recursively is implicitly more
// forgiving than the standards require. Effectively, we are turning
// the question "are these types compatible/similar" into "are
// accesses to these types allowed to alias". In both C and C++,
// the latter question has special carve-outs for signedness
// mismatches that only apply at the top level. As a result, we are
// allowing e.g. `int *` l-values to access `unsigned *` objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, thank you very much!

@fhahn fhahn force-pushed the clang-pointer-tbaa branch from 95973d3 to 11011ef Compare June 26, 2024 21:11
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. LGTM, but let's ping @AaronBallman and @efriedma-quic.

@efriedma-quic
Copy link
Collaborator

I don't see any issues with the code. I'd prefer if we has a TYSan-instrumented bootstrap build of LLVM before we merge this, so we're confident this doesn't cause any unexpected issues.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes generally LGTM though I think this should come with a release note so users know about the new command line options and functionality?

// For two pointer types to be compatible, both shall be identically
// qualified and both shall be pointers to compatible types.
//
// This rule is impractically strict; we want to at least ignore CVR
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this for the default behavior, but I think we should still allow opting into the strict C conformance behavior so that users can sanitize the code for portability to stricter compilers (also, it may allow for different optimization impacts that users might care about... maybe). This can be follow-up work though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@fhahn fhahn force-pushed the clang-pointer-tbaa branch from 11011ef to 06d4406 Compare June 27, 2024 21:01
Copy link
Contributor Author

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes generally LGTM though I think this should come with a release note so users know about the new command line options and functionality?

Thanks, I tried to add release note entries for the new behavior + the new flags. Hope I added them in the right place.

I don't see any issues with the code. I'd prefer if we has a TYSan-instrumented bootstrap build of LLVM before we merge this, so we're confident this doesn't cause any unexpected issues.

Just updated the tysan branches again. Unfortunately we aren't yet at a point where LLVM is tysan clean, there is a large number of reported violations when running the tblgen built with tysan even without this patch. I'd expect that a substantial amount of work is still needed to get to a state where we can build LLVM successfully with tysan.

What is feasible at the moment is building SingleSource and for that the patch doesn't add new regressions (there are ~20 tests failing with tysan out of ~1800). Still building MultiSource, but some files take a huge amount of time to build with tysan :(

// For two pointer types to be compatible, both shall be identically
// qualified and both shall be pointers to compatible types.
//
// This rule is impractically strict; we want to at least ignore CVR
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all I want to say that this is a really cool project, especially the type sanitizer part. Thanks for working on this!

Just updated the tysan branches again. Unfortunately we aren't yet at a point where LLVM is tysan clean, there is a large number of reported violations when running the tblgen built with tysan even without this patch. I'd expect that a substantial amount of work is still needed to get to a state where we can build LLVM successfully with tysan.

Given that not even LLVM itself is clean (which has probably some of the densest population of compiler engineers), and you say that this will require a significant amount of work, would it maybe make sense to have this off-by-default for now and only enable it in a year or so by default? Especially if there are problems in any system libraries, like libc++, it would be rather unfortunate, since users can't do much about it.

@@ -392,6 +392,10 @@ Non-comprehensive list of changes in this release
- ``#pragma GCC diagnostic warning "-Wfoo"`` can now downgrade ``-Werror=foo``
errors and certain default-to-error ``-W`` diagnostics to warnings.

- Clang now emits distinct type-based alias analysis tags for incompatible
pointers, enabling more powerful alias analysis when accessing pointer types.
The new behavior can be disabledusing ``-fno-pointer-tbaa``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The new behavior can be disabledusing ``-fno-pointer-tbaa``.
The new behavior can be disabled using ``-fno-pointer-tbaa``.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ,thanks!

This patch extends Clang's TBAA generation code to emit distinct tags
for incompatible pointer types.

Pointers with different element types are incompatible if the pointee
types are also incompatible (modulo sugar/modifiers).

Express this in TBAA by generating different tags for pointers based
on the pointer depth and pointee type. To get the TBAA tag for the
pointee type it uses getTypeInfoHelper on the pointee type.

(Moved from https://reviews.llvm.org/D122573)
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from a minor code formatting suggestion.

@@ -233,6 +233,7 @@ ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Defa

CODEGENOPT(RelaxAll , 1, 0) ///< Relax all machine code instructions.
CODEGENOPT(RelaxedAliasing , 1, 0) ///< Set when -fno-strict-aliasing is enabled.
CODEGENOPT(PointerTBAA, 1, 0) ///< Whether or not to use distinct TBAA tags for pointers.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to align the code with the surrounding text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted, thanks!

@fhahn fhahn merged commit 038c48c into llvm:main Jul 12, 2024
6 of 7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder clang-ve-ninja running on hpce-ve-main while building clang at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/12/builds/1782

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py ...' (failure)
...
[297/303] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[298/303] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[299/303] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[300/303] Linking CXX executable tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[301/303] Building CXX object tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/SourceCodeTest.cpp.o
[302/303] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[302/303] Running the Clang regression tests
-- Testing: 20823 tests, 48 workers --
llvm-lit: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:508: note: using clang: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.. 10.. 20.. 30.
FAIL: Clang :: CodeGen/tbaa-pointers.c (7544 of 20823)
******************** TEST 'Clang :: CodeGen/tbaa-pointers.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes -pointer-tbaa /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,ENABLED /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes -pointer-tbaa /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,ENABLED /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
RUN: at line 3: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang --target=x86_64-apple-darwin -O1 /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -S -mllvm -disable-llvm-optzns -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang --target=x86_64-apple-darwin -O1 /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -S -mllvm -disable-llvm-optzns -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c:7:19: error: COMMON-LABEL: expected string not found in input
 // COMMON-LABEL: define void @p2unsigned(ptr noundef %ptr)
                  ^
<stdin>:1:1: note: scanning from here
; ModuleID = '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c'
^
<stdin>:7:1: note: possible intended match here
define void @p2unsigned(ptr noundef %0) #0 {
^

Input file: <stdin>
Check file: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: ; ModuleID = '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c' 
label:7'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: source_filename = "/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c" 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "x86_64-apple-macosx10.4.0" 
Step 8 (check-llvm) failure: check-llvm (failure)
...
[297/303] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[298/303] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[299/303] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[300/303] Linking CXX executable tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[301/303] Building CXX object tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/SourceCodeTest.cpp.o
[302/303] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[302/303] Running the Clang regression tests
-- Testing: 20823 tests, 48 workers --
llvm-lit: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:508: note: using clang: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.. 10.. 20.. 30.
FAIL: Clang :: CodeGen/tbaa-pointers.c (7544 of 20823)
******************** TEST 'Clang :: CodeGen/tbaa-pointers.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
RUN: at line 2: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes -pointer-tbaa /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,ENABLED /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/19/include -nostdsysteminc -triple x86_64-apple-darwin -O1 -disable-llvm-passes -pointer-tbaa /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,ENABLED /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
RUN: at line 3: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang --target=x86_64-apple-darwin -O1 /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -S -mllvm -disable-llvm-optzns -o - | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang --target=x86_64-apple-darwin -O1 /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c -emit-llvm -S -mllvm -disable-llvm-optzns -o -
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck --check-prefixes=COMMON,DEFAULT /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c:7:19: error: COMMON-LABEL: expected string not found in input
 // COMMON-LABEL: define void @p2unsigned(ptr noundef %ptr)
                  ^
<stdin>:1:1: note: scanning from here
; ModuleID = '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c'
^
<stdin>:7:1: note: possible intended match here
define void @p2unsigned(ptr noundef %0) #0 {
^

Input file: <stdin>
Check file: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: ; ModuleID = '/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c' 
label:7'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: source_filename = "/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/CodeGen/tbaa-pointers.c" 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
label:7'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "x86_64-apple-macosx10.4.0" 

@fhahn fhahn deleted the clang-pointer-tbaa branch July 12, 2024 20:10
fhahn added a commit that referenced this pull request Jul 12, 2024
…pths,types. (#76612)"

This reverts commit 038c48c.

This is causing test failures in some configurations, reverted while I
investigate.

Failures include

 http://lab.llvm.org/buildbot/#/builders/11/builds/1623
 http://lab.llvm.org/buildbot/#/builders/108/builds/1172
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…es. (llvm#76612)

This patch extends Clang's TBAA generation code to emit distinct tags
for incompatible pointer types.

Pointers with different element types are incompatible if the pointee
types are also incompatible (modulo sugar/modifiers).

Express this in TBAA by generating different tags for pointers based on
the pointer depth and pointee type. To get the TBAA tag for the pointee
type it uses getTypeInfoHelper on the pointee type.

(Moved from https://reviews.llvm.org/D122573)

PR: llvm#76612
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…pths,types. (llvm#76612)"

This reverts commit 038c48c.

This is causing test failures in some configurations, reverted while I
investigate.

Failures include

 http://lab.llvm.org/buildbot/#/builders/11/builds/1623
 http://lab.llvm.org/buildbot/#/builders/108/builds/1172
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 16, 2024
…es. (llvm#76612)

This patch extends Clang's TBAA generation code to emit distinct tags
for incompatible pointer types.

Pointers with different element types are incompatible if the pointee
types are also incompatible (modulo sugar/modifiers).

Express this in TBAA by generating different tags for pointers based on
the pointer depth and pointee type. To get the TBAA tag for the pointee
type it uses getTypeInfoHelper on the pointee type.

(Moved from https://reviews.llvm.org/D122573)

PR: llvm#76612
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 16, 2024
…pths,types. (llvm#76612)"

This reverts commit 038c48c.

This is causing test failures in some configurations, reverted while I
investigate.

Failures include

 http://lab.llvm.org/buildbot/#/builders/11/builds/1623
 http://lab.llvm.org/buildbot/#/builders/108/builds/1172
fhahn added a commit that referenced this pull request Jul 19, 2024
…depths,types. (#76612)"

This reverts the revert commit bee2403.

This version includes updates to the tests to use patterns when matching
the pointer argument.

Original commit message:

    This patch extends Clang's TBAA generation code to emit distinct tags
    for incompatible pointer types.

    Pointers with different element types are incompatible if the pointee
    types are also incompatible (modulo sugar/modifiers).

    Express this in TBAA by generating different tags for pointers based on
    the pointer depth and pointee type. To get the TBAA tag for the pointee
    type it uses getTypeInfoHelper on the pointee type.

    (Moved from https://reviews.llvm.org/D122573)

    PR: #76612
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this pull request Jul 23, 2024
…depths,types. (llvm#76612)"

This reverts the revert commit bee2403.

This version includes updates to the tests to use patterns when matching
the pointer argument.

Original commit message:

    This patch extends Clang's TBAA generation code to emit distinct tags
    for incompatible pointer types.

    Pointers with different element types are incompatible if the pointee
    types are also incompatible (modulo sugar/modifiers).

    Express this in TBAA by generating different tags for pointers based on
    the pointer depth and pointee type. To get the TBAA tag for the pointee
    type it uses getTypeInfoHelper on the pointee type.

    (Moved from https://reviews.llvm.org/D122573)

    PR: llvm#76612
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…depths,types. (#76612)"

Summary:
This reverts the revert commit bee2403.

This version includes updates to the tests to use patterns when matching
the pointer argument.

Original commit message:

    This patch extends Clang's TBAA generation code to emit distinct tags
    for incompatible pointer types.

    Pointers with different element types are incompatible if the pointee
    types are also incompatible (modulo sugar/modifiers).

    Express this in TBAA by generating different tags for pointers based on
    the pointer depth and pointee type. To get the TBAA tag for the pointee
    type it uses getTypeInfoHelper on the pointee type.

    (Moved from https://reviews.llvm.org/D122573)

    PR: #76612

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251466
fhahn added a commit to fhahn/llvm-project that referenced this pull request Sep 30, 2024
Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.
fhahn added a commit to fhahn/llvm-project that referenced this pull request Oct 20, 2024
Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.
fhahn added a commit to fhahn/llvm-project that referenced this pull request Oct 21, 2024
Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.
fhahn added a commit that referenced this pull request Oct 22, 2024
Extend the logic added in 123c036
(#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.

PR: #110569
fhahn added a commit to fhahn/llvm-project that referenced this pull request Nov 14, 2024
…0569)

Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.

PR: llvm#110569
fhahn added a commit to fhahn/llvm-project that referenced this pull request Nov 21, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory access
 * +4% more loops vectorized
 * +3% more stores removed by DSE.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
llvm#76612.

Support for user-defined types has been added in
llvm#110569.

There are 2 pending PRs with bug fixes for special cases uncovered
during some of my testing:
 * llvm#116991
 * llvm#116596
fhahn added a commit to fhahn/llvm-project that referenced this pull request Nov 21, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory access
 * +4% more loops vectorized
 * +3% more stores removed by DSE.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
llvm#76612.

Support for user-defined types has been added in
llvm#110569.

There are 2 pending PRs with bug fixes for special cases uncovered
during some of my testing:
 * llvm#116991
 * llvm#116596
fhahn added a commit to fhahn/llvm-project that referenced this pull request Nov 22, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory access
 * +4% more loops vectorized
 * +3% more stores removed by DSE.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
llvm#76612.

Support for user-defined types has been added in
llvm#110569.

There are 2 pending PRs with bug fixes for special cases uncovered
during some of my testing:
 * llvm#116991
 * llvm#116596
fhahn added a commit to fhahn/llvm-project that referenced this pull request Dec 3, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory access
 * +4% more loops vectorized
 * +3% more stores removed by DSE.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
llvm#76612.

Support for user-defined types has been added in
llvm#110569.

There are 2 pending PRs with bug fixes for special cases uncovered
during some of my testing:
 * llvm#116991
 * llvm#116596
fhahn added a commit that referenced this pull request Dec 4, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory accesses
 * +3% more stores removed by DSE,
 * +4% more loops vectorized.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
#76612.

Support for user-defined types has been added in
#110569.

There are 2 recent PRs with bug fixes for special cases uncovered during
testing:
 * #116991
 * #116596

PR: #117244
TIFitis pushed a commit to TIFitis/llvm-project that referenced this pull request Dec 18, 2024
Support for more precise TBAA metadata has been added a while ago
(behind the -fpointer-tbaa flag). The more precise TBAA metadata allows
treating accesses of different pointer types as no-alias.

This helps to remove more redundant loads and stores in a number of
workloads.

Some highlights on the impact across llvm-test-suite's MultiSource,
SPEC2006 & SPEC2017 include:
 * +2% more NoAlias results for memory accesses
 * +3% more stores removed by DSE,
 * +4% more loops vectorized.

This closes a relatively big gap to GCC, which has been supporting
disambiguating based on pointer types for a long time.
(https://clang.godbolt.org/z/K7Wbhrz4q)

Pointer-TBAA support for pointers to builtin types has been added in
llvm#76612.

Support for user-defined types has been added in
llvm#110569.

There are 2 recent PRs with bug fixes for special cases uncovered during
testing:
 * llvm#116991
 * llvm#116596

PR: llvm#117244
fhahn added a commit to fhahn/llvm-project that referenced this pull request Jan 8, 2025
…0569)

Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.

PR: llvm#110569
(cherry picked from commit 4334f31)
fhahn added a commit to fhahn/llvm-project that referenced this pull request Jan 9, 2025
…0569)

Extend the logic added in 123c036
(llvm#76612) to support pointers to
non-builtin types by using the mangled name of the canonical type.

PR: llvm#110569
(cherry picked from commit 4334f31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:codegen clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category TBAA Type-Based Alias Analysis / Strict Aliasing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants