Skip to content

Commit

Permalink
[ConstantFolding] Avoid some uses of ConstantExpr::getCast()
Browse files Browse the repository at this point in the history
Call the constant folding API instead.
  • Loading branch information
nikic committed Sep 29, 2023
1 parent 0d328e3 commit 8934160
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Constant *llvm::ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy,
Cast = Instruction::PtrToInt;

if (CastInst::castIsValid(Cast, C, DestTy))
return ConstantExpr::getCast(Cast, C, DestTy);
return ConstantFoldCastOperand(Cast, C, DestTy, DL);
}

// If this isn't an aggregate type, there is nothing we can do to drill down
Expand Down Expand Up @@ -846,14 +846,14 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
SrcElemTy, Ops.slice(1, i - 1)))) &&
Ops[i]->getType()->getScalarType() != IntIdxScalarTy) {
Any = true;
Type *NewType = Ops[i]->getType()->isVectorTy()
? IntIdxTy
: IntIdxScalarTy;
NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
true,
NewType,
true),
Ops[i], NewType));
Type *NewType =
Ops[i]->getType()->isVectorTy() ? IntIdxTy : IntIdxScalarTy;
Constant *NewIdx = ConstantFoldCastOperand(
CastInst::getCastOpcode(Ops[i], true, NewType, true), Ops[i], NewType,
DL);
if (!NewIdx)
return nullptr;
NewIdxs.push_back(NewIdx);
} else
NewIdxs.push_back(Ops[i]);
}
Expand Down

0 comments on commit 8934160

Please sign in to comment.