[llvm] b606e2d - [Evaluator] Bitcast result of pointer stripping

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 21 13:36:58 PDT 2021


Author: Arthur Eubanks
Date: 2021-04-21T13:32:29-07:00
New Revision: b606e2df4dd49c17c9f2733f2339b6dd0dd427de

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

LOG: [Evaluator] Bitcast result of pointer stripping

Trying to evaluate a GEP would assert with
  "Ty == cast<PointerType>(C->getType()->getScalarType())->getElementType()"
because the type of the pointer we would evaluate the GEP argument to
would be a different type than the GEP was expecting. We should treat
pointer stripping as a bitcast.

The test adds a redundant GEP that would crash due to type mismatch.

Reviewed By: rnk

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Evaluator.cpp
    llvm/test/Transforms/GlobalOpt/invariant.group.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index 7404ceb83ab87..02cfb09241721 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -566,6 +566,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
                        << "Stripped pointer casts for alias analysis for "
                           "intrinsic call.\n");
             StrippedPointerCastsForAliasAnalysis = true;
+            InstResult = ConstantExpr::getBitCast(InstResult, II->getType());
           } else {
             LLVM_DEBUG(dbgs() << "Unknown intrinsic. Cannot evaluate.\n");
             return false;

diff  --git a/llvm/test/Transforms/GlobalOpt/invariant.group.ll b/llvm/test/Transforms/GlobalOpt/invariant.group.ll
index 586432b60b650..6d192939a5e04 100644
--- a/llvm/test/Transforms/GlobalOpt/invariant.group.ll
+++ b/llvm/test/Transforms/GlobalOpt/invariant.group.ll
@@ -32,9 +32,10 @@ enter:
 
   %0 = bitcast i32* %valptr to i8*
   %barr = call i8* @llvm.launder.invariant.group(i8* %0)
-  %1 = bitcast i8* %barr to i32*
+  %1 = getelementptr i8, i8* %barr, i32 0
+  %2 = bitcast i8* %1 to i32*
 
-  %val2 = load i32, i32* %1
+  %val2 = load i32, i32* %2
   store i32 %val2, i32* @tmp2
   ret void
 }


        


More information about the llvm-commits mailing list