Skip to content

Commit

Permalink
[InstCombine] Skip GEP of bitcast transform with opaque pointers
Browse files Browse the repository at this point in the history
This transform is fundamentally incompatible with opaque pointers.
Usually we would not hit it anyway because the bitcast is folded
away earlier, but due to worklist order it might survive until
here, so make sure we bail out explicitly.
  • Loading branch information
nikic committed Jan 27, 2022
1 parent b7179d9 commit 2c736f6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Expand Up @@ -2082,10 +2082,15 @@ Instruction *InstCombinerImpl::visitGEPOfGEP(GetElementPtrInst &GEP,
// Note that we may have also stripped an address space cast in between.
Instruction *InstCombinerImpl::visitGEPOfBitcast(BitCastInst *BCI,
GetElementPtrInst &GEP) {
// With opaque pointers, there is no pointer element type we can use to
// adjust the GEP type.
PointerType *SrcType = cast<PointerType>(BCI->getSrcTy());
if (SrcType->isOpaque())
return nullptr;

Type *GEPEltType = GEP.getSourceElementType();
Type *SrcEltType = SrcType->getNonOpaquePointerElementType();
Value *SrcOp = BCI->getOperand(0);
PointerType *SrcType = cast<PointerType>(BCI->getSrcTy());
Type *SrcEltType = SrcType->getPointerElementType();

// GEP directly using the source operand if this GEP is accessing an element
// of a bitcasted pointer to vector or array of the same dimensions:
Expand Down

0 comments on commit 2c736f6

Please sign in to comment.