diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -748,15 +748,6 @@ namespace { -Constant *ConstantFoldLoadInst(const LoadInst *LI, const DataLayout &DL) { - if (LI->isVolatile()) return nullptr; - - if (auto *C = dyn_cast(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, @@ -1206,21 +1197,17 @@ return ConstantFoldCompareInstOperands(CI->getPredicate(), Ops[0], Ops[1], DL, TLI); - if (const auto *LI = dyn_cast(I)) - return ConstantFoldLoadInst(LI, DL); - - if (auto *IVI = dyn_cast(I)) { - return ConstantExpr::getInsertValue( - cast(IVI->getAggregateOperand()), - cast(IVI->getInsertedValueOperand()), - IVI->getIndices()); + if (const auto *LI = dyn_cast(I)) { + if (LI->isVolatile()) + return nullptr; + return ConstantFoldLoadFromConstPtr(Ops[0], LI->getType(), DL); } - if (auto *EVI = dyn_cast(I)) { - return ConstantExpr::getExtractValue( - cast(EVI->getAggregateOperand()), - EVI->getIndices()); - } + if (auto *IVI = dyn_cast(I)) + return ConstantExpr::getInsertValue(Ops[0], Ops[1], IVI->getIndices()); + + if (auto *EVI = dyn_cast(I)) + return ConstantExpr::getExtractValue(Ops[0], EVI->getIndices()); return ConstantFoldInstOperands(I, Ops, DL, TLI); }