[PATCH] D77600: [CallSite Removal] a CallBase is never an IndirectCall for isInlineAsm

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 15:49:14 PDT 2020


nickdesaulniers created this revision.
nickdesaulniers added reviewers: void, chandlerc.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nickdesaulniers edited the summary of this revision.
void accepted this revision.
This revision is now accepted and ready to land.
nickdesaulniers planned changes to this revision.
nickdesaulniers updated this revision to Diff 255518.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.
nickdesaulniers marked an inline comment as done.
nickdesaulniers edited the summary of this revision.

- simplify function



================
Comment at: llvm/lib/IR/Instructions.cpp:272
+    return false;
   return true;
 }
----------------
eh, could simplify this more, will do.


Thanks to Bill Wendling (void) for the report and steps to reproduce.  It looks
like this was missed during r350508's cleanup of the CallSite split into
CallBase, CallInst, and CallBrInst.

This was exposed by running pgo on a callbr, which was creating a ptrtoint to
the inline asm thinking it was an indirect call. The relevant callchain looks
like:

  IndirectCallPromotionPlugin::run()
  -> PGOIndirectCallVisitor::findIndirectCalls()
    -> PGOIndirectCallVisitor::visitCallBase()
      -> CallBase::isIndirectCall()


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77600

Files:
  llvm/lib/IR/Instructions.cpp
  llvm/test/Transforms/PGOProfile/callbr.ll


Index: llvm/test/Transforms/PGOProfile/callbr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/callbr.ll
@@ -0,0 +1,17 @@
+; RUN: opt -pgo-instr-gen -S 2>&1 < %s | FileCheck %s
+
+define i32 @a() {
+entry:
+; CHECK-NOT: ptrtoint void (i8*)* asm sideeffect
+; CHECK: callbr void asm sideeffect
+  %retval = alloca i32, align 4
+  callbr void asm sideeffect "", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@a, %b)) #1
+          to label %asm.fallthrough [label %b]
+
+asm.fallthrough:
+  br label %b
+
+b:
+  %0 = load i32, i32* %retval, align 4
+  ret i32 %0
+}
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -265,12 +265,7 @@
 
 bool CallBase::isIndirectCall() const {
   const Value *V = getCalledValue();
-  if (isa<Function>(V) || isa<Constant>(V))
-    return false;
-  if (const CallInst *CI = dyn_cast<CallInst>(this))
-    if (CI->isInlineAsm())
-      return false;
-  return true;
+  return !(isa<Function>(V) || isa<Constant>(V) || isInlineAsm());
 }
 
 /// Tests if this call site must be tail call optimized. Only a CallInst can


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77600.255518.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/e598fd6d/attachment.bin>


More information about the llvm-commits mailing list