Skip to content

Commit d873630

Browse files
committedJul 12, 2024
Revert "[InstCombine] Generalize ptrtoint(gep) fold (NFC)"
This reverts commit c45f939. This refactoring turned out to not be useful for the case I had originally in mind, so revert it for now.
1 parent b94c248 commit d873630

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,25 +2025,6 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {
20252025
return nullptr;
20262026
}
20272027

2028-
// Whether we should convert ptrtoint(gep P, X) to ptrtoint(P) + X
2029-
static bool shouldPushPtrToIntThroughGEP(GEPOperator *GEP, Type *IntTy,
2030-
const DataLayout &DL) {
2031-
if (!GEP->hasOneUse())
2032-
return false;
2033-
2034-
// Skip cases whether there is a mismatch between the pointer integer type
2035-
// and the index type, or the GEP performs an implicit splat operation.
2036-
if (DL.getIndexType(GEP->getType()) != IntTy ||
2037-
GEP->getType() != GEP->getPointerOperand()->getType())
2038-
return false;
2039-
2040-
// (ptrtoint (gep (inttoptr Base), Offset)) -> Base + Offset
2041-
if (match(GEP->getPointerOperand(), m_OneUse(m_IntToPtr(m_Value()))))
2042-
return true;
2043-
2044-
return false;
2045-
}
2046-
20472028
Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
20482029
// If the destination integer type is not the intptr_t type for this target,
20492030
// do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
@@ -2083,8 +2064,10 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
20832064
}
20842065

20852066
// (ptrtoint (gep (inttoptr Base), ...)) -> Base + Offset
2086-
if (shouldPushPtrToIntThroughGEP(GEP, Ty, DL)) {
2087-
Value *Base = Builder.CreatePtrToInt(GEP->getPointerOperand(), Ty);
2067+
Value *Base;
2068+
if (GEP->hasOneUse() &&
2069+
match(GEP->getPointerOperand(), m_OneUse(m_IntToPtr(m_Value(Base)))) &&
2070+
Base->getType() == Ty) {
20882071
Value *Offset = EmitGEPOffset(GEP);
20892072
auto *NewOp = BinaryOperator::CreateAdd(Base, Offset);
20902073
if (GEP->hasNoUnsignedWrap() ||

0 commit comments

Comments
 (0)