[all-commits] [llvm/llvm-project] 4fa971: [FunctionAttrs] Propagate some func/arg/ret attrib...

goldsteinn via All-commits all-commits at lists.llvm.org
Mon Jun 12 22:51:57 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4fa971ff62c3c48c606b792c572c03bd4d5906ee
      https://github.com/llvm/llvm-project/commit/4fa971ff62c3c48c606b792c572c03bd4d5906ee
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-06-13 (Tue, 13 Jun 2023)

  Changed paths:
    M clang/test/CodeGen/LoongArch/inline-asm-constraints.c
    M clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c
    M clang/test/CodeGen/LoongArch/intrinsic-la32.c
    M clang/test/CodeGen/LoongArch/intrinsic-la64.c
    M clang/test/CodeGen/PowerPC/builtins-ppc-build-pair-mma.c
    M clang/test/CodeGen/PowerPC/builtins-ppc-pair-mma.c
    M clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReseve-StoreCond-64bit-only.c
    M clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReseve-StoreCond.c
    M clang/test/CodeGen/PowerPC/ppc64-inline-asm.c
    M clang/test/CodeGen/RISCV/riscv-inline-asm.c
    M clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vwrite-csr.c
    M clang/test/CodeGen/X86/fma-builtins-constrained.c
    M clang/test/CodeGen/X86/ms-x86-intrinsics.c
    M clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
    M clang/test/CodeGen/aarch64-ls64-inline-asm.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1sb.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1sh.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1sw.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1ub.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1uh.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_ldnt1uw.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_stnt1.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_stnt1b.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_stnt1h.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_stnt1w.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilege.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilegt.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
    M clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr.c
    M clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
    M clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_get_neonq.c
    M clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
    M clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
    M clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c
    M clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c
    M clang/test/CodeGen/msp430-builtins.c
    M clang/test/CodeGen/nofpclass.c
    M clang/test/Headers/wasm.c
    A llvm/include/llvm/Transforms/Utils/InferCallsiteAttrs.h
    M llvm/lib/Transforms/IPO/FunctionAttrs.cpp
    M llvm/lib/Transforms/Utils/CMakeLists.txt
    A llvm/lib/Transforms/Utils/InferCallsiteAttrs.cpp
    M llvm/test/Other/cgscc-devirt-iteration.ll
    M llvm/test/Transforms/FunctionAttrs/nonnull.ll
    M llvm/test/Transforms/FunctionAttrs/readattrs.ll
    M llvm/test/Transforms/FunctionAttrs/willreturn-callsites.ll
    M llvm/test/Transforms/MergeFunc/mergefunc-preserve-debug-info.ll
    M llvm/test/Transforms/PhaseOrdering/X86/loop-idiom-vs-indvars.ll
    M llvm/test/Transforms/PhaseOrdering/memset-tail.ll

  Log Message:
  -----------
  [FunctionAttrs] Propagate some func/arg/ret attributes from caller to callsite (WIP)

This is the consolidation of D151644 and D151943 moved from
InstCombine to FunctionAttrs. This is based on discussion in the above
patches as well as D152081 (Attributor). This patch was written in a
way so it can have an immediate impact in currently active passes
(FunctionAttrs), but should be easy to port elsewhere (Attributor or
Inliner) if that makes more sense later on.

Some function attributes imply the attribute for all/some instructions
in the function. These attributes can be safely propagated to
callsites within the function that are missing the attribute. This can
be useful when 1) analyzing individual instructions in a function
and 2) if the original caller is later inlined, as if the attributes are
not propagated, they will be lost.

This patch implements propagation in a new class/file
`InferCallsiteAttrs` which can hypothetically be included elsewhere.

At the moment this patch infers the following:

Function Attributes:
    - mustprogress
    - nofree
    - willreturn
    - All memory attributes (readnone, readonly, writeonly, argmem,
      etc...)
        - The memory attributes are only propagated IFF the set of
          pointers available to the callsite is the same as the set
          available outside the caller (i.e no local memory arguments
          from alloca or local malloc like functions).

Argument Attributes:
    - noundef
    - nonnull
    - nofree
    - readnone
    - readonly
    - writeonly
    - nocapture
        - nocapture is only propagated IFF the set of pointers
          available to the callsite is the same as the set available
          outside the caller and its guranteed that between the
          callsite and function return, the state of any capture
          pointers will not change (so the nocaptured gurantee of the
          caller has been met by the instruction preceding the
          callsite and will not changed).

Argument are only propagated to callsite arguments that are also function
arguments, but not derived values.

Return Attributes:
    - noundef
    - nonnull

Return attributes are only propagated if the callsite's return value
is used as the caller's return and execution is guranteed to pass from
callsite to return.

The compile time hit of this for -O3 and -O3+thinLTO is ~[.02, .37]%
regression. Proper LTO, however, has more significant regressions (up
to 3.92%):
https://llvm-compile-time-tracker.com/compare.php?from=94407e1bba9807193afde61c56b6125c0fc0b1d1&to=79feb6e78b818e33ec69abdc58c5f713d691554f&stat=instructions:u

Differential Revision: https://reviews.llvm.org/D152226


  Commit: b76bd2db65b4890f1ec494fa95286533dd6b09e5
      https://github.com/llvm/llvm-project/commit/b76bd2db65b4890f1ec494fa95286533dd6b09e5
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-06-13 (Tue, 13 Jun 2023)

  Changed paths:
    M llvm/include/llvm/Transforms/Utils/InferCallsiteAttrs.h

  Log Message:
  -----------
  100 checks


Compare: https://github.com/llvm/llvm-project/compare/5e691a1c9b0a...b76bd2db65b4


More information about the All-commits mailing list