Skip to content

Commit 8934160

Browse files
committed
[ConstantFolding] Avoid some uses of ConstantExpr::getCast()
Call the constant folding API instead.
1 parent 0d328e3 commit 8934160

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Constant *llvm::ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy,
383383
Cast = Instruction::PtrToInt;
384384

385385
if (CastInst::castIsValid(Cast, C, DestTy))
386-
return ConstantExpr::getCast(Cast, C, DestTy);
386+
return ConstantFoldCastOperand(Cast, C, DestTy, DL);
387387
}
388388

389389
// If this isn't an aggregate type, there is nothing we can do to drill down
@@ -846,14 +846,14 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
846846
SrcElemTy, Ops.slice(1, i - 1)))) &&
847847
Ops[i]->getType()->getScalarType() != IntIdxScalarTy) {
848848
Any = true;
849-
Type *NewType = Ops[i]->getType()->isVectorTy()
850-
? IntIdxTy
851-
: IntIdxScalarTy;
852-
NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
853-
true,
854-
NewType,
855-
true),
856-
Ops[i], NewType));
849+
Type *NewType =
850+
Ops[i]->getType()->isVectorTy() ? IntIdxTy : IntIdxScalarTy;
851+
Constant *NewIdx = ConstantFoldCastOperand(
852+
CastInst::getCastOpcode(Ops[i], true, NewType, true), Ops[i], NewType,
853+
DL);
854+
if (!NewIdx)
855+
return nullptr;
856+
NewIdxs.push_back(NewIdx);
857857
} else
858858
NewIdxs.push_back(Ops[i]);
859859
}

0 commit comments

Comments
 (0)