[llvm] 7c3e2b9 - [RewriteStatepointsForGC] Fix an incorrect assertion

Daniil Suchkov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 10:45:37 PST 2022


Author: Daniil Suchkov
Date: 2022-02-17T18:44:57Z
New Revision: 7c3e2b92cf66fd7cf84e59e10fb911d0887c5788

URL: https://github.com/llvm/llvm-project/commit/7c3e2b92cf66fd7cf84e59e10fb911d0887c5788
DIFF: https://github.com/llvm/llvm-project/commit/7c3e2b92cf66fd7cf84e59e10fb911d0887c5788.diff

LOG: [RewriteStatepointsForGC] Fix an incorrect assertion

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.

Reviewed By: skatkov, reames

Differential Revision: https://reviews.llvm.org/D119994

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 6be0c7dc3adac..9d7ea43629d8b 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1164,13 +1164,21 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache) {
 #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 
diff erent is by
           // being 
diff erent 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
         }

diff  --git a/llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll b/llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll
index 6f69234cc993e..f87b84ef3480b 100644
--- a/llvm/test/Transforms/RewriteStatepointsForGC/phi-vector-bitcast.ll
+++ b/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
 


        


More information about the llvm-commits mailing list