415 Commits

Author SHA1 Message Date
Nikita Popov
eeac0ffaf4 Revert "[MachineLICM] Use RegisterClassInfo::getRegPressureSetLimit (#119826)"
This reverts commit b4e17d4a314ed87ff6b40b4b05397d4b25b6636a.

This causes a large compile-time regression.
2025-01-10 09:05:06 +01:00
Pengcheng Wang
b4e17d4a31
[MachineLICM] Use RegisterClassInfo::getRegPressureSetLimit (#119826)
`RegisterClassInfo::getRegPressureSetLimit` is a wrapper of
`TargetRegisterInfo::getRegPressureSetLimit` with some logics to
adjust the limit by removing reserved registers.

It seems that we shouldn't use
`TargetRegisterInfo::getRegPressureSetLimit`
directly, just like the comment "This limit must be adjusted
dynamically for reserved registers" said.

Separate from https://github.com/llvm/llvm-project/pull/118787
2025-01-09 21:05:52 +08:00
ZhaoQi
67ff11ea5b
[LoongArch] Avoid scheduling tls-desc code sequence in large code model (#121541) 2025-01-03 16:43:39 +08:00
ZhaoQi
e4372c4454
[LoongArch] Pre-commit tests for tls-desc scheduling. NFC (#121538)
Code sequence for tls-desc in large code model is not expected to be
scheduled according to psABI 2.30.

A later commit will fix it.
2025-01-03 11:23:44 +08:00
ZhaoQi
b53866fec8
[LoongArch] Modify expanding code sequence for PseudoLA_TLS_LE (#119696)
Before this commit, PseudoLA_TLS_LE for normal/medium code model expand
normally to:
```
  lu12i.w $rd, %le_hi20(sym)
  ori $rd, $rd, %le_lo12(sym)
```

This commit changes the result to:
```
  lu12i.w $rd, %le_hi20_r(sym)
  add.w/d $rd, $rd, $tp, %le_add_r(sym)
  addi.w/d $rd, $rd, %le_lo12_r(sym)
```

This aims to be optimized by linker relaxation in the future.

This commit makes no change to PseudoLA_TLS_LE in large code model.
2024-12-30 16:01:46 +08:00
Zhaoxin Yang
f334db92be
[llvm][CodeGen] Intrinsic llvm.powi.* code gen for vector arguments (#118242)
Scalarize vector FPOWI instead of promoting the type. This allows the
scalar FPOWIs to be visited and converted to libcalls before promoting
the type.

FIXME: This should be done in LegalizeVectorOps/LegalizeDAG, but call
lowering needs the unpromoted EVT.

Without this patch, in some backends, such as RISCV64 and LoongArch64,
the i32 type is illegal and will be promoted. This causes exponent type
check to fail when ISD::FPOWI node generates a libcall.

Fix https://github.com/llvm/llvm-project/issues/118079
2024-12-19 08:57:31 +08:00
hev
e4fb30205f
[LoongArch] Adds support for vectors in OptWInstrs (#118935) 2024-12-16 13:39:01 +08:00
WANG Rui
019948647e [LoongArch][NFC] Pre-commit tests for sign-extension removal with vectors 2024-12-13 23:09:23 +08:00
hev
f6289f1308
[LoongArch] Enable AllNBitUsers checking for {DIV,MOD}.W{U} with div32 enabled (#118776) 2024-12-10 21:19:38 +08:00
ZhaoQi
953838dcea
[LoongArch] Optimize vector bitreverse using scalar bitrev and vshuf4i (#118054)
Custom lower vector type bitreverse to scalar bitrev and vshuf4i
instructions.

Keep `v2i64` and `v4i64` bitreverse `Expand`, it's good enough.
2024-12-10 09:11:28 +08:00
ZhaoQi
20d4742eae
[LoongArch] Pre-commit tests for vector type llvm.bitreverse. NFC (#118053)
A later commit will optimize this.
2024-12-09 19:43:12 +08:00
WANG Rui
dca2ed3127 [LoongArch][NFC] Pre-commit tests for sign-extension removal with vectors 2024-12-06 15:02:55 +08:00
WANG Rui
487a070beb [LoongArch][NFC] Pre-commit tests for sign-extension removal with div32 enabled 2024-12-05 17:40:28 +08:00
hev
00d8ea3a4c
[LoongArch] Supports FP_TO_SINT operation for fp16 (#118303)
Fixes #118301
2024-12-05 10:46:23 +08:00
tangaac
427be07675
[LoongArch] Support amcas[_db].{b/h/w/d} instructions. (#114189)
Two options for clang: -mlamcas & -mno-lamcas.
Enable or disable amcas[_db].{b/h} instructions.
The default is -mno-lamcas.
Only works on LoongArch64.
2024-11-27 17:36:13 +08:00
tangaac
53c0a25db7
[LoongArch] Use div.w/mod.w to eliminate unnecessary sign-extend for sdiv/srem i32. (#117298) 2024-11-27 14:35:53 +08:00
tangaac
f4379db496
[LoongArch] Support LA V1.1 feature that div.w[u] and mod.w[u] instructions with inputs not signed-extended. (#116764)
Two options for clang
-mdiv32: Use div.w[u] and mod.w[u] instructions with input not
sign-extended.
-mno-div32: Do not use div.w[u] and mod.w[u] instructions with input not
sign-extended.
The default is -mno-div32.
2024-11-26 21:57:29 +08:00
tangaac
1d4602070f
[LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (#116762)
Two options for clang
-mld-seq-sa: Do not generate load-load barrier instructions (dbar 0x700)
-mno-ld-seq-sa: Generate load-load barrier instructions (dbar 0x700)
The default is -mno-ld-seq-sa
2024-11-22 17:34:15 +08:00
wanglei
6377ae46a8
[LoongArch] Fix GOT usage for non-dso_local function calls in large code model
This commit fixes an issue in the large code model where non-dso_local
function calls did not use the GOT as expected in PIC mode. Instead,
direct PC-relative access was incorrectly applied, leading to linker
errors when building shared libraries.

For `ExternalSymbol`, it is not possible to determine whether it is
dso_local during pseudo-instruction expansion. We use target flags to
differentiate whether GOT should be used.

Reviewed By: heiher, SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/117099
2024-11-21 16:52:38 +08:00
Yingwei Zheng
c727b48287
[SDAG][ISel][TableGen][LoongArch] Report error for trivial bitcasts when there are predicate calls (#116075)
On loongarch64 with lsx extension, we select `VBITREV_W` for `v4i32 (xor
X, (shl splat(1), Y))`:

8e66303916/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td (L1583-L1584)

And `vsplat_imm_eq_1` is defined as:

8e66303916/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td (L77-L87)

For the `(bitconvert (v4i32 (build_vector)))` case, the pattern is
expected to be:
```
PATTERN: (xor:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, (shl:{ *:[v4i32] } (bitconvert:{ *:[v4i32] } (build_vector:{ *:[v4i32] }))<<P:Predicate_vsplat_imm_eq_1>>, v4i32:{ *:[v4i32] }:$vk))
RESULT:  (VBITREV_W:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, v4i32:{ *:[v4i32] }:$vk)
```

However, `simplifyTree` drops the `bitconvert` node and its predicates:

8e66303916/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (L3036-L3062)

Then llvm will match `vsplat_imm_eq_1` for any v4i32 splats and cause a
miscompilation:
```
PATTERN: (xor:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, (shl:{ *:[v4i32] } (build_vector:{ *:[v4i32] }), v4i32:{ *:[v4i32] }:$vk))
RESULT:  (VBITREV_W:{ *:[v4i32] } v4i32:{ *:[v4i32] }:$vj, v4i32:{ *:[v4i32] }:$vk)
```

This patch adds additional checks for predicates associated with the
trivial bitconvert node. Unused patterns in the LoongArch target are
also removed.

Fixes https://github.com/llvm/llvm-project/issues/116008.
2024-11-19 21:24:40 +08:00
ZhaoQi
512208b498
[LoongArch] Optimize vreplgr2vr + vinsgr2vr intrinsic sequence (#115803)
Inspired by https://github.com/llvm/llvm-project/issues/101624.
2024-11-12 19:07:53 +08:00
ZhaoQi
aad256598d
[LoongArch] Pre-commit test for vreplgr2vr + vinsgr2vr intrinsics (#115702)
Inspired by https://github.com/llvm/llvm-project/issues/101624.

A later commit will optimize it.
2024-11-12 10:27:37 +08:00
Zhaoxin Yang
75c2888209
[MC][LoongArch] Change default cpu in MCSubtargetInfo. (#114922)
The default value of this CPU affects the `FeatureBits` obtained by
`LoongArchTargetELFStreamer` when creating an ELF file, and it will
further affect the `Flags` field in the generated file.

So, the default CPU value should be consistent with the
`initializeSubtargetDependencies` in `LoongArchSubtarget.cpp`.
Otherwise, the `Flags` field may be unexpected.
2024-11-11 16:46:22 +08:00
wanglei
21ef17c626
[LoongArch] Avoid indirect branch jumps using the ra register
Micro-architecture unconditionally treats a "jr $ra" as "return from
subroutine", hence doing "jr $ra" would interfere with both subroutine
return prediction and the more general indirect branch prediction.

GCC thread: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110136

Reviewed By: SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/115424
2024-11-11 14:15:22 +08:00
wanglei
2eaf50716a
[LoongArch] Precommit test for avoid indirect branch jumps through ra. NFC
Reviewed By: SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/115423
2024-11-11 14:14:16 +08:00
abhishek-kaushik22
d2aff182d3
Revert "TLS loads opimization (hoist)" (#114740)
This reverts commit c31014322c0b5ae596da129cbb844fb2198b4ef4.

Based on the discussions in #112772, this pass is not needed after the
introduction of `llvm.threadlocal.address` intrinsic.

Fixes https://github.com/llvm/llvm-project/issues/112771.
2024-11-07 10:10:28 +01:00
hev
cab606c306
[LoongArch] Enable alias analysis by default (#114980)
Enable use of alias analysis during code generation.
2024-11-06 19:30:57 +08:00
Zhaoxin Yang
8c565de5ec
[LoongArch] Support llvm.lround intrinsics with i32 return type. (#114733)
This is needed by flang, similar to RISCV-64 in
https://reviews.llvm.org/D147195.
2024-11-06 17:34:13 +08:00
WANG Rui
a165bbddf9 [LoongArch][NFC] Reland "Pre-commit tests for codegen with alias analysis" 2024-11-06 11:54:34 +08:00
WANG Rui
9ba0e5c27d Revert "[LoongArch][NFC] Pre-commit tests for codegen with alias analysis"
This reverts commit 445db93844cb50eeb6f587bef0749c2950b46e70.
2024-11-06 11:45:18 +08:00
ZhaoQi
92be2cb086
[LoongArch] Use LSX for scalar FP rounding with explicit rounding mode (#114766)
LoongArch FP base ISA only have frint.{s/d} instruction which reads the
global rounding mode. Utilize LSX for explicit rounding mode for scalar
ceil/floor/trunc/roundeven calls when -mlsx opend. It is faster than
calling the libm library functions.

Same as what gcc did:
https://gcc.gnu.org/pipermail/gcc-cvs/2023-November/394218.html
2024-11-06 09:26:28 +08:00
ZhaoQi
4ff62052c8
[LoongArch] Add test for scalar FP rounding (#114968) 2024-11-05 21:21:20 +08:00
WANG Rui
445db93844 [LoongArch][NFC] Pre-commit tests for codegen with alias analysis 2024-11-05 20:53:38 +08:00
WÁNG Xuěruì
f246b5f547
[LoongArch] Support bswap for LSX/LASX VTs (#114171)
On top of #114170
2024-11-01 00:38:13 +08:00
hev
f7a96dc664
[LoongArch] Ensure pcaddu18i and jirl adjacency in tail calls for correct relocation (#113932)
Prior to this patch, both `pcaddu18i` and `jirl` were marked as
scheduling boundaries to prevent instruction reordering that would
disrupt their adjacency. However, in certain cases, epilogues were still
being inserted between these two instructions, breaking the required
proximity. This patch ensures that `pcaddu18i` and `jirl` remain
adjacent even in the presence of epilogues, maintaining correct
relocation behavior for tail calls on LoongArch.
2024-11-01 00:08:15 +08:00
WÁNG Xuěruì
5581e43a2b
[LoongArch][NFC] Pre-commit tests for LSX/LASX bswap codegen (#114170) 2024-10-31 21:10:26 +08:00
WANG Rui
862074fa57 [LoongArch][NFC] Pre-commit tests for the adjacency of expanded pseudo-insns 2024-10-31 16:59:41 +08:00
Ami-zhang
1897bf61f0
[LoongArch] Enable FeatureExtLSX for generic-la64 processor (#113421)
This commit makes the `generic` target to support FP and LSX, as
discussed in #110211. Thereby, it allows 128-bit vector to be enabled by
default in the loongarch64 backend.
2024-10-31 15:58:15 +08:00
hev
b225b15a3d
[LoongArch] Merge base and offset for large offsets (#113277)
This PR merges large offsets into the base address loading.
2024-10-23 19:43:23 +08:00
tangaac
5b9c76b6e7
[LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (#113255)
Two options for clang: -mlam-bh & -mno-lam-bh.
Enable or disable amswap[__db].{b/h} and amadd[__db].{b/h} instructions.
The default is -mno-lam-bh.
Only works on LoongArch64.
2024-10-23 16:03:15 +08:00
WANG Rui
4614b80c49 [LoongArch] Pre-commit tests for merge base with large offset. NFC 2024-10-22 15:44:40 +08:00
tangaac
ba5676cf91
[LoongArch] Minor refinement to monotonic atomic semantics. (#112681)
Don't use "_db" version AM instructions for LoongArch atomic memory
operations with monotonic semantics.
2024-10-21 15:58:35 +08:00
Alex Rønne Petersen
ad4a582fd9
[llvm] Consistently respect naked fn attribute in TargetFrameLowering::hasFP() (#106014)
Some targets (e.g. PPC and Hexagon) already did this. I think it's best
to do this consistently so that frontend authors don't run into
inconsistent results when they emit `naked` functions. For example, in
Zig, we had to change our emit code to also set `frame-pointer=none` to
get reliable results across targets.

Note: I don't have commit access.
2024-10-18 09:35:42 +04:00
tangaac
e9eec14bb3
[LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (#109917)
Two options: `-mfrecipe` & `-mno-frecipe`.
Enable or Disable frecipe.{s/d} and frsqrte.{s/d} instructions. 
The default is `-mno-frecipe`.
2024-10-18 09:06:29 +08:00
wanglei
4c2c177567
[LoongArch] Add options for annotate tablejump
This aligns with GCC. LoongArch kernel developers requested that this
option generate some corresponding relations in a section, including the
addresses of the jump instruction(jr) and the `MachineJumpTableEntry`.

Reviewed By: heiher

Pull Request: https://github.com/llvm/llvm-project/pull/102411
2024-10-16 11:58:00 +08:00
WANG Rui
8e3cde04cb [LoongArch][test] Add float-point atomic load/store tests. NFC 2024-09-25 15:39:22 +08:00
Robert Dazi
8837898b8d
[DAGCombine] Count leading ones: refine post DAG/Type Legalisation if promotion (#102877)
This PR is related to #99591. In this PR, instead of modifying how the
legalisation occurs depending on surrounding instructions, we refine
after legalisation.

This PR has two parts:

* `SDPatternMatch/MatchContext`: Modify a little bit the code to match
Operands (used by `m_Node(...)`) and Unary/Binary/Ternary Patterns to
make it compatible with `VPMatchContext`, instead of only `m_Opc`
supported. Some tests were added to ensure no regressions.
* `DAGCombiner`: Add a `foldSubCtlzNot` which detect and rewrite the
patterns using matching context.

Remaining Tasks:

- [ ] GlobalISel
- [ ] Currently the pattern matching will occur even before
legalisation. Should I restrict it to specific stages instead ?
- [ ] Style: Add a visitVP_SUB ?? Move `foldSubCtlzNot` in another
location for style consistency purpose ?

@topperc

---------

Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
2024-09-15 15:48:36 +04:00
YANG Xudong
13280d99ae
[loongarch][DAG][FREEZE] Fix crash when FREEZE a half(f16) type on loongarch (#107791)
For zig with LLVM 19.1.0rc4, we are seeing the following error when
bootstrapping a `loongarch64-linux-musl` target.


https://github.com/ziglang/zig-bootstrap/issues/164#issuecomment-2332357069

It seems that this issue is caused by `PromoteFloatResult` is not
handling FREEZE OP on loongarch.

Here is the reproduction of the error: https://godbolt.org/z/PPfvWjjG5

~~This patch adds the FREEZE OP handling with `PromoteFloatRes_UnaryOp`
and adds a test case.~~

This patch changes loongarch's way of floating point promotion to soft
promotion to avoid this problem.

See: loongarch's handling of `half`:
- https://github.com/llvm/llvm-project/issues/93894
- https://github.com/llvm/llvm-project/pull/94456

Also see: other float promotion FREEZE handling
-
0019c2f194
2024-09-13 08:49:54 +08:00
Lu Weining
ffcebcdb96
[LoongArch] Implement Statepoint lowering (#108212)
The functionality has been validated in OpenHarmony's arkcompiler.
2024-09-12 18:05:13 +08:00
hev
0f47e3aebd
[LoongArch] Eliminate the redundant sign extension of division (#107971)
If all incoming values of `div.d` are sign-extended and all users only
use the lower 32 bits, then convert them to W versions.

Fixes: #107946
2024-09-10 16:52:21 +08:00