[PATCH] D101180: Mark type test intrinsics as speculatable to fix inline cost

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 10:02:49 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG10b781fb033e: Mark type test intrinsics as speculatable to fix inline cost (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101180/new/

https://reviews.llvm.org/D101180

Files:
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/Transforms/Inline/ephemeral.ll
  llvm/test/Transforms/SimplifyCFG/no-md-sink.ll


Index: llvm/test/Transforms/SimplifyCFG/no-md-sink.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/no-md-sink.ll
+++ llvm/test/Transforms/SimplifyCFG/no-md-sink.ll
@@ -47,6 +47,6 @@
 
 ; CHECK-LABEL: test2
 ; CHECK: %[[S:[a-z0-9.]+]] = select i1 %flag, i8* %y, i8* %z
-; CHECK: %[[R:[a-z0-9.]+]] = call i1 @llvm.type.test(i8* %[[S]], metadata !0)
+; CHECK: %[[R:[a-z0-9.]+]] = call i1 @llvm.type.test(i8* %[[S]], metadata ![[MD:[0-9]+]]
 ; CHECK: ret i1 %[[R]]
-
+; CHECK: ![[MD]] = !{i32 0, !"typeid1"}
Index: llvm/test/Transforms/Inline/ephemeral.ll
===================================================================
--- llvm/test/Transforms/Inline/ephemeral.ll
+++ llvm/test/Transforms/Inline/ephemeral.ll
@@ -1,30 +1,35 @@
-; RUN: opt -S -Oz %s | FileCheck %s
+; RUN: opt -S -inline %s -debug-only=inline-cost 2>&1 | FileCheck %s
+; Only the load and ret should be included in the instruction count, not
+; the instructions feeding the assume.
+; CHECK: NumInstructions: 2
 
 @a = global i32 4
 
-define i32 @inner() {
+define i32 @inner(i8* %y) {
   %a1 = load volatile i32, i32* @a
 
-  ; Here are enough instructions to prevent inlining, but because they are used
-  ; only by the @llvm.assume intrinsic, they're free (and, thus, inlining will
-  ; still happen).
+  ; Because these instructions are used only by the @llvm.assume intrinsic,
+  ; they're free and should not be included in the instruction count when
+  ; computing the inline cost.
   %a2 = mul i32 %a1, %a1
-  %a3 = sub i32 %a1, 5
+  %a3 = sub i32 %a1, %a2
   %a4 = udiv i32 %a3, -13
   %a5 = mul i32 %a4, %a4
   %a6 = add i32 %a5, %a5
   %ca = icmp sgt i32 %a6, -7
-  tail call void @llvm.assume(i1 %ca)
+  %r = call i1 @llvm.type.test(i8* %y, metadata !0)
+  %ca2 = icmp eq i1 %ca, %r
+  tail call void @llvm.assume(i1 %ca2)
 
   ret i32 %a1
 }
 
-; @inner() should be inlined for -Oz.
-; CHECK-NOT: call i1 @inner
-define i32 @outer() optsize {
-   %r = call i32 @inner()
+define i32 @outer(i8* %y) optsize {
+   %r = call i32 @inner(i8* %y)
    ret i32 %r
 }
 
 declare void @llvm.assume(i1) nounwind
+declare i1 @llvm.type.test(i8*, metadata) nounwind readnone
 
+!0 = !{i32 0, !"typeid1"}
Index: llvm/include/llvm/IR/Intrinsics.td
===================================================================
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -1461,7 +1461,7 @@
 
 // Test whether a pointer is associated with a type metadata identifier.
 def int_type_test : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_ptr_ty, llvm_metadata_ty],
-                              [IntrNoMem, IntrWillReturn]>;
+                              [IntrNoMem, IntrWillReturn, IntrSpeculatable]>;
 
 // Safely loads a function pointer from a virtual table pointer using type metadata.
 def int_type_checked_load : DefaultAttrsIntrinsic<[llvm_ptr_ty, llvm_i1_ty],


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101180.340092.patch
Type: text/x-patch
Size: 2912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210423/d18bf0ac/attachment.bin>


More information about the llvm-commits mailing list