[llvm] 73cd8e2 - [InstCombine] Skip PromoteCastOfAllocation() transform under opaque pointers

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 27 01:25:53 PST 2022


Author: Nikita Popov
Date: 2022-01-27T10:25:45+01:00
New Revision: 73cd8e29ad1d95692e480b85ccbefe5212468e9c

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

LOG: [InstCombine] Skip PromoteCastOfAllocation() transform under opaque pointers

I think this can't be hit anyway (because a ptr-to-ptr bitcast would
get folded earlier), but in the interest of being explicit skip
this transform for opaque pointers entirely.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 10a7c1b406a5..f11ba8772f3c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -85,13 +85,16 @@ static Value *decomposeSimpleLinearExpr(Value *Val, unsigned &Scale,
 Instruction *InstCombinerImpl::PromoteCastOfAllocation(BitCastInst &CI,
                                                        AllocaInst &AI) {
   PointerType *PTy = cast<PointerType>(CI.getType());
+  // Opaque pointers don't have an element type we could replace with.
+  if (PTy->isOpaque())
+    return nullptr;
 
   IRBuilderBase::InsertPointGuard Guard(Builder);
   Builder.SetInsertPoint(&AI);
 
   // Get the type really allocated and the type casted to.
   Type *AllocElTy = AI.getAllocatedType();
-  Type *CastElTy = PTy->getPointerElementType();
+  Type *CastElTy = PTy->getNonOpaquePointerElementType();
   if (!AllocElTy->isSized() || !CastElTy->isSized()) return nullptr;
 
   // This optimisation does not work for cases where the cast type


        


More information about the llvm-commits mailing list