SuccessChanges

Summary

  1. [FuncSpec] Support specialising recursive functions (details)
  2. [libc] Fix Memory Benchmarks code after rename (details)
  3. Introduce intrinsic llvm.isnan (details)
  4. X86: fix frame offset calculation with mandatory tail calls (details)
  5. [lldb] Partly revert "Allow range-based for loops over DWARFDIE's children" (details)
  6. [llvm][ExecutionEngine] Don't try to run tests on ARM64/Windows on Arm (details)
  7. [lldb] Fix lookup of .debug_loclists with split-dwarf (details)
  8. [X86] Split Subtarget ISA / Security / Tuning Feature Flags Definitions. NFC (details)
  9. Revert "Introduce intrinsic llvm.isnan" (details)
Commit 30fbb06979077740961ebc46853e28ab1f999f9d by sjoerd.meijer
[FuncSpec] Support specialising recursive functions

This adds support for specialising recursive functions. For example:

    int Global = 1;
    void recursiveFunc(int *arg) {
      if (*arg < 4) {
        print(*arg);
        recursiveFunc(*arg + 1);
      }
    }
    void main() {
      recursiveFunc(&Global);
    }

After 3 iterations of function specialisation, followed by inlining of the
specialised versions of recursiveFunc, the main function looks like this:

    void main() {
      print(1);
      print(2);
      print(3);
    }

To support this, the following has been added:
- Update the solver and state of the new specialised functions,
- An optimisation to propagate constant stack values after each iteration of
  function specialisation, which is necessary for the next iteration to
  recognise the constant values and trigger.

Specialising recursive functions is (at the moment) controlled by option
-func-specialization-max-iters and is opt-in for compile-time reasons. I.e.,
the default is -func-specialization-max-iters=1, but for the example above we
would need to use -func-specialization-max-iters=3. Future work is to see if we
can increase the default, or improve the cost-model/heuristics to control
compile-times.

Differential Revision: https://reviews.llvm.org/D106426
The file was addedllvm/test/Transforms/FunctionSpecialization/function-specialization-recursive2.ll
The file was modifiedllvm/test/Transforms/FunctionSpecialization/function-specialization-recursive.ll
The file was addedllvm/test/Transforms/FunctionSpecialization/function-specialization-recursive4.ll
The file was modifiedllvm/lib/Transforms/IPO/FunctionSpecialization.cpp
The file was addedllvm/test/Transforms/FunctionSpecialization/function-specialization-recursive3.ll
Commit 2f002817fb462d01d26374015421a24fa2a5a676 by andre.simoesdiasvieira
[libc] Fix Memory Benchmarks code after rename

Differential Revision: https://reviews.llvm.org/D107376
The file was modifiedlibc/benchmarks/LibcMemoryBenchmarkMain.cpp
Commit 16ff91ebccda1128c43ff3cee104e2c603569fb2 by sepavloff
Introduce intrinsic llvm.isnan

Clang has builtin function '__builtin_isnan', which implements C
library function 'isnan'. This function now is implemented entirely in
clang codegen, which expands the function into set of IR operations.
There are three mechanisms by which the expansion can be made.

* The most common mechanism is using an unordered comparison made by
  instruction 'fcmp uno'. This simple solution is target-independent
  and works well in most cases. It however is not suitable if floating
  point exceptions are tracked. Corresponding IEEE 754 operation and C
  function must never raise FP exception, even if the argument is a
  signaling NaN. Compare instructions usually does not have such
  property, they raise 'invalid' exception in such case. So this
  mechanism is unsuitable when exception behavior is strict. In
  particular it could result in unexpected trapping if argument is SNaN.

* Another solution was implemented in https://reviews.llvm.org/D95948.
  It is used in the cases when raising FP exceptions by 'isnan' is not
  allowed. This solution implements 'isnan' using integer operations.
  It solves the problem of exceptions, but offers one solution for all
  targets, however some can do the check in more efficient way.

* Solution implemented by https://reviews.llvm.org/D96568 introduced a
  hook 'clang::TargetCodeGenInfo::testFPKind', which injects target
  specific code into IR. Now only SystemZ implements this hook and it
  generates a call to target specific intrinsic function.

Although these mechanisms allow to implement 'isnan' with enough
efficiency, expanding 'isnan' in clang has drawbacks:

* The operation 'isnan' is hidden behind generic integer operations or
  target-specific intrinsics. It complicates analysis and can prevent
  some optimizations.

* IR can be created by tools other than clang, in this case treatment
  of 'isnan' has to be duplicated in that tool.

Another issue with the current implementation of 'isnan' comes from the
use of options '-ffast-math' or '-fno-honor-nans'. If such option is
specified, 'fcmp uno' may be optimized to 'false'. It is valid
optimization in general, but it results in 'isnan' always returning
'false'. For example, in some libc++ implementations the following code
returns 'false':

    std::isnan(std::numeric_limits<float>::quiet_NaN())

The options '-ffast-math' and '-fno-honor-nans' imply that FP operation
operands are never NaNs. This assumption however should not be applied
to the functions that check FP number properties, including 'isnan'. If
such function returns expected result instead of actually making
checks, it becomes useless in many cases. The option '-ffast-math' is
often used for performance critical code, as it can speed up execution
by the expense of manual treatment of corner cases. If 'isnan' returns
assumed result, a user cannot use it in the manual treatment of NaNs
and has to invent replacements, like making the check using integer
operations. There is a discussion in https://reviews.llvm.org/D18513#387418,
which also expresses the opinion, that limitations imposed by
'-ffast-math' should be applied only to 'math' functions but not to
'tests'.

To overcome these drawbacks, this change introduces a new IR intrinsic
function 'llvm.isnan', which realizes the check as specified by IEEE-754
and C standards in target-agnostic way. During IR transformations it
does not undergo undesirable optimizations. It reaches instruction
selection, where is lowered in target-dependent way. The lowering can
vary depending on options like '-ffast-math' or '-ffp-model' so the
resulting code satisfies requested semantics.

Differential Revision: https://reviews.llvm.org/D104854
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
The file was addedllvm/test/CodeGen/PowerPC/ppc-fpclass.ll
The file was modifiedllvm/lib/CodeGen/TargetLoweringBase.cpp
The file was addedllvm/test/CodeGen/X86/x86-fpclass.ll
The file was addedllvm/test/CodeGen/AArch64/aarch64-fpclass.ll
The file was addedllvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll
The file was modifiedclang/test/CodeGen/X86/strictfp_builtins.c
The file was modifiedclang/test/CodeGen/aarch64-strictfp-builtins.c
The file was modifiedllvm/include/llvm/CodeGen/TargetLowering.h
The file was modifiedllvm/lib/Analysis/ConstantFolding.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
The file was modifiedllvm/include/llvm/IR/Intrinsics.td
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
The file was modifiedclang/lib/CodeGen/CGBuiltin.cpp
The file was modifiedllvm/include/llvm/CodeGen/ISDOpcodes.h
The file was modifiedllvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
The file was modifiedclang/test/CodeGen/strictfp_builtins.c
The file was modifiedllvm/docs/LangRef.rst
The file was modifiedllvm/lib/Target/X86/X86ISelLowering.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
The file was addedllvm/test/Transforms/InstCombine/fpclass.ll
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Commit d7b0e5525a4e809cf61a4e1c82f000af781cbab4 by Tim Northover
X86: fix frame offset calculation with mandatory tail calls

If there's a region of the stack reserved for potential tail call arguments
(only the case when we guarantee tail calls will be honoured), this is right
next to the incoming stored return address, not necessarily next to the
callee-saved area, so combining the two into a single figure leads to incorrect
offsets in some edge cases.
The file was modifiedllvm/lib/Target/X86/X86FrameLowering.cpp
Commit e4977f9cb58ff7820d0287ba309490af57787749 by Raphael Isemann
[lldb] Partly revert "Allow range-based for loops over DWARFDIE's children"

As pointed out in D107434 by Walter, D103172 also changed two for loops that
were actually not just iterating over some DIEs but also using the iteration
variable later on for some other things. This patch reverts the respective
faulty parts of D103172.
The file was modifiedlldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Commit b1802d694c1cce753d4e54b5924c68c7621d9dc7 by david.spickett
[llvm][ExecutionEngine] Don't try to run tests on ARM64/Windows on Arm

We use CMAKE_SYSTEM_PROCESSOR to set the host_arch lit feature.
This is going to be the same value as CMAKE_HOST_SYSTEM_PROCESSOR,
which on windows is set to the value of the PROCESSOR_ARCHITECTURE
environment variable.

https://cmake.org/cmake/help/latest/variable/CMAKE_HOST_SYSTEM_PROCESSOR.html#cmake-host-system-processor

On Windows on Arm this is "ARM64", not "AArch64" as we currently
look for.

https://docs.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details#environment-variables

Add ARM64 to the unsupported list.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107361
The file was modifiedllvm/test/ExecutionEngine/lit.local.cfg
Commit 0092dbcd80f208f7becec002e70bad5b35a081cd by kimanh
[lldb] Fix lookup of .debug_loclists with split-dwarf

This patch fixes the lookup of locations in
.debug_loclists, if they are split in a .dwp file.

Mainly, we need to consider the cu index offsets.

Reviewed By: jankratochvil

Differential Revision: https://reviews.llvm.org/D107161
The file was modifiedlldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
The file was addedlldb/test/Shell/SymbolFile/DWARF/x86/debug_loclists-dwp.s
Commit fc8dee1ebb9e3a660b18330888edad95ce893422 by llvm-dev
[X86] Split Subtarget ISA / Security / Tuning Feature Flags Definitions. NFC

Our list of slow/fast tuning feature flags has become pretty extensive and is randomly interleaved with ISA and Security (Retpoline etc.) flags, not even based on when the ISAs/flags were introduced, making it tricky to locate them. Plus we started treating tuning flags separately some time ago, so this patch tries to group the flags to match.

I've left them mostly in the same order within each group - I'm happy to rearrange them further if there are specific ISA or Tuning flags that you think should be kept closer together.

Differential Revision: https://reviews.llvm.org/D107370
The file was modifiedllvm/lib/Target/X86/X86.td
Commit 0c28a7c990c5218d6aec47c5052a51cba686ec5e by sepavloff
Revert "Introduce intrinsic llvm.isnan"

This reverts commit 16ff91ebccda1128c43ff3cee104e2c603569fb2.
Several errors were reported mainly test-suite execution time. Reverted
for investigation.
The file was modifiedllvm/lib/CodeGen/TargetLoweringBase.cpp
The file was removedllvm/test/CodeGen/AArch64/aarch64-fpclass.ll
The file was modifiedllvm/docs/LangRef.rst
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
The file was modifiedllvm/include/llvm/IR/Intrinsics.td
The file was modifiedclang/test/CodeGen/X86/strictfp_builtins.c
The file was modifiedllvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
The file was modifiedclang/lib/CodeGen/CGBuiltin.cpp
The file was removedllvm/test/CodeGen/X86/x86-fpclass.ll
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
The file was modifiedclang/test/CodeGen/strictfp_builtins.c
The file was modifiedllvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
The file was modifiedllvm/include/llvm/CodeGen/ISDOpcodes.h
The file was modifiedllvm/lib/Analysis/ConstantFolding.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
The file was modifiedllvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
The file was removedllvm/test/CodeGen/PowerPC/ppc-fpclass.ll
The file was modifiedllvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
The file was modifiedllvm/lib/Target/X86/X86ISelLowering.cpp
The file was modifiedclang/test/CodeGen/aarch64-strictfp-builtins.c
The file was modifiedllvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
The file was removedllvm/test/Transforms/InstCombine/fpclass.ll
The file was removedllvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll
The file was modifiedllvm/include/llvm/CodeGen/TargetLowering.h