[llvm] [Analysis] Use BitVector::test in areInlineCompatible (NFC) (PR #98776)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 13 16:35:16 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/98776

areInlineCompatible checks to see if CalleeTLI.OverrideAsUnavailable
is a subset of OverrideAsUnavailable by computing a union of the two
and comparing the union and OverrideAsUnavailable.

The problem is that computing a union involves memory allocations.
This patch removes the need for memory allocations by switching to
BitVector::test.  Note that A.test(B) returns true if A - B is
non-empty.  That is, !A.test(B) is true if A if a subset of B.

The use of BitVector::test here saves 0.20% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.


>From 72b1a84c15ed2c0aa56afe153fd372e3e24e2581 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 15 Jun 2024 22:17:57 -0700
Subject: [PATCH] [Analysis] Use BitVector::test in areInlineCompatible (NFC)

areInlineCompatible checks to see if CalleeTLI.OverrideAsUnavailable
is a subset of OverrideAsUnavailable by computing a union of the two
and comparing the union and OverrideAsUnavailable.

The problem is that computing a union involves memory allocations.
This patch removes the need for memory allocations by switching to
BitVector::test.  Note that A.test(B) returns true if A - B is
non-empty.  That is, !A.test(B) is true if A if a subset of B.

The use of BitVector::test here saves 0.20% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.
---
 llvm/include/llvm/Analysis/TargetLibraryInfo.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index c98d08fa0888d..db5e80ccdbaab 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -327,11 +327,9 @@ class TargetLibraryInfo {
                            bool AllowCallerSuperset) const {
     if (!AllowCallerSuperset)
       return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
-    BitVector B = OverrideAsUnavailable;
-    B |= CalleeTLI.OverrideAsUnavailable;
-    // We can inline if the union of the caller and callee's nobuiltin
-    // attributes is no stricter than the caller's nobuiltin attributes.
-    return B == OverrideAsUnavailable;
+    // We can inline if the callee's nobuiltin attributes are no stricter than
+    // the caller's.
+    return !CalleeTLI.OverrideAsUnavailable.test(OverrideAsUnavailable);
   }
 
   /// Return true if the function type FTy is valid for the library function



More information about the llvm-commits mailing list