[llvm] 3ec44c2 - [DeadArgElim] Guard against function type mismatch

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 05:03:52 PDT 2022


Author: Nikita Popov
Date: 2022-03-14T13:03:04+01:00
New Revision: 3ec44c22b1d60cf63ab93a4a9097d8c2a0ad08aa

URL: https://github.com/llvm/llvm-project/commit/3ec44c22b1d60cf63ab93a4a9097d8c2a0ad08aa
DIFF: https://github.com/llvm/llvm-project/commit/3ec44c22b1d60cf63ab93a4a9097d8c2a0ad08aa.diff

LOG: [DeadArgElim] Guard against function type mismatch

If the call function type and function type don't match, we should
consider the function live (there is effectively a bitcast
sitting in between).

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
    llvm/test/Transforms/DeadArgElim/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index d7d6c7d31bc2f..1e25c7724d1f1 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -560,7 +560,8 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
     // If the function is PASSED IN as an argument, its address has been
     // taken.
     const auto *CB = dyn_cast<CallBase>(U.getUser());
-    if (!CB || !CB->isCallee(&U)) {
+    if (!CB || !CB->isCallee(&U) ||
+        CB->getFunctionType() != F.getFunctionType()) {
       MarkLive(F);
       return;
     }

diff  --git a/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll b/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll
index 039614d96980d..02f2e0162ae07 100644
--- a/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll
+++ b/llvm/test/Transforms/DeadArgElim/opaque-ptr.ll
@@ -21,3 +21,21 @@ define void @caller() {
   call void @callee(i32 42, i32 24)
   ret void
 }
+
+define internal i16 @callee2(i16 %p1, i16 %p2) {
+; CHECK-LABEL: define {{[^@]+}}@callee2
+; CHECK-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) {
+; CHECK-NEXT:    ret i16 [[P2]]
+;
+  ret i16 %p2
+}
+
+define i16 @caller2(i16 %a) {
+; CHECK-LABEL: define {{[^@]+}}@caller2
+; CHECK-SAME: (i16 [[A:%.*]]) {
+; CHECK-NEXT:    [[CALL:%.*]] = call i16 @callee2(i16 [[A]], i32 42)
+; CHECK-NEXT:    ret i16 [[CALL]]
+;
+  %call = call i16 @callee2(i16 %a, i32 42)
+  ret i16 %call
+}


        


More information about the llvm-commits mailing list