aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-03 11:17:26 +0100
committerNikita Popov <npopov@redhat.com>2023-11-03 11:25:40 +0100
commit85f79233286c78a1b79d01ca0677230658732b35 (patch)
tree7806ed0bf3c83e94641d3d00b85452653edab0fe /llvm/lib/IR/ConstantFold.cpp
parent8fd43fddd3b1c1dba9d59a10268a6cd71c2e3504 (diff)
downloadllvm-85f79233286c78a1b79d01ca0677230658732b35.zip
llvm-85f79233286c78a1b79d01ca0677230658732b35.tar.gz
llvm-85f79233286c78a1b79d01ca0677230658732b35.tar.bz2
[ConstantFold] Remove unnecessary cast of zero gep fold (NFCI)
Zero GEPs will be optimized away entirely, except in the cases which this transform also excludes (splat, inrange).
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp22
1 files changed, 0 insertions, 22 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 4651767..d69665b 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -233,28 +233,6 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
// Try hard to fold cast of cast because they are often eliminable.
if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
return foldMaybeUndesirableCast(newOpc, CE->getOperand(0), DestTy);
- } else if (CE->getOpcode() == Instruction::GetElementPtr &&
- // Do not fold addrspacecast (gep 0, .., 0). It might make the
- // addrspacecast uncanonicalized.
- opc != Instruction::AddrSpaceCast &&
- // Do not fold bitcast (gep) with inrange index, as this loses
- // information.
- !cast<GEPOperator>(CE)->getInRangeIndex() &&
- // Do not fold if the gep type is a vector, as bitcasting
- // operand 0 of a vector gep will result in a bitcast between
- // different sizes.
- !CE->getType()->isVectorTy()) {
- // If all of the indexes in the GEP are null values, there is no pointer
- // adjustment going on. We might as well cast the source pointer.
- bool isAllNull = true;
- for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
- if (!CE->getOperand(i)->isNullValue()) {
- isAllNull = false;
- break;
- }
- if (isAllNull)
- // This is casting one pointer type to another, always BitCast
- return ConstantExpr::getPointerCast(CE->getOperand(0), DestTy);
}
}