[llvm] 2639fdc - [InlineCost]Account for switch instructons when the switch condition could be simplified as a result of inlines.

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 14:49:11 PDT 2023


Author: Mingming Liu
Date: 2023-09-20T14:49:06-07:00
New Revision: 2639fdc5dd0e41d6f45154741dc29d1ae4563906

URL: https://github.com/llvm/llvm-project/commit/2639fdc5dd0e41d6f45154741dc29d1ae4563906
DIFF: https://github.com/llvm/llvm-project/commit/2639fdc5dd0e41d6f45154741dc29d1ae4563906.diff

LOG: [InlineCost]Account for switch instructons when the switch condition could be simplified as a result of inlines.

Reviewed By: kazu

Differential Revision: https://reviews.llvm.org/D152053

Added: 
    

Modified: 
    llvm/lib/Analysis/InlineCost.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 84dc412a3ab6e18..71d35ad6cf3cacb 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -855,6 +855,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
                   SimplifiedValues.lookup(BI->getCondition()))) {
             CurrentSavings += InstrCost;
           }
+        } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I)) {
+          if (isa_and_present<ConstantInt>(SimplifiedValues.lookup(SI->getCondition())))
+            CurrentSavings += InstrCost;
         } else if (Value *V = dyn_cast<Value>(&I)) {
           // Count an instruction as savings if we can fold it.
           if (SimplifiedValues.count(V)) {


        


More information about the llvm-commits mailing list