[PATCH] D119994: [RewriteStatepointsForGC] Fix an incorrect assertion

Daniil Suchkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 16:53:06 PST 2022


DaniilSuchkov created this revision.
DaniilSuchkov added reviewers: anna, reames, skatkov.
Herald added a subscriber: hiraditya.
DaniilSuchkov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The assertion verifying that a newly computed value matches what is
already cached used stripPointerCasts() to strip bitcasts, however the
values can be not only pointers, but also vectors of pointers. That is
problematic because stripPointerCasts() doesn't handle vectors of
pointers. This patch introduces an ad-hoc utility function to strip all
bitcasts regardless of the value type.


https://reviews.llvm.org/D119994

Files:
  llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
  llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll


Index: llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll
===================================================================
--- llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll
+++ llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll
@@ -1,4 +1,3 @@
-; XFAIL: *
 ; REQUIRES: asserts
 ; RUN: opt < %s -disable-output -passes=rewrite-statepoints-for-gc
 
Index: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1164,13 +1164,21 @@
 #ifndef NDEBUG
           Value *OldBase = BlockToValue[InBB];
           Value *Base = getBaseForInput(InVal, nullptr);
+
+          // We can't use `stripPointerCasts` instead of this function because
+          // `stripPointerCasts` doesn't handle vectors of pointers.
+          auto StripBitCasts = [](Value *V) -> Value * {
+            while (auto *BC = dyn_cast<BitCastInst>(V))
+              V = BC->getOperand(0);
+            return V;
+          };
           // In essence this assert states: the only way two values
           // incoming from the same basic block may be different is by
           // being different bitcasts of the same value.  A cleanup
           // that remains TODO is changing findBaseOrBDV to return an
           // llvm::Value of the correct type (and still remain pure).
           // This will remove the need to add bitcasts.
-          assert(Base->stripPointerCasts() == OldBase->stripPointerCasts() &&
+          assert(StripBitCasts(Base) == StripBitCasts(OldBase) &&
                  "findBaseOrBDV should be pure!");
 #endif
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119994.409451.patch
Type: text/x-patch
Size: 1765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220217/6fb0911a/attachment.bin>


More information about the llvm-commits mailing list