Home | History | Annotate | Download | only in InstCombine

Lines Matching refs:GEP

78 Value *InstCombiner::EmitGEPOffset(User *GEP) {
79 return llvm::EmitGEPOffset(Builder, DL, GEP);
869 /// whether or not there is a sequence of GEP indices into the pointed type that
930 static bool shouldMergeGEPs(GEPOperator &GEP, GEPOperator &Src) {
931 // If this GEP has only 0 indices, it is the same pointer as
932 // Src. If Src is not a trivial GEP too, don't combine
934 if (GEP.hasAllZeroIndices() && !Src.hasAllZeroIndices() &&
1287 Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
1288 SmallVector<Value*, 8> Ops(GEP.op_begin(), GEP.op_end());
1291 return ReplaceInstUsesWith(GEP, V);
1293 Value *PtrOp = GEP.getOperand(0);
1298 Type *IntPtrTy = DL.getIntPtrType(GEP.getPointerOperandType());
1300 gep_type_iterator GTI = gep_type_begin(GEP);
1301 for (User::op_iterator I = GEP.op_begin() + 1, E = GEP.op_end(); I != E;
1327 return &GEP;
1335 // Don't fold a GEP into itself through a PHI node. This can only happen
1336 // through the back-edge of a loop. Folding a GEP into itself means that
1339 // actually achieving anything (the GEP still needs to be executed once per
1341 if (Op1 == &GEP)
1351 // As for Op1 above, don't try to fold a GEP into itself.
1352 if (Op2 == &GEP)
1355 // Keep track of the type as we walk the GEP.
1368 // The first two arguments can vary for any GEP, the rest have to be
1375 // The GEP is different by more than one input. While this could be
1400 // BB so that it can be merged with the current GEP.
1401 GEP.getParent()->getInstList().insert(
1402 GEP.getParent()->getFirstInsertionPt(), NewGEP);
1404 // All the GEPs feeding the PHI differ at a single offset. Clone a GEP
1418 GEP.getParent()->getInstList().insert(
1419 GEP.getParent()->getFirstInsertionPt(), NewGEP);
1423 GEP.setOperand(0, NewGEP);
1432 if (!shouldMergeGEPs(*cast<GEPOperator>(&GEP), *Src))
1435 // Note that if our source is a gep chain itself then we wait for that
1445 // Find out whether the last index in the source GEP is a sequential idx.
1453 // Replace: gep (gep %P, long B), long A, ...
1454 // With: T = long A+B; gep %P, T, ...
1458 Value *GO1 = GEP.getOperand(1);
1473 // Update the GEP in place if possible.
1475 GEP.setOperand(0, Src->getOperand(0));
1476 GEP.setOperand(1, Sum);
1477 return &GEP;
1481 Indices.append(GEP.op_begin()+2, GEP.op_end());
1482 } else if (isa<Constant>(*GEP.idx_begin()) &&
1483 cast<Constant>(*GEP.idx_begin())->isNullValue() &&
1485 // Otherwise we can do the fold if the first index of the GEP is a zero
1487 Indices.append(GEP.idx_begin()+1, GEP.idx_end());
1491 return GEP.isInBounds() && Src->isInBounds()
1494 GEP.getName())
1497 GEP.getName());
1500 if (GEP.getNumIndices() == 1) {
1501 unsigned AS = GEP.getPointerAddressSpace();
1502 if (GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
1504 Type *PtrTy = GEP.getPointerOperandType();
1512 V = GEP.getOperand(1);
1514 } else if (match(GEP.getOperand(1),
1518 } else if (match(GEP.getOperand(1),
1525 // Canonicalize (gep i8* X, -(ptrtoint Y))
1527 // The GEP pattern is emitted by the SCEV expander for certain kinds of
1533 return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
1535 // Canonicalize (gep i8* X, (ptrtoint Y)-(ptrtoint X))
1539 m_PtrToInt(m_Specific(GEP.getOperand(0)))))) {
1541 GEP.getType());
1547 // Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
1557 if (ConstantInt *C = dyn_cast<ConstantInt>(GEP.getOperand(1)))
1560 // Transform: GEP (bitcast [10 x i8]* X to [0 x i8]*), i32 0, ...
1561 // into : GEP [10 x i8]* X, i32 0, ...
1563 // Likewise, transform: GEP (bitcast i8* X to [0 x i8]*), i32 0, ...
1564 // into : GEP i8* X, ...
1571 // GEP (bitcast i8* X to [0 x i8]*), i32 0, ... ?
1573 // -> GEP i8* X, ...
1574 SmallVector<Value*, 8> Idx(GEP.idx_begin()+1, GEP.idx_end());
1576 StrippedPtrTy->getElementType(), StrippedPtr, Idx, GEP.getName());
1577 Res->setIsInBounds(GEP.isInBounds());
1578 if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace())
1582 // GEP (addrspacecast i8 addrspace(1)* X to [0 x i8]*), i32 0, ...
1584 // %0 = GEP i8 addrspace(1)* X, ...
1586 return new AddrSpaceCastInst(Builder->Insert(Res), GEP.getType());
1591 // GEP (bitcast [10 x i8]* X to [0 x i8]*), i32 0, ... ?
1593 // -> GEP [10 x i8]* X, i32 0, ...
1597 // is a leading zero) we can fold the cast into this GEP.
1598 if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
1599 GEP.setOperand(0, StrippedPtr);
1600 return &GEP;
1603 // address space is different. Instead, create a new GEP followed by
1606 // GEP (addrspacecast [10 x i8] addrspace(1)* X to [0 x i8]*),
1609 // %0 = GEP [10 x i8] addrspace(1)* X, ...
1611 SmallVector<Value*, 8> Idx(GEP.idx_begin(), GEP.idx_end());
1612 Value *NewGEP = GEP.isInBounds()
1614 nullptr, StrippedPtr, Idx, GEP.getName())
1616 GEP.getName());
1617 return new AddrSpaceCastInst(NewGEP, GEP.getType());
1621 } else if (GEP.getNumOperands() == 2) {
1630 Type *IdxType = DL.getIntPtrType(GEP.getType());
1631 Value *Idx[2] = { Constant::getNullValue(IdxType), GEP.getOperand(1) };
1633 GEP.isInBounds()
1635 GEP.getName())
1636 : Builder->CreateGEP(nullptr, StrippedPtr, Idx, GEP.getName());
1638 // V and GEP are both pointer types --> BitCast
1640 GEP.getType());
1653 Value *Idx = GEP.getOperand(1);
1659 assert(Idx->getType() == DL.getIntPtrType(GEP.getType()) &&
1664 // Successfully decomposed Idx as NewIdx * Scale, form a new GEP.
1666 // GEP may not be "inbounds".
1668 GEP.isInBounds() && NSW
1670 GEP.getName())
1672 GEP.getName());
1676 GEP.getType());
1692 Value *Idx = GEP.getOperand(1);
1698 assert(Idx->getType() == DL.getIntPtrType(GEP.getType()) &&
1703 // Successfully decomposed Idx as NewIdx * Scale, form a new GEP.
1705 // GEP may not be "inbounds".
1707 Constant::getNullValue(DL.getIntPtrType(GEP.getType())),
1710 Value *NewGEP = GEP.isInBounds() && NSW
1712 SrcElTy, StrippedPtr, Off, GEP.getName())
1714 GEP.getName());
1717 GEP.getType());
1725 // addrspacecast. To take advantage of the below bitcast + struct GEP, look
1730 // Z = gep Y, <...constant indices...>
1731 // Into an addrspacecasted GEP of the struct.
1738 /// Y = gep X, <...constant indices...>
1739 /// into a gep of the original struct. This is important for SROA and alias
1744 unsigned OffsetBits = DL.getPointerTypeSizeInBits(GEP.getType());
1747 GEP.accumulateConstantOffset(DL, Offset)) {
1749 // If this GEP instruction doesn't move the pointer, just replace the GEP
1755 // See if the bitcast simplifies, if so, don't nuke this GEP yet.
1762 return &GEP;
1766 if (Operand->getType()->getPointerAddressSpace() != GEP.getAddressSpace())
1767 return new AddrSpaceCastInst(Operand, GEP.getType());
1768 return new BitCastInst(Operand, GEP.getType());
1773 // GEP.
1777 GEP.isInBounds()
1781 if (NGEP->getType() == GEP.getType())
1782 return ReplaceInstUsesWith(GEP, NGEP);
1783 NGEP->takeName(&GEP);
1785 if (NGEP->getType()->getPointerAddressSpace() != GEP.getAddressSpace())
1786 return new AddrSpaceCastInst(NGEP, GEP.getType());
1787 return new BitCastInst(NGEP, GEP.getType());
2256 // load from a GEP. This reduces the size of the load.
2271 Value *GEP = Builder->CreateInBoundsGEP(L->getType(),
2275 return ReplaceInstUsesWith(EV, Builder->CreateLoad(GEP));
2281 // loads: extract (extract (load)) will be translated to extract (load (gep))
2282 // and if again single-use then via load (gep (gep)) to load (gep).