Changes

Summary

  1. Revert D106195 "[dfsan] Add wrappers for v*printf functions" (details)
  2. [InstCombine] Add freezeAllUsesOfArgument to visitFreeze (details)
  3. [llvm] Inline getAssociatedFunction() in LLVM_DEBUG. (details)
  4. [x86] add more tests for add with CMOV of constants; NFC (details)
  5. [DAG] Add initial SelectionDAG::isGuaranteedNotToBeUndefOrPoison framework (PR51129) (details)
  6. [clang][patch] Remove test artifact before running test for consistent results (details)
  7. [mlir] ConversionTarget legality callbacks refactoring (details)
  8. [lld][WebAssembly] Align __heap_base (details)
  9. [AVR] Do not chain stores in call frame setup (details)
  10. [AVR] Set R31R30 as clobbered after ADJCALLSTACKDOWN (details)
  11. [AVR] Improve 8/16 bit atomic operations (details)
  12. [AVR] Expand large shifts early in IR (details)
  13. [AVR] Fix rotate instructions (details)
  14. [AVR] Only support sp, r0 and r1 in llvm.read_register (details)
  15. [gn build] Port 6aa9e746ebde (details)
  16. [CGP] despeculateCountZeros - Don't create is-zero branch if cttz/ctlz source is known non-zero (details)
  17. [SVE][NFC] Cleanup fixed length code gen tests to make them more resilient. (details)
Commit 228bea6a36cd0eb3b7f80d18bce9f8d5a1a69c95 by gbalats
Revert D106195 "[dfsan] Add wrappers for v*printf functions"

This reverts commit bf281f364757d6af8d9d8456f26d334d1eeaf575.

This commit causes dfsan to segfault.
The file was modifiedcompiler-rt/lib/dfsan/done_abilist.txt
The file was modifiedcompiler-rt/test/dfsan/custom.cpp
The file was modifiedcompiler-rt/lib/dfsan/dfsan_custom.cpp
Commit aca5aeb7523d7868a4b0706330dcdfc58c0adaed by gusrb406
[InstCombine] Add freezeAllUsesOfArgument to visitFreeze

In D106041, a freeze was added before the branch condition to solve the miscompilation problem of SimpleLoopUnswitch.
However, I found that the added freeze disturbed other optimizations in the following situations.
```
arg.fr = freeze(arg)
use(arg.fr)
...
use(arg)
```
It is a problem that occurred when arg and arg.fr were recognized as different values.
Therefore, changing to use arg.fr instead of arg throughout the function eliminates the above problem.
Thus, I add a function that changes all uses of arg to freeze(arg) to visitFreeze of InstCombine.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D106233
The file was modifiedllvm/test/Transforms/InstCombine/freeze.ll
The file was modifiedllvm/test/Transforms/PhaseOrdering/X86/vector-reductions-logical.ll
The file was modifiedllvm/lib/Transforms/InstCombine/InstructionCombining.cpp
The file was modifiedllvm/lib/Transforms/InstCombine/InstCombineInternal.h
Commit edb05d555e6a121fc853fbb000b73570af0ea197 by pifon
[llvm] Inline getAssociatedFunction() in LLVM_DEBUG.

Function* F is used only inside LLVM_DEBUG, so that it causes unused
variable warning.
The file was modifiedllvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
Commit 937e7c60c8775110dd7e6572b406ef7ce770493e by spatel
[x86] add more tests for add with CMOV of constants; NFC

See D106607 / https://llvm.org/PR51069 for details.
The file was modifiedllvm/test/CodeGen/X86/add-cmov.ll
Commit c261a06b7a98549ab7be858337bb80c9259c2be8 by llvm-dev
[DAG] Add initial SelectionDAG::isGuaranteedNotToBeUndefOrPoison framework (PR51129)

I've setup the basic framework for the isGuaranteedNotToBeUndefOrPoison call and updated DAGCombiner::visitFREEZE to use it, further Opcodes can be handled when we have test coverage.

I'm not aware of any vector test freeze coverage so the DemandedElts (and the Depth) args are not being used yet - but they are in place.

SelectionDAG::isGuaranteedNotToBePoison wrappers have also been added.

Differential Revision: https://reviews.llvm.org/D106668
The file was modifiedllvm/include/llvm/CodeGen/SelectionDAG.h
The file was modifiedllvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
The file was modifiedllvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
The file was modifiedllvm/include/llvm/CodeGen/TargetLowering.h
The file was modifiedllvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Commit 05ae3035554aab083ea1ba721284c950cf25d158 by melanie.blower
[clang][patch] Remove test artifact before running test for consistent results

Fix non-deterministic test behavior by removing previously-created
test directory, see comments in D95159
The file was modifiedclang/test/Index/preamble-reparse-changed-module.m
Commit b7a464989955e6374b39b518e317b59b510d4dc5 by ivan.butygin
[mlir] ConversionTarget legality callbacks refactoring

* Get rid of Optional<std::function> as std::function already have a null state
* Add private setLegalityCallback function to set legality callback for unknown ops
* Get rid of unknownOpsDynamicallyLegal flag, use unknownLegalityFn state insted. This causes behavior change when user first calls markUnknownOpDynamicallyLegal with callback and then without but I am not sure is the original behavior was really a 'feature', or just oversignt in the original implementation.

Differential Revision: https://reviews.llvm.org/D105496
The file was modifiedmlir/lib/Transforms/Utils/DialectConversion.cpp
The file was modifiedmlir/include/mlir/Transforms/DialectConversion.h
Commit 13ca0c87edd026813ef7cbf3fbeb0efdb9c8bd3c by aykevanlaethem
[lld][WebAssembly] Align __heap_base

__heap_base was not aligned. In practice, it will often be aligned
simply because it follows the stack, but when the stack is placed at the
beginning (with the --stack-first option), the __heap_base might be
unaligned. It could even be byte-aligned.

At least wasi-libc appears to expect that __heap_base is aligned:
https://github.com/WebAssembly/wasi-libc/blob/659ff414560721b1660a19685110e484a081c3d4/dlmalloc/src/malloc.c#L5224

While WebAssembly itself does not appear to require any alignment for
memory accesses, it is sometimes required when sharing a pointer
externally. For example, WASI might expect alignment up to 8:
https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#-timestamp-u64

This issue got introduced with the addition of the --stack-first flag:
https://reviews.llvm.org/D46141
I suspect the lack of alignment wasn't intentional here.

Differential Revision: https://reviews.llvm.org/D106499
The file was addedlld/test/wasm/Inputs/stack-first.s
The file was modifiedlld/wasm/Writer.cpp
The file was modifiedlld/test/wasm/stack-first.test
Commit feda08b70a9bbb55bbdd1b85a83d29f3ed41cf08 by aykevanlaethem
[AVR] Do not chain stores in call frame setup

Previously, AVRTargetLowering::LowerCall attempted to keep stack stores
in order with chains. Perhaps this worked in the past, but it does not
work now: it appears that the SelectionDAG legalization phase removes
these chains. Therefore, I've removed these chains entirely to match
X86 (which, similar to AVR, also prefers to use push instructions over
stack-relative stores to set up a call frame). With this change, all the
stack stores are in a somewhat reasonable order.

Differential Revision: https://reviews.llvm.org/D97853
The file was modifiedllvm/test/CodeGen/AVR/varargs.ll
The file was modifiedllvm/lib/Target/AVR/AVRISelLowering.cpp
The file was modifiedllvm/test/CodeGen/AVR/call.ll
The file was modifiedllvm/test/CodeGen/AVR/dynalloca.ll
Commit 8544ce80f881a33a2c4c8e234709d136b52fa4d8 by aykevanlaethem
[AVR] Set R31R30 as clobbered after ADJCALLSTACKDOWN

In most cases, using R31R30 is fine because the call (which always
precedes ADJCALLSTACKDOWN) will clobber R31R30 anyway. However, in some
rare cases the register allocator might insert an instruction between
the call and the ADJCALLSTACKDOWN instruction and expect the register
pair to be live afterwards. I think this happens as a result of
rematerialization. Therefore, to fix this, the instruction needs to have
Defs set to R31R30.

Setting the Defs field does have the effect of making the instruction
look dead, which it certainly is not. This is fixed by setting
hasSideEffects to true.

Differential Revision: https://reviews.llvm.org/D97745
The file was modifiedllvm/lib/Target/AVR/AVRInstrInfo.td
Commit 431a9414655ba4825a46e6765ef50a0b4ef7e101 by aykevanlaethem
[AVR] Improve 8/16 bit atomic operations

There were some serious issues with atomic operations. This patch should
fix the biggest issues.

For details on the issue take a look at this Compiler Explorer sample:
https://godbolt.org/z/n3ndhn

Code:

    void atomicadd(_Atomic char *val) {
        *val += 5;
    }

Output:

    atomicadd:
        movw    r26, r24
        ldi     r24, 5     ; 'operand' register
        in      r0, 63
        cli
        ld      r24, X     ; load value
        add     r24, r26   ; value += X
        st      X, r24     ; store value back
        out     63, r0
        ret                ; return the wrong value (in r24)

There are various problems with this.

- The value to add (5) is stored in r24. However, the value to add to
   is loaded in the same register: r24.
- The `add` instruction adds half of the pointer to the loaded value,
   instead of (attempting to) add the operand with value 5.
- The output value of the cmpxchg instruction (which is not used in
   this code sample) is the new value with 5 added, not the old value.
   The LangRef specifies that it has to be the old value, before the
   operation.

This patch fixes the first two and leaves the third problem to be fixed
at a later date. I believe atomics were mostly broken before this patch,
with this patch they should become usable as long as you ignore the
output of the atomic operation. In particular it fixes the following
things:

- It sets the earlyclobber flag for the input ('$operand' operand) so
   that the register allocator puts it in a different register than the
   output value.
- It fixes a number of issues with the pseudo op expansion pass, for
   example now it adds the $operand field instead of the pointer. This
   fixes most machine instruction verifier issues (other flagged issues
   are unrelated to atomics).

Differential Revision: https://reviews.llvm.org/D97127
The file was modifiedllvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
The file was modifiedllvm/lib/Target/AVR/AVRInstrInfo.td
Commit 6aa9e746ebde6efd2479fa833d2d816d0a7bb353 by aykevanlaethem
[AVR] Expand large shifts early in IR

This patch makes sure shift instructions such as this one:

    %result = shl i32 %n, %amount

are expanded just before the IR to SelectionDAG conversion to a loop so
that calls to non-existing library functions such as __ashlsi3 are
avoided. The generated code is currently pretty bad but there's a lot of
room for improvement: the shift itself can be done in just four
instructions.

Differential Revision: https://reviews.llvm.org/D96677
The file was modifiedllvm/lib/Target/AVR/AVRTargetMachine.cpp
The file was addedllvm/lib/Target/AVR/AVRShiftExpand.cpp
The file was modifiedllvm/lib/Target/AVR/AVR.h
The file was modifiedllvm/lib/Target/AVR/CMakeLists.txt
The file was addedllvm/test/CodeGen/AVR/shift-expand.ll
Commit 41f905b211fc904d10f819618dcb62f90ba82c45 by aykevanlaethem
[AVR] Fix rotate instructions

This patch fixes some issues with the RORB pseudo instruction.

  - A minor issue in which the instructions were said to use the SREG,
    which is not true.
  - An issue with the BLD instruction, which did not have an output operand.
  - A major issue in which invalid instructions were generated. The fix
    also reduce RORB from 4 to 3 instructions, so it's also a small
    optimization.

These issues were flagged by the machine verifier.

Differential Revision: https://reviews.llvm.org/D96957
The file was modifiedllvm/lib/Target/AVR/AVRInstrInfo.td
The file was modifiedllvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
The file was modifiedllvm/test/CodeGen/AVR/rot.ll
Commit 4d7f5c0a85cde0c144a424059e53079230ec2ea2 by aykevanlaethem
[AVR] Only support sp, r0 and r1 in llvm.read_register

Most other registers are allocatable and therefore cannot be used.

This issue was flagged by the machine verifier, because reading other
registers is considered reading from an undefined register.

Differential Revision: https://reviews.llvm.org/D96969
The file was addedllvm/test/CodeGen/AVR/intrinsics/named-reg-alloc.ll
The file was modifiedllvm/lib/Target/AVR/AVRISelLowering.cpp
The file was removedllvm/test/CodeGen/AVR/intrinsics/read_register.ll
The file was addedllvm/test/CodeGen/AVR/intrinsics/named-reg-special.ll
Commit fcb3bb581bdd94e001edfd33eeff2caa609c0f1b by llvmgnsyncbot
[gn build] Port 6aa9e746ebde
The file was modifiedllvm/utils/gn/secondary/llvm/lib/Target/AVR/BUILD.gn
Commit 478b22d95aee2b818008a7b92b8606175767d0de by llvm-dev
[CGP] despeculateCountZeros - Don't create is-zero branch if cttz/ctlz source is known non-zero

If value tracking can confirm that the cttz/ctlz source is known non-zero then we don't need to create a branch (which DAG will struggle to recover from).

Differential Revision: https://reviews.llvm.org/D106685
The file was modifiedllvm/test/CodeGen/X86/clz.ll
The file was modifiedllvm/lib/CodeGen/CodeGenPrepare.cpp
Commit e697a542cab39360a578adbf32e0d853a444804c by paul.walker
[SVE][NFC] Cleanup fixed length code gen tests to make them more resilient.

Many of the tests have used NEXT when DAG is more approprite. In
some cases single DAG lines have been used. Note that these are
manual tests because they're to complex for update_llc_test_checks.py
and so it's worth not relying too much on the ordered output.

I've also made the CHECK lines more uniform when it comes to the
ordering of things like LO/HI.
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-fp-extend-trunc.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-masked-gather.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-fp-to-int.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-int-to-fp.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-vector-shuffle.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-masked-scatter.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-trunc-stores.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-fp-rounding.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-fp-reduce.ll
The file was modifiedllvm/test/CodeGen/AArch64/sve-fixed-length-int-extends.ll