[llvm] e57cf12 - [SimplifyCFG] Sinking indirect calls - they're already indirect anyways

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 28 07:37:17 PDT 2021


Author: Roman Lebedev
Date: 2021-04-28T17:36:23+03:00
New Revision: e57cf128b30a88c6dd42e8ef40deeedd0d7f116d

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

LOG: [SimplifyCFG] Sinking indirect calls - they're already indirect anyways

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 16e69c0b0d0e..207aacbad93e 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1748,11 +1748,10 @@ static bool canSinkInstructions(
           !canReplaceOperandWithVariable(I0, OI))
         // We can't create a PHI from this GEP.
         return false;
-      // Don't create indirect calls! The called value is the final operand.
-      if (isa<CallBase>(I0) && OI == OE - 1) {
-        // FIXME: if the call was *already* indirect, we should do this.
+      // Don't *create* indirect calls! The called value is the final operand.
+      auto *CB = dyn_cast<CallBase>(I0);
+      if (CB && OI == OE - 1 && !CB->isIndirectCall())
         return false;
-      }
       for (auto *I : Insts)
         PHIOperands[I].push_back(I->getOperand(OI));
     }

diff  --git a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
index 917d1ab89eea..24f11b85bec5 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
@@ -1383,14 +1383,9 @@ if.end:
 
 define void @indirect_caller(i1 %c, i32 %v, void (i32)* %foo, void (i32)* %bar) {
 ; CHECK-LABEL: @indirect_caller(
-; CHECK-NEXT:    br i1 [[C:%.*]], label [[CALL_FOO:%.*]], label [[CALL_BAR:%.*]]
-; CHECK:       call_foo:
-; CHECK-NEXT:    tail call void [[FOO:%.*]](i32 [[V:%.*]])
-; CHECK-NEXT:    br label [[END:%.*]]
-; CHECK:       call_bar:
-; CHECK-NEXT:    tail call void [[BAR:%.*]](i32 [[V]])
-; CHECK-NEXT:    br label [[END]]
-; CHECK:       end:
+; CHECK-NEXT:  end:
+; CHECK-NEXT:    [[BAR_SINK:%.*]] = select i1 [[C:%.*]], void (i32)* [[FOO:%.*]], void (i32)* [[BAR:%.*]]
+; CHECK-NEXT:    tail call void [[BAR_SINK]](i32 [[V:%.*]])
 ; CHECK-NEXT:    ret void
 ;
   br i1 %c, label %call_foo, label %call_bar


        


More information about the llvm-commits mailing list