53684 Commits

Author SHA1 Message Date
Vyacheslav Levytskyy
163d036d64
[SPIR-V] Validate and fix bit width of scalar registers (#95147)
This PR improves legalization process of SPIR-V instructions. Namely, it
introduces validation and fixing of bit width of scalar registers as a
part of pre-legalizer. A test case is added that demonstrates ability to
legalize instructions with non 8/16/32/64 bit width both with and
without vendor-specific SPIR-V extension
(SPV_INTEL_arbitrary_precision_integers). In the case of absence of the
extension, a generated SPIR-V code will fallback to 8/16/32/64 bit width
in OpTypeInt, but SPIR-V Backend still is able to legalize operations
with original integer sizes.
2024-06-11 21:56:39 +02:00
Vyacheslav Levytskyy
57520985e0
[SPIR-V] Implement insertion of OpGenericCastToPtr using builtin functions (#95055)
This PR implements insertion of OpGenericCastToPtr using builtin
functions (both opencl `to_global|local|private` and `__spirv_`
wrappers), and improves type inference.
2024-06-11 21:23:48 +02:00
Michal Paszkowski
ca63860733
[SPIR-V] Don't change switch condition type in CodeGen opts (#94959)
This change makes sure the preferred switch condition int type size
remains the same throughout CodeGen optimizations.

The change fixes running several OpenCL applications with -O2 or higher
opt levels, and fixes Basic/stream/stream_max_stmt_exceed.cpp DPC++ E2E
test with -O2.
2024-06-11 11:09:21 -07:00
Simon Pilgrim
3f3e85cd23
[X86] ICMP EQ/NE MIN_SIGNED_INT - avoid immediate argument by using NEG + SETO/SETNO (#94948)
For i64 this avoids loading a 64-bit value into register, for smaller registers this just avoids an immediate operand.

For i8+i16, limit to one use case as we save fewer bytes and these can be wasted entirely on extra register moves.

Fixes #67709
2024-06-11 16:38:53 +01:00
Farzon Lotfi
38ccee0034
[WASM] Fix for wasi libc build break add tan to RuntimeLibcallSignatureTable (#95082)
The wasm backend fetches the tan runtime lib call in
`llvm/include/llvm/IR/RuntimeLibcalls.def` via `StaticLibcallNameMap()`,
but ignores the runtime function because a function sinature mapping is
not specified in RuntimeLibcallSignatureTable(). The fix is to specify
the function signatures for float32-128.

This is a fix for a build break reported on PR
https://github.com/llvm/llvm-project/pull/94559#issuecomment-2159923215.
2024-06-11 10:43:51 -04:00
Simon Pilgrim
464eb648fa [X86] SimplifyDemandedBitsForTargetNode - add basic X86ISD::CMOV handling
Add basic pass through handling - we could extend this to truncate CMOVQ to CMOVL in a future patch
2024-06-11 15:17:53 +01:00
Simon Pilgrim
1df37980c2 [X86] early-ifcvt-remarks.ll - use i64 arithmetic to ensure ifcvt doesn't drop below threshold
Upcoming SimplifyDemandedBits support for CMOV will simplify the code and reduce the critical path below the threshold if we stick with i32 multiplies
2024-06-11 15:17:53 +01:00
Simon Pilgrim
a7d28f5a4d [X86] early-ifcvt-remarks.ll - add codegen checks 2024-06-11 14:35:32 +01:00
Paul T Robinson
32add2435f
Fix test to have correct requirements (#95106) 2024-06-11 06:04:09 -07:00
Matt Arsenault
a2bc50aa8b AMDGPU: Add more tests for vector typed atomicrmw fadd
Some cases should be legal for gfx940.
2024-06-11 14:44:28 +02:00
Pierre van Houtryve
d4b8b7217f
[CodeGen][MachineLICM] Use RegUnits in HoistRegionPostRA (#94608)
Those BitVectors get expensive on targets like AMDGPU with thousands of
registers, and RegAliasIterator is also expensive.

We can move all liveness calculations to use RegUnits instead to speed
it up for targets where RegAliasIterator is expensive, like AMDGPU.
On targets where RegAliasIterator is cheap, this alternative can be a little more expensive, but I believe the tradeoff is worth it.
2024-06-11 14:27:35 +02:00
Nathan Gauër
a141a28c0c
[SPIR-V] Fix flakiness during switch generation. (#95001)
The case-list of the switches generated by this pass were not
"deterministic" (based on allocation patterns).
This is because the CaseList order relied on an unordered_set order.
Using the sorted exit target list for those should solve the problem.

Fixes #94961

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-06-11 13:57:31 +02:00
Paul T Robinson
3f88311124
[Driver] Rearrange some Apple version testing (#94514)
There were four tests in Driver that actually tested bits of Driver and
bits of CodeGen, and therefore had target restrictions. Rework those
four tests into one Driver test (with no target restrictions) and two
target-specific CodeGen tests.
2024-06-11 07:51:21 -04:00
aengelke
214ff5036c
[X86] Add AMXProgModel to YAML serialization (#94988)
This allows tested passes to depend on the AMX model in the function
info. Preparatory work for to adopt #94358 for other AMX passes.
2024-06-11 13:08:55 +02:00
Simon Pilgrim
2ca8c856ee [X86] is_fpclass.ll - add NDD test coverage 2024-06-11 11:23:17 +01:00
Simon Pilgrim
995ba4afcd [CostModel][X86] Adjust ABS scalar SizeLatency cost to 3uops
This was previously set to 4uops which was including the cost of extra register moves in the original test code.
2024-06-11 10:29:18 +01:00
Sander de Smalen
c63a622ba7
[AArch64] Disable red-zone when lowering Q-reg copy through memory. (#94962)
This was pointed out in PR #93940.
2024-06-11 08:58:28 +01:00
Pengcheng Wang
1bebb99324
[RISCV] Add B extension (#76893)
It seems that we have `B` extension again:
https://github.com/riscv/riscv-b

According to the spec, `B` extension represents the collection of
the `Zba`, `Zbb`, `Zbs` extensions.

Though it hasn't been ratified, I set its version to `1.0`.
2024-06-11 14:06:23 +08:00
Mariusz Sikora
0bc33f41ab
[AMDGPU] Update tests for last-use in global/scratch/flat/buffer load… (#94975)
… instructions
2024-06-11 06:30:13 +02:00
Daniil Kovalev
690480f588
[PAC][AArch64] Lower ptrauth constants in data (#94240)
Lower global references to ptrauth constants into `@AUTH` `MCExpr`'s.
The logic is common for MachO and ELF - test both.

---------

Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
2024-06-11 07:28:42 +03:00
Farzon Lotfi
189d471191
[clang] Reland Add tanf16 builtin and support for tan constrained intrinsic (#94559)
Relanding this PR now that
https://github.com/llvm/llvm-project/pull/90503 has merged. with `FTAN`
landing in
[TargetLoweringBase.cpp:L1021](https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1020C23-L1021C63
) There is now a llvm tan intrinsic 32\64\128 Expand case for all llvm
backends.

In LLVM, the `llvm.experimental.constrained.cos` and
`llvm.experimental.constrained.sin` intrinsics are used for performing
cosine and sine calculations with additional constraints on
floating-point operations. This behavior is expected for all
floating-point math intrinsics. This change adds these constraints for
the `tan` intrinsic.

-  `Builtins.td` - replace TanF128 with F16F128MathTemplate
- `CGBuiltin.cpp` - map existing tan builtins to `tan` and
`constrained_tan` intrinsic
-   `ConstrainedOps.def` map tan and constrained_tan  to an ISDOpcode.

resolves  #91421

---------

Co-authored-by: Farzon Lotfi <farzon@farzon.com>
2024-06-10 20:46:26 -04:00
David Green
c7308d405d
[LSR][AArch64] Optimize chain generation based on legal addressing modes (#94453)
LSR will generate chains of related instructions with a known increment
between them. With SVE, in the case of the test case, this can include
increments like 'vscale * 16 + 8'. The idea of this patch is if we have
a '+8' increment already calculated in the chain, we can generate a
(legal) '+ vscale*16' addressing mode from it, allowing us to use the
'[x16, #1, mul vl]' addressing mode instructions.

In order to do this we keep track of the known 'bases' when generating
chains in GenerateIVChain, checking for each if the accumulated
increment expression from the base neatly folds into a legal addressing
mode. If they do not we fall back to the existing LeftOverExpr, whether
it is legal or not.

This is mostly orthogonal to #88124, dealing with the generation of
chains as opposed to rest of LSR. The existing vscale addressing mode
work has greatly helped compared to the last time I looked at this,
allowing us to check that the addressing modes are indeed legal.
2024-06-10 20:35:33 +01:00
David Green
8462e20230
[AArch64] Push mul into extend operands (#94960)
In a similar way to how we push vector adds into extends, this pushed
'mul(zext,zext)' into 'zext(mul(zext,zext))' if the extend can be done
in two or more steps.

https://alive2.llvm.org/ce/z/WjU7Kr
2024-06-10 18:06:48 +01:00
Simon Pilgrim
a8d38c140b [X86] Add abs tests that check for MIN_SIGNED_INT cases
Additional multi-use tests for #94948
2024-06-10 17:59:25 +01:00
Yingwei Zheng
b0822af06d
[GISel][RISCV] Anyextend before copying f16 -> i32/i64 (#94993)
Fixes type check failure in
https://github.com/llvm/llvm-project/pull/94110#issuecomment-2158417937
2024-06-11 00:48:38 +08:00
Jay Foad
58550a7938
[AMDGPU] Restore non-buffer atomic tests lost in #93801 (#94978) 2024-06-10 15:49:18 +01:00
Matt Arsenault
c894f90c58
AMDGPU: Do not assert on v6x16 buffer load intrinsics (#94966)
Just use the original type and let it hit a standard legalization error.
2024-06-10 16:38:06 +02:00
Matt Arsenault
dbc99e9521 AMDGPU: Simplify some tests by not using amdgpu_ps
Since inreg now works for the default calling convention, we can
check the output with fewer argument shuffling instructions.
2024-06-10 16:14:51 +02:00
Matt Arsenault
73d9041254 AMDGPU: Fix using useless cachepolicy argument in buffer atomic test
This was probably intended to test the immediate offset addressing
mode. Add some tests to check immediate offsets, and clean up run lines.
2024-06-10 16:14:51 +02:00
Jay Foad
18ec885a26
[RFC][AMDGPU] Remove old llvm.amdgcn.buffer.* and tbuffer intrinsics (#93801)
They have been superseded by llvm.amdgcn.raw.buffer.* and
llvm.amdgcn.struct.buffer.*.
2024-06-10 12:14:51 +01:00
David Green
fe0dee4df0 [AArch64] Add tests for extending mul. NFC 2024-06-10 11:43:21 +01:00
Jay Foad
317ed770e3 [AMDGPU] Fix typos in GCN-PROMOTE check prefix 2024-06-10 10:24:23 +01:00
Jay Foad
c9fd7b1a54 [AMDGPU] Remove unused checks left over from X86 2024-06-10 10:12:05 +01:00
Paschalis Mpeis
e4790ce209
[TLI] ReplaceWithVecLib: drop Instruction support (#94365)
Refactor the pass to only support `IntrinsicInst` calls.

`ReplaceWithVecLib` used to support instructions, as AArch64 was using
this pass to replace a vectorized frem instruction to the fmod vector
library call (through TLI).

As this replacement is now done by the codegen (#83859), there is no
need for this pass to support instructions.

Additionally, removed 'frem' tests from:
- AArch64/replace-with-veclib-armpl.ll
- AArch64/replace-with-veclib-sleef-scalable.ll
- AArch64/replace-with-veclib-sleef.ll

Such testing is done at codegen level:
- #83859
2024-06-10 08:37:00 +01:00
Andreas Jonson
cc19374afa
[AMDGPU] Swap range metadata to attribute for workitem id. (#94871)
Swap out range metadata to range attribute for calls to be able to
deprecate range metadata on calls in the future.
2024-06-09 10:29:50 -04:00
David Green
a284bdb311 [DAG] Fold fdiv X, c2 -> fmul X, 1/c2 without AllowReciprocal if exact (#93882)
This moves the combine of fdiv by constant to fmul out of an
'if (Options.UnsafeFPMath || Flags.hasAllowReciprocal()' block,
so that it triggers if the divide is exact. An extra check for
Recip.isDenormal() is added as multiple places make reference
to it being unsafe or slow on certain platforms.
2024-06-09 12:28:20 +01:00
Simon Pilgrim
53fecef1ec
[DAG] FoldConstantArithmetic - allow binop folding to work with differing bitcasted constants (#94863)
We currently only constant fold binop(bitcast(c1),bitcast(c2)) if c1 and c2 are both bitcasted and from the same type.

This patch relaxes this assumption to allow the constant build vector to originate from different types (and allow cases where only one operand was bitcasted).

We still ensure we bitcast back to one of the original types if both operand were bitcasted (we assume that if we have a non-bitcasted constant then its legal to keep using that type).
2024-06-09 11:30:05 +01:00
Simon Pilgrim
32b70430c3 [ARM] vector-store.ll - add big-endian test coverage
Based on feedback on #94863
2024-06-09 10:39:43 +01:00
Yingwei Zheng
643e4718af
[RISCV][GISel] Add calling convention support for half (#94110)
This patch adds initial support to the half type on RISC-V.
2024-06-09 03:44:19 +08:00
AtariDreams
bca7864ffe
[X86] Support ATOMIC_LOAD_FP_BINOP_MI for other binops (#87524)
Since we can bitcast and then do the same thing sub does in the table
section above, I figured it was trivial to add fsub, fmul, and fdiv.
2024-06-08 23:01:05 +08:00
Yingwei Zheng
d9507a3e10
[DAGCombine] Fix miscompilation caused by PR94008 (#94850)
The pr description in #94008 mismatches with the code.
> + When VT is smaller than ShiftVT, it is safe to use trunc.
> + When VT is larger than ShiftVT, it is safe to use zext iff
`is_zero_poison` is true (i.e., `opcode == ISD::CTTZ_ZERO_UNDEF`). See
also the counterexample `src_shl_cttz2 -> tgt_shl_cttz2` in the alive2
    proofs.

Closes #94824.
2024-06-08 21:40:57 +08:00
Quentin Colombet
25506f4864
[SDISel][Combine] Constant fold FP16_TO_FP (#94790)
In some case, constant can survive early constant folding optimization
because they are hidden behind several layers of type changes.

E.g., consider the following sequence (extracted from the arm test that
this commit changes):
```
    t2: v1f16 = BUILD_VECTOR ConstantFP:f16<APFloat(0)>
    t4: v1f16 = insert_vector_elt t2, ConstantFP:f16<APFloat(0)>, Constant:i32<0>
  t5: f16 = bitcast t4
t6: f32 = fp_extend t5
```

Because the constant (APFloat(0)) is hidden behind a <1 x ty> type, all
the constant folding that normally happen for scalar nodes when using
`SelectionDAG::getNode` are blocked.

As a result the constant manages to survive as an actual conversion
instruction down to the select phase:
```
t11: f32 = fp16_to_fp Constant:i32<0>
```

With the change in this patch, we try to do constant folding one more
time during dag combine, which in the motivating example result in the
much better sequence:
```
t7: ch = CopyToReg t0, Register:f32 %0, ConstantFP:f32<0.000000e+00>
```

Note: I'm sure we have this problem in a lot of other places. Generally
speaking I believe SDISel is not that good with <1 x ty> compared to
pure scalar. However, I only changed what I could easily test.
2024-06-08 11:31:13 +02:00
Gábor Spaits
28dd55b973
[RISCV][GISel] Do libcall for G_FPTOSI, G_FPTOUI when no D or F support (#94613)
When compiling the following code:
```cpp
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>

int main() {
    int a;
    float f;
    scanf("%d", &a);

    scanf("%f", &f);
    a += (int)f;
    
    return a;
}
``` 
for `-march=rv32ima_zbb` we get a libcall:
```
call    scanf
        lw      a0, -20(s0)
        call    __fixsfsi
        mv      a1, a0
```
When we try to use GlobalISel we get this error:
```
 error in backend: unable to legalize instruction: %9:_(s32) = G_FPTOSI %8:_(s32) (in function: main)
```

(Here is a link to a reproducer in Godblot:
https://godbolt.org/z/f67vEEb41 )

The goal of this PR is to do a libcall for the legalization of
`G_FPTOSI` and `G_FPTOUI` instead of doing a fallback to Selection DAG
to do the same libcall later.
2024-06-07 21:27:49 +02:00
Vyacheslav Levytskyy
9a737109a0
[SPIR-V] Improve type inference, addrspacecast and dependencies between SPIR-V entities and required capability/extensions (#94626)
This PR continues https://github.com/llvm/llvm-project/pull/94467 and
contains fixes in emission of type intrinsics, constant recording and
corresponding test cases:
* type-deduce-global-dup.ll -- fix of integer constant emission on
32-bit platforms and correct type deduction for globals
* type-deduce-simple-for.ll -- fix of GEP translation (there was an
issue previously that led to incorrect translation/broken logic of
for-range implementation)

This PR also:
* fixes a cast between identical storage classes and updates the test
case to include validation run by spirv-val,
* ensures that Bitcast for pointers satisfies the requirement that the
address spaces must match and adds the corresponding test case,
* improve encode in Tablegen and decode in code of dependencies between
SPIR-V entities and required capability/extensions,
* prevent emission of identical OpTypePointer instructions.
2024-06-07 21:12:33 +02:00
David Green
e5648525fd [AArch64] Add patterns for fadd(uzp1(x,y), uzp2(x, y)) -> faddp.
Similar to f7018ba0eeaad8dc3e1917cfb986fc9689d72e85, this adds patterns for
floating point faddp from an fadd and shuffles.
2024-06-07 18:19:32 +01:00
Craig Topper
e9fa6ffaf7
[RISCV] Fold (vXi8 (trunc (vselect (setltu, X, 256), X, (sext (setgt X, 0))))) to vmax+vnclipu. (#94720)
This pattern is an obscured way to express saturating a signed value
into a smaller unsigned value.

If (setltu, X, 256) is true, then the value is already in the desired
range so we can pick X. If it's false, we select (sext (setgt X, 0))
which is 0 for negative values and all ones for positive values. The all
ones value when truncated to the final type will still be all ones like
we want.
2024-06-07 09:57:03 -07:00
Quentin Colombet
0605e984fa
[SDISel][Builder] Fix the instantiation of <1 x bfloat|half> (#94591)
Prior to this change, `SelectionDAGBuilder` was producing `SDNode`s of
the form: `f32 = extract_vector_elt <1 x bfloat|half>, i32 0` when
lowering phis of `<1 x bfloat|half>` and running on a target that
promotes this type to `f32` (like some x86 or AMDGPU targets.)

This construct is invalid since this type of node only allows type
extensions for integer types.
It went unotice because the `extract_vector_elt` node is later broken
down in `bitcast` followed by `bf16_to_fp|fp_extend`. However, when the
argument of the phi is a constant we were crashing because the existing
code would try to constant fold this `extract_vector_elt` into a
any_ext.

This patch fixes this by using a proper decomposition for `<1 x
bfloat|half>`:
```
bfloat|half = bitcast <1 x blfoat|half>
float = fp_extend bfloat|half
```

This change should be NFC for the non-constant-folding cases and fix the
SDISel crashes (reported in
https://github.com/llvm/llvm-project/issues/94449) for the folding
cases.

Note: The change on the arm test is a missing fp16 to f32 constant folding
exposed by this patch. I'll push a separate improvement for that.
2024-06-07 18:47:37 +02:00
David Green
f7018ba0ee [AArch64] Add patterns for add(uzp1(x,y), uzp2(x, y)) -> addp.
If we are extracting the even lanes and the odd lanes and adding them, we can
use an addp instruction.
2024-06-07 16:09:57 +01:00
Xuan Zhang
3b16630c26
[MachineOutliner] Sort by Benefit to Cost Ratio (#90264)
This PR depends on https://github.com/llvm/llvm-project/pull/90260

We changed the order in which functions are outlined in Machine
Outliner.

The formula for priority is found via a black-box Bayesian optimization
toolbox. Using this formula for sorting consistently reduces the
uncompressed size of large real-world mobile apps. We also ran a few
benchmarks using LLVM test suites, and showed that sorting by priority
consistently reduces the text segment size.

|run (CTMark/)   |baseline (1)|priority (2)|diff (1 -> 2)|
|----------------|------------|------------|-------------|
|lencod          |349624      |349264      |-0.1030%     |
|SPASS           |219672      |219480      |-0.0874%     |
|kc              |271956      |251200      |-7.6321%     |
|sqlite3         |223920      |223708      |-0.0947%     |
|7zip-benchmark  |405364      |402624      |-0.6759%     |
|bullet          |139820      |139500      |-0.2289%     |
|consumer-typeset|295684      |290196      |-1.8560%     |
|pairlocalalign  |72236       |72092       |-0.1993%     |
|tramp3d-v4      |189572      |189292      |-0.1477%     |

This is part of an enhanced version of machine outliner -- see
[RFC](https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-1-fulllto-part-2-thinlto-nolto-to-come/78732).
2024-06-07 06:50:13 -07:00
Liao Chunyu
2afea72968
[RISCV] Codegen support for XCVmem extension (#76916)
All post-Increment load/store, register-register load/store

spec:

https://github.com/openhwgroup/cv32e40p/blob/master/docs/source/instruction_set_extensions.rst

Contributors: @CharKeaney, @jeremybennett, @lewis-revill,
@NandniJamnadas, @PaoloS02, @serkm, @simonpcook, @xingmingjie, @realqhc
2024-06-07 21:45:49 +08:00