[llvm] bb6d60b - [FuncSpec][NFC] Sink cast into function.
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 06:03:41 PDT 2023
Author: Alexandros Lamprineas
Date: 2023-07-14T14:00:23+01:00
New Revision: bb6d60bf9dfea82814d9e50c5bb457c47d010611
URL: https://github.com/llvm/llvm-project/commit/bb6d60bf9dfea82814d9e50c5bb457c47d010611
DIFF: https://github.com/llvm/llvm-project/commit/bb6d60bf9dfea82814d9e50c5bb457c47d010611.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index b51b45a8fb16ea..47d1fcfabc7845 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;
More information about the llvm-commits
mailing list