[all-commits] [llvm/llvm-project] 9186df: [InlineCost] Simplify extractvalue across callsite...

Tobias Stadler via All-commits all-commits at lists.llvm.org
Tue Jun 24 06:15:49 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9186df9b088f425182c58c7eee23645a77d7591c
      https://github.com/llvm/llvm-project/commit/9186df9b088f425182c58c7eee23645a77d7591c
  Author: Tobias Stadler <mail at stadler-tobias.de>
  Date:   2025-06-24 (Tue, 24 Jun 2025)

  Changed paths:
    M llvm/lib/Analysis/InlineCost.cpp
    A llvm/test/Transforms/Inline/simplify-crosscallsite.ll

  Log Message:
  -----------
  [InlineCost] Simplify extractvalue across callsite (#145054)

Motivation: When using libc++, `std::bitset<64>::count()` doesn't
optimize to a single popcount instruction on AArch64, because we fail to
inline the library code completely. Inlining fails, because the internal
bit_iterator struct is passed as a [2 x i64] %arg value on AArch64. The
value is built using insertvalue instructions and only one of the array
entries is constant. If we know that this entry is constant, we can
prove that half the function becomes dead. However, InlineCost only
considers operands for simplification if they are Constants, which %arg
is not. Without this simplification the function is too expensive to
inline.

Therefore, we had to teach InlineCost to support non-Constant simplified values
(PR #145083). Now, we enable this for extractvalue, because we want to simplify
the extractvalue with the insertvalues from the caller function. This is enough to
get bitset::count fully optimized.

There are similar opportunities we can explore for BinOps in the future
(e.g. cmp eq %arg1, %arg2 when the caller passes the same value into
both arguments), but we need to be careful here, because InstSimplify
isn't completely safe to use with operands owned by different functions.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list