[llvm] 1b6663a - [FuncSpec] Remove unnecessary function pointer type check

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 06:23:37 PST 2022


Author: Nikita Popov
Date: 2022-03-03T15:20:11+01:00
New Revision: 1b6663a10458ab2bb242f8f28940dd3ea1271e70

URL: https://github.com/llvm/llvm-project/commit/1b6663a10458ab2bb242f8f28940dd3ea1271e70
DIFF: https://github.com/llvm/llvm-project/commit/1b6663a10458ab2bb242f8f28940dd3ea1271e70.diff

LOG: [FuncSpec] Remove unnecessary function pointer type check

We will check a bit later that the constant is in fact a function,
so the separate check for a function pointer type is largely
redunant. Also simplify the cast stripping with
stripPointerCasts().

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 e625868fe6a83..5d0ec6e4f9dc0 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -583,19 +583,8 @@ class FunctionSpecializer {
 
     // The below heuristic is only concerned with exposing inlining
     // opportunities via indirect call promotion. If the argument is not a
-    // function pointer, give up.
-    if (!isa<PointerType>(A->getType()) ||
-        !isa<FunctionType>(A->getType()->getPointerElementType()))
-      return TotalCost;
-
-    // Since the argument is a function pointer, its incoming constant values
-    // should be functions or constant expressions. The code below attempts to
-    // look through cast expressions to find the function that will be called.
-    Value *CalledValue = C;
-    while (isa<ConstantExpr>(CalledValue) &&
-           cast<ConstantExpr>(CalledValue)->isCast())
-      CalledValue = cast<User>(CalledValue)->getOperand(0);
-    Function *CalledFunction = dyn_cast<Function>(CalledValue);
+    // (potentially casted) function pointer, give up.
+    Function *CalledFunction = dyn_cast<Function>(C->stripPointerCasts());
     if (!CalledFunction)
       return TotalCost;
 


        


More information about the llvm-commits mailing list