[llvm] Extra assertions in RS4GC (PR #71201)

Petr Maj via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 23 03:27:29 PST 2023


https://github.com/zduka updated https://github.com/llvm/llvm-project/pull/71201

>From 5c99f1b2fe5316c7c3c422c18f5836c32abdbd40 Mon Sep 17 00:00:00 2001
From: Petr Maj <pmaj at azul.com>
Date: Fri, 27 Oct 2023 18:31:53 +0200
Subject: [PATCH 1/5] Extra assert added

---
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 63ee11295e9c032..5b8d0344af687e1 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1249,6 +1249,8 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
 
 #ifndef NDEBUG
   VerifyStates();
+  // get the data layout to compare the sizes of base/derived pointer values 
+  auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
 #endif
 
   // Cache all of our results so we can cheaply reuse them
@@ -1258,6 +1260,8 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
     auto *BDV = Pair.first;
     Value *Base = Pair.second.getBaseValue();
     assert(BDV && Base);
+    // the assumption is that whenever we have a derived ptr(s), their base ptr(s) must be of the same size, not necessarily the same type
+    assert(DL.getTypeAllocSize(BDV->getType()) == DL.getTypeAllocSize(Base->getType()) && "Derived and base values should have same size");
     // Only values that do not have known bases or those that have differing
     // type (scalar versus vector) from a possible known base should be in the
     // lattice.

>From 04a56cfbf02878b09470c1e9727f97ceb9c1fdc2 Mon Sep 17 00:00:00 2001
From: Petr Maj <pmaj at azul.com>
Date: Fri, 27 Oct 2023 18:32:16 +0200
Subject: [PATCH 2/5] fmt

---
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 5b8d0344af687e1..35945a8fb577545 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1249,7 +1249,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
 
 #ifndef NDEBUG
   VerifyStates();
-  // get the data layout to compare the sizes of base/derived pointer values 
+  // get the data layout to compare the sizes of base/derived pointer values
   auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
 #endif
 
@@ -1260,8 +1260,11 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
     auto *BDV = Pair.first;
     Value *Base = Pair.second.getBaseValue();
     assert(BDV && Base);
-    // the assumption is that whenever we have a derived ptr(s), their base ptr(s) must be of the same size, not necessarily the same type
-    assert(DL.getTypeAllocSize(BDV->getType()) == DL.getTypeAllocSize(Base->getType()) && "Derived and base values should have same size");
+    // the assumption is that whenever we have a derived ptr(s), their base
+    // ptr(s) must be of the same size, not necessarily the same type
+    assert(DL.getTypeAllocSize(BDV->getType()) ==
+               DL.getTypeAllocSize(Base->getType()) &&
+           "Derived and base values should have same size");
     // Only values that do not have known bases or those that have differing
     // type (scalar versus vector) from a possible known base should be in the
     // lattice.

>From e0d7e367dd15b48a6e257596f5517444b72e727b Mon Sep 17 00:00:00 2001
From: Petr Maj <pmaj at azul.com>
Date: Wed, 8 Nov 2023 12:06:21 +0100
Subject: [PATCH 3/5] maybe unused

---
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 35945a8fb577545..3206549733c223d 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1249,10 +1249,11 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
 
 #ifndef NDEBUG
   VerifyStates();
-  // get the data layout to compare the sizes of base/derived pointer values
-  auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
 #endif
 
+  // get the data layout to compare the sizes of base/derived pointer values
+  [[maybe_unused]]
+  auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
   // Cache all of our results so we can cheaply reuse them
   // NOTE: This is actually two caches: one of the base defining value
   // relation and one of the base pointer relation!  FIXME

>From 142f4e68f6f449f747db937e92100ed652130622 Mon Sep 17 00:00:00 2001
From: Petr Maj <pmaj at azul.com>
Date: Wed, 8 Nov 2023 12:20:10 +0100
Subject: [PATCH 4/5] fmt fix

---
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 3206549733c223d..93cacbe5ef17184 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1252,8 +1252,8 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
 #endif
 
   // get the data layout to compare the sizes of base/derived pointer values
-  [[maybe_unused]]
-  auto &DL = cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
+  [[maybe_unused]] auto &DL =
+      cast<llvm::Instruction>(Def)->getModule()->getDataLayout();
   // Cache all of our results so we can cheaply reuse them
   // NOTE: This is actually two caches: one of the base defining value
   // relation and one of the base pointer relation!  FIXME

>From 7dccdaa20368c35ce50229d5dc7b5523bb0120da Mon Sep 17 00:00:00 2001
From: Petr Maj <53400784+zduka at users.noreply.github.com>
Date: Thu, 23 Nov 2023 12:27:21 +0100
Subject: [PATCH 5/5] Update
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Co-authored-by: annamthomas <anna at azul.com>
---
 llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 93cacbe5ef17184..3ce00337b08ceab 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1261,7 +1261,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
     auto *BDV = Pair.first;
     Value *Base = Pair.second.getBaseValue();
     assert(BDV && Base);
-    // the assumption is that whenever we have a derived ptr(s), their base
+    // Whenever we have a derived ptr(s), their base
     // ptr(s) must be of the same size, not necessarily the same type
     assert(DL.getTypeAllocSize(BDV->getType()) ==
                DL.getTypeAllocSize(Base->getType()) &&



More information about the llvm-commits mailing list