Skip to content

Commit e4dc7d4

Browse files
committed
[InstCombine] Remove redundant cast of GEP fold (NFC)
With opaque pointers, zero-index GEPs will be eliminated in general.
1 parent 4d4f603 commit e4dc7d4

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,29 +1916,6 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {
19161916
return nullptr;
19171917
}
19181918

1919-
/// Implement the transforms for cast of pointer (bitcast/ptrtoint)
1920-
Instruction *InstCombinerImpl::commonPointerCastTransforms(CastInst &CI) {
1921-
Value *Src = CI.getOperand(0);
1922-
1923-
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Src)) {
1924-
// If casting the result of a getelementptr instruction with no offset, turn
1925-
// this into a cast of the original pointer!
1926-
if (GEP->hasAllZeroIndices() &&
1927-
// If CI is an addrspacecast and GEP changes the poiner type, merging
1928-
// GEP into CI would undo canonicalizing addrspacecast with different
1929-
// pointer types, causing infinite loops.
1930-
(!isa<AddrSpaceCastInst>(CI) ||
1931-
GEP->getType() == GEP->getPointerOperandType())) {
1932-
// Changing the cast operand is usually not a good idea but it is safe
1933-
// here because the pointer operand is being replaced with another
1934-
// pointer operand so the opcode doesn't need to change.
1935-
return replaceOperand(CI, 0, GEP->getOperand(0));
1936-
}
1937-
}
1938-
1939-
return commonCastTransforms(CI);
1940-
}
1941-
19421919
Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
19431920
// If the destination integer type is not the intptr_t type for this target,
19441921
// do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
@@ -1980,7 +1957,7 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
19801957
return InsertElementInst::Create(Vec, NewCast, Index);
19811958
}
19821959

1983-
return commonPointerCastTransforms(CI);
1960+
return commonCastTransforms(CI);
19841961
}
19851962

19861963
/// This input value (which is known to have vector type) is being zero extended
@@ -2702,11 +2679,9 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
27022679
if (Instruction *I = foldBitCastSelect(CI, Builder))
27032680
return I;
27042681

2705-
if (SrcTy->isPointerTy())
2706-
return commonPointerCastTransforms(CI);
27072682
return commonCastTransforms(CI);
27082683
}
27092684

27102685
Instruction *InstCombinerImpl::visitAddrSpaceCast(AddrSpaceCastInst &CI) {
2711-
return commonPointerCastTransforms(CI);
2686+
return commonCastTransforms(CI);
27122687
}

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
131131
Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1,
132132
BinaryOperator &I);
133133
Instruction *commonCastTransforms(CastInst &CI);
134-
Instruction *commonPointerCastTransforms(CastInst &CI);
135134
Instruction *visitTrunc(TruncInst &CI);
136135
Instruction *visitZExt(ZExtInst &Zext);
137136
Instruction *visitSExt(SExtInst &Sext);

0 commit comments

Comments
 (0)