aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
diff options
context:
space:
mode:
authorAlexandros Lamprineas <alexandros.lamprineas@arm.com>2023-07-13 11:54:49 +0100
committerAlexandros Lamprineas <alexandros.lamprineas@arm.com>2023-07-14 14:00:23 +0100
commitbb6d60bf9dfea82814d9e50c5bb457c47d010611 (patch)
tree4c3f0a6a7ea472dc97761bf50b7954f628ac49e4 /llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
parent9170fa58082e368f8b6ed8e0e6ef88fad8dd4633 (diff)
downloadllvm-bb6d60bf9dfea82814d9e50c5bb457c47d010611.zip
llvm-bb6d60bf9dfea82814d9e50c5bb457c47d010611.tar.gz
llvm-bb6d60bf9dfea82814d9e50c5bb457c47d010611.tar.bz2
[FuncSpec][NFC] Sink cast into function.
Before looking up a value in the map of known constants we attempt to dynamically cast it. The code looks cleaner if we move the cast inside findConstantFor(), where the look up happens. Differential Revision: https://reviews.llvm.org/D155177
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionSpecialization.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/FunctionSpecialization.cpp24
1 files changed, 7 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index b51b45a..47d1fcf 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -145,6 +145,8 @@ static Cost estimateBasicBlocks(SmallVectorImpl<BasicBlock *> &WorkList,
}
static Constant *findConstantFor(Value *V, ConstMap &KnownConstants) {
+ if (auto *C = dyn_cast<Constant>(V))
+ return C;
if (auto It = KnownConstants.find(V); It != KnownConstants.end())
return It->second;
return nullptr;
@@ -240,9 +242,7 @@ Constant *InstCostVisitor::visitCallBase(CallBase &I) {
for (unsigned Idx = 0, E = I.getNumOperands() - 1; Idx != E; ++Idx) {
Value *V = I.getOperand(Idx);
- auto *C = dyn_cast<Constant>(V);
- if (!C)
- C = findConstantFor(V, KnownConstants);
+ Constant *C = findConstantFor(V, KnownConstants);
if (!C)
return nullptr;
Operands.push_back(C);
@@ -264,9 +264,7 @@ Constant *InstCostVisitor::visitGetElementPtrInst(GetElementPtrInst &I) {
for (unsigned Idx = 0, E = I.getNumOperands(); Idx != E; ++Idx) {
Value *V = I.getOperand(Idx);
- auto *C = dyn_cast<Constant>(V);
- if (!C)
- C = findConstantFor(V, KnownConstants);
+ Constant *C = findConstantFor(V, KnownConstants);
if (!C)
return nullptr;
Operands.push_back(C);
@@ -282,9 +280,7 @@ Constant *InstCostVisitor::visitSelectInst(SelectInst &I) {
Value *V = LastVisited->second->isZeroValue() ? I.getFalseValue()
: I.getTrueValue();
- auto *C = dyn_cast<Constant>(V);
- if (!C)
- C = findConstantFor(V, KnownConstants);
+ Constant *C = findConstantFor(V, KnownConstants);
return C;
}
@@ -296,10 +292,7 @@ Constant *InstCostVisitor::visitCastInst(CastInst &I) {
Constant *InstCostVisitor::visitCmpInst(CmpInst &I) {
bool Swap = I.getOperand(1) == LastVisited->first;
Value *V = Swap ? I.getOperand(0) : I.getOperand(1);
- auto *Other = dyn_cast<Constant>(V);
- if (!Other)
- Other = findConstantFor(V, KnownConstants);
-
+ Constant *Other = findConstantFor(V, KnownConstants);
if (!Other)
return nullptr;
@@ -316,10 +309,7 @@ Constant *InstCostVisitor::visitUnaryOperator(UnaryOperator &I) {
Constant *InstCostVisitor::visitBinaryOperator(BinaryOperator &I) {
bool Swap = I.getOperand(1) == LastVisited->first;
Value *V = Swap ? I.getOperand(0) : I.getOperand(1);
- auto *Other = dyn_cast<Constant>(V);
- if (!Other)
- Other = findConstantFor(V, KnownConstants);
-
+ Constant *Other = findConstantFor(V, KnownConstants);
if (!Other)
return nullptr;