[llvm] 8934160 - [ConstantFolding] Avoid some uses of ConstantExpr::getCast()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 02:41:23 PDT 2023
Author: Nikita Popov
Date: 2023-09-29T11:41:14+02:00
New Revision: 893416051d517d979481510fe3b52d83ba0d1e01
URL: https://github.com/llvm/llvm-project/commit/893416051d517d979481510fe3b52d83ba0d1e01
DIFF: https://github.com/llvm/llvm-project/commit/893416051d517d979481510fe3b52d83ba0d1e01.diff
LOG: [ConstantFolding] Avoid some uses of ConstantExpr::getCast()
Call the constant folding API instead.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 501a8cb6bea519b..fab73c20f3f2d8d 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -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
@@ -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]);
}
More information about the llvm-commits
mailing list