[llvm] 74ab493 - [ValueTracking] Avoid use of ConstantExpr::getCast()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 02:51:45 PDT 2023
Author: Nikita Popov
Date: 2023-09-29T11:48:59+02:00
New Revision: 74ab4937c1ed2f156606f620b5eed758492673c7
URL: https://github.com/llvm/llvm-project/commit/74ab4937c1ed2f156606f620b5eed758492673c7
DIFF: https://github.com/llvm/llvm-project/commit/74ab4937c1ed2f156606f620b5eed758492673c7.diff
LOG: [ValueTracking] Avoid use of ConstantExpr::getCast()
Use the constant folding API instead.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d93e030cdfa0c5b..0736ef65b306519 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7834,6 +7834,7 @@ static Value *lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2,
if (!C)
return nullptr;
+ const DataLayout &DL = CmpI->getModule()->getDataLayout();
Constant *CastedTo = nullptr;
switch (*CastOp) {
case Instruction::ZExt:
@@ -7871,7 +7872,8 @@ static Value *lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2,
// 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 @@ static Value *lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2,
// 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;
More information about the llvm-commits
mailing list