namespace {
-Constant *ConstantFoldLoadInst(const LoadInst *LI, const DataLayout &DL) {
- if (LI->isVolatile()) return nullptr;
-
- if (auto *C = dyn_cast<Constant>(LI->getOperand(0)))
- return ConstantFoldLoadFromConstPtr(C, LI->getType(), DL);
-
- return nullptr;
-}
-
/// One of Op0/Op1 is a constant expression.
/// Attempt to symbolically evaluate the result of a binary operator merging
/// these together. If target data info is available, it is provided as DL,
return ConstantFoldCompareInstOperands(CI->getPredicate(), Ops[0], Ops[1],
DL, TLI);
- if (const auto *LI = dyn_cast<LoadInst>(I))
- return ConstantFoldLoadInst(LI, DL);
-
- if (auto *IVI = dyn_cast<InsertValueInst>(I)) {
- return ConstantExpr::getInsertValue(
- cast<Constant>(IVI->getAggregateOperand()),
- cast<Constant>(IVI->getInsertedValueOperand()),
- IVI->getIndices());
+ if (const auto *LI = dyn_cast<LoadInst>(I)) {
+ if (LI->isVolatile())
+ return nullptr;
+ return ConstantFoldLoadFromConstPtr(Ops[0], LI->getType(), DL);
}
- if (auto *EVI = dyn_cast<ExtractValueInst>(I)) {
- return ConstantExpr::getExtractValue(
- cast<Constant>(EVI->getAggregateOperand()),
- EVI->getIndices());
- }
+ if (auto *IVI = dyn_cast<InsertValueInst>(I))
+ return ConstantExpr::getInsertValue(Ops[0], Ops[1], IVI->getIndices());
+
+ if (auto *EVI = dyn_cast<ExtractValueInst>(I))
+ return ConstantExpr::getExtractValue(Ops[0], EVI->getIndices());
return ConstantFoldInstOperands(I, Ops, DL, TLI);
}