[PATCH] D139051: [PGO][indirect-call-promotion] Add extra parameter check for musttail callsite

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 15:26:40 PST 2022


xur created this revision.
xur added reviewers: tejohnson, rnk.
Herald added subscribers: wenlei, hiraditya.
Herald added a project: All.
xur requested review of this revision.
Herald added a project: LLVM.

Add extra parameter type check to musttail callsite to avoid verifier error.


https://reviews.llvm.org/D139051

Files:
  llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
  llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail_typecheck.ll


Index: llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail_typecheck.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/indirect_call_promotion_musttail_typecheck.ll
@@ -0,0 +1,36 @@
+; Mustcall needs stricter parameter type checks otherwise it will fail in verifier.
+
+; RUN: opt < %s -passes=pgo-icall-prom -S | FileCheck %s
+
+define ptr @func(ptr %msg, ptr %ptr, ptr %ctx, i64 %data.coerce, ptr %table, i64 %hasbits) {
+entry:
+  %0 = load ptr, ptr null, align 8
+  ret ptr null
+
+1:
+  %call11.i = musttail call ptr %0(ptr null, ptr null, ptr null, i64 0, ptr null, i64 0), !prof !0
+  ret ptr %call11.i
+}
+
+; CHECK-LABEL: @func
+; CHECK-NOT: {{[0-9]+}} = icmp eq ptr %0, @_ZN6proto28internal12ExtensionSet10ParseFieldEmPKcPKNS_7MessageEPNS0_16InternalMetadataEPNS0_12ParseContextE
+
+define ptr @func2(ptr %msg, i64 %tag, ptr %ctx, ptr %type, ptr %table, ptr %ptr) {
+entry:
+  %0 = load ptr, ptr null, align 8
+  ret ptr null
+
+1:
+  %call11.i = musttail call ptr %0(ptr null, i64 0, ptr null, ptr null, ptr null, ptr null), !prof !0
+  ret ptr %call11.i
+}
+
+; CHECK-LABEL: @func2
+; CHECK: {{[0-9]+}} = icmp eq ptr %0, @_ZN6proto28internal12ExtensionSet10ParseFieldEmPKcPKNS_7MessageEPNS0_16InternalMetadataEPNS0_12ParseContextE
+
+define available_externally ptr @_ZN6proto28internal12ExtensionSet10ParseFieldEmPKcPKNS_7MessageEPNS0_16InternalMetadataEPNS0_12ParseContextE(ptr %this, i64 %tag, ptr %ptr, ptr %containing_type, ptr %metadata, ptr %ctx) {
+entry:
+  ret ptr null
+}
+
+!0 = !{!"VP", i32 0, i64 2024, i64 -4843250054591211088, i64 -1, i64 1456131869974120143, i64 947, i64 -4941069334091589447, i64 18}
Index: llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -434,11 +434,24 @@
     Type *ActualTy = CB.getArgOperand(I)->getType();
     if (FormalTy == ActualTy)
       continue;
+
     if (!CastInst::isBitOrNoopPointerCastable(ActualTy, FormalTy, DL)) {
       if (FailureReason)
         *FailureReason = "Argument type mismatch";
       return false;
     }
+
+    // MustTail call needs stricter type match. See
+    // Verifier::verifyMustTailCall().
+    if (CB.isMustTailCall()) {
+      PointerType *PF = dyn_cast<PointerType>(FormalTy);
+      PointerType *PA = dyn_cast<PointerType>(ActualTy);
+      if (!PF || !PA || PF->getAddressSpace() != PA->getAddressSpace()) {
+        if (FailureReason)
+          *FailureReason = "Musttail call Argument type mismatch";
+        return false;
+      }
+    }
   }
   for (; I < NumArgs; I++) {
     // Vararg functions can have more arguments than parameters.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139051.479083.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221130/12c6f82b/attachment.bin>


More information about the llvm-commits mailing list