[PATCH] D128792: [ConstExpr] Don't create insertvalue expressions
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 01:57:36 PDT 2022
nikic created this revision.
nikic added reviewers: reames, nhaehnle.
Herald added subscribers: ChuanqiXu, haicheng, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In preparation for the removal in D128719 <https://reviews.llvm.org/D128719>, this stops creating insertvalue constant expressions as part (well, unless it's directly used in LLVM IR).
https://reviews.llvm.org/D128792
Files:
clang/lib/CodeGen/ItaniumCXXABI.cpp
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/Transforms/Utils/Evaluator.cpp
Index: llvm/lib/Transforms/Utils/Evaluator.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Evaluator.cpp
+++ llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -368,9 +368,11 @@
LLVM_DEBUG(dbgs() << "Found an ExtractValueInst! Simplifying: "
<< *InstResult << "\n");
} else if (auto *IVI = dyn_cast<InsertValueInst>(CurInst)) {
- InstResult = ConstantExpr::getInsertValue(
+ InstResult = ConstantFoldInsertValueInstruction(
getVal(IVI->getAggregateOperand()),
getVal(IVI->getInsertedValueOperand()), IVI->getIndices());
+ if (!InstResult)
+ return false;
LLVM_DEBUG(dbgs() << "Found an InsertValueInst! Simplifying: "
<< *InstResult << "\n");
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -2089,9 +2089,9 @@
bool CallAnalyzer::visitInsertValue(InsertValueInst &I) {
// Constant folding for insert value is trivial.
if (simplifyInstruction(I, [&](SmallVectorImpl<Constant *> &COps) {
- return ConstantExpr::getInsertValue(/*AggregateOperand*/ COps[0],
- /*InsertedValueOperand*/ COps[1],
- I.getIndices());
+ return ConstantFoldInsertValueInstruction(
+ /*AggregateOperand*/ COps[0], /*InsertedValueOperand*/ COps[1],
+ I.getIndices());
}))
return true;
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -1195,7 +1195,8 @@
}
if (auto *IVI = dyn_cast<InsertValueInst>(I))
- return ConstantExpr::getInsertValue(Ops[0], Ops[1], IVI->getIndices());
+ return ConstantFoldInsertValueInstruction(Ops[0], Ops[1],
+ IVI->getIndices());
if (auto *EVI = dyn_cast<ExtractValueInst>(I))
return ConstantFoldExtractValueInstruction(Ops[0], EVI->getIndices());
Index: llvm/include/llvm/IR/ConstantFolder.h
===================================================================
--- llvm/include/llvm/IR/ConstantFolder.h
+++ llvm/include/llvm/IR/ConstantFolder.h
@@ -107,7 +107,7 @@
auto *CAgg = dyn_cast<Constant>(Agg);
auto *CVal = dyn_cast<Constant>(Val);
if (CAgg && CVal)
- return ConstantExpr::getInsertValue(CAgg, CVal, IdxList);
+ return ConstantFoldInsertValueInstruction(CAgg, CVal, IdxList);
return nullptr;
}
Index: llvm/include/llvm/Analysis/TargetFolder.h
===================================================================
--- llvm/include/llvm/Analysis/TargetFolder.h
+++ llvm/include/llvm/Analysis/TargetFolder.h
@@ -118,7 +118,7 @@
auto *CAgg = dyn_cast<Constant>(Agg);
auto *CVal = dyn_cast<Constant>(Val);
if (CAgg && CVal)
- return Fold(ConstantExpr::getInsertValue(CAgg, CVal, IdxList));
+ return ConstantFoldInsertValueInstruction(CAgg, CVal, IdxList);
return nullptr;
}
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -962,7 +962,9 @@
else
dstAdj = llvm::ConstantExpr::getNSWAdd(srcAdj, adj);
- return llvm::ConstantExpr::getInsertValue(src, dstAdj, 1);
+ llvm::Constant *res = ConstantFoldInsertValueInstruction(src, dstAdj, 1);
+ assert(res != nullptr && "Folding must succeed");
+ return res;
}
llvm::Constant *
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128792.440899.patch
Type: text/x-patch
Size: 3792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/36efd5f6/attachment.bin>
More information about the llvm-commits
mailing list