[ValueTracking] Avoid use of ConstantExpr::getCast()
Use the constant folding API instead.
GitOrigin-RevId: 74ab4937c1ed2f156606f620b5eed758492673c7
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index d93e030..0736ef6 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -7834,6 +7834,7 @@
if (!C)
return nullptr;
+ const DataLayout &DL = CmpI->getModule()->getDataLayout();
Constant *CastedTo = nullptr;
switch (*CastOp) {
case Instruction::ZExt:
@@ -7871,7 +7872,8 @@
// CmpConst == C is checked below.
CastedTo = CmpConst;
} else {
- CastedTo = ConstantExpr::getIntegerCast(C, SrcTy, CmpI->isSigned());
+ unsigned ExtOp = CmpI->isSigned() ? Instruction::SExt : Instruction::ZExt;
+ CastedTo = ConstantFoldCastOperand(ExtOp, C, SrcTy, DL);
}
break;
case Instruction::FPTrunc:
@@ -7901,8 +7903,8 @@
// Make sure the cast doesn't lose any information.
Constant *CastedBack =
- ConstantExpr::getCast(*CastOp, CastedTo, C->getType(), true);
- if (CastedBack != C)
+ ConstantFoldCastOperand(*CastOp, CastedTo, C->getType(), DL);
+ if (CastedBack && CastedBack != C)
return nullptr;
return CastedTo;