[all-commits] [llvm/llvm-project] 38f44c: Recommit: [FuncSpec] Fix specialisation based on l...

Momchil Velikov via All-commits all-commits at lists.llvm.org
Thu Oct 27 04:51:03 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 38f44ccfba22ccdf5b06c58b5fdbb619bc891fee
      https://github.com/llvm/llvm-project/commit/38f44ccfba22ccdf5b06c58b5fdbb619bc891fee
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2022-10-27 (Thu, 27 Oct 2022)

  Changed paths:
    M llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
    A llvm/test/Transforms/FunctionSpecialization/literal-const.ll

  Log Message:
  -----------
  Recommit: [FuncSpec] Fix specialisation based on literals

[fixed test to work with reverse iteration]

The `FunctionSpecialization` pass has support for specialising
functions, which are called with literal arguments. This functionality
is disabled by default and is enabled with the option
`-function-specialization-for-literal-constant` .  There are a few
issues with the implementation, though:

* even with the default, the pass will still specialise based on
   floating-point literals

* even when it's enabled, the pass will specialise only for the `i1`
    type (or `i2` if all of the possible 4 values occur, or `i3` if all
    of the possible 8 values occur, etc)

The reason for this is incorrect check of the lattice value of the
function formal parameter. The lattice value is `overdefined` when the
constant range of the possible arguments is the full set, and this is
the reason for the specialisation to trigger. However, if the set of
the possible arguments is not the full set, that must not prevent the
specialisation.

This patch changes the pass to NOT consider a formal parameter when
specialising a function if the lattice value for that parameter is:

* unknown or undef
* a constant
* a constant range with a single element

on the basis that specialisation is pointless for those cases.

Is also changes the criteria for picking up an actual argument to
specialise if the argument is:

* a LLVM IR constant
* has `constant` lattice value
 has `constantrange` lattice value with a single element.

Reviewed By: ChuanqiXu

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

Change-Id: Iea273423176082ec51339aa66a5fe9fea83557ee




More information about the All-commits mailing list