Commit Graph

135 Commits

Author SHA1 Message Date
Weining Lu 771aee91c8 Reland "[LoongArch] Fix codegen of atomicrmw nand"
Fix invalid RISCV-like MI being emitted for performing the `not`
operation: the LoongArch `xori` zero-extends the immediate, hence is
not equivalent to RISCV `xori`. The LoongArch `not` is a `nor` with
zero.

Patch by lrzlin (Lin Runze).

Differential Revision: https://reviews.llvm.org/D136021
2022-10-19 10:05:35 +08:00
Weining Lu 0f374ca5cd Revert "[LoongArch] Fix codegen of atomicrmw nand"
This reverts commit 9572406bbc.

The author name is wrong.
2022-10-19 07:56:23 +08:00
Weining Lu 9572406bbc [LoongArch] Fix codegen of atomicrmw nand
Fix invalid RISCV-like MI being emitted for performing the `not`
operation: the LoongArch `xori` zero-extends the immediate, hence is
not equivalent to RISCV `xori`. The LoongArch `not` is a `nor` with
zero.

Differential Revision: https://reviews.llvm.org/D136021
2022-10-18 20:39:20 +08:00
wanglei 506e936871 [LoongArch] Fix wrong VariantKind for MO_GOT_PC_{HI/LO} flags
Differential Revision: https://reviews.llvm.org/D135946
2022-10-15 17:45:08 +08:00
gonglingqin e632bb6543 [LoongArch] Add codegen support for atomicrmw umin/umax operation on LA64
Furthermore, use `beqz $rd, .BB` instead of `beq $rd, $zero, .BB`.

Differential Revision: https://reviews.llvm.org/D135525
2022-10-14 15:24:43 +08:00
WANG Xuerui f017e92c1c [LoongArch] Add support for llvm.trap and llvm.debugtrap
Similar to D69390 for RISCV, use a guaranteed non-existing insn for
llvm.trap and the break insn for llvm.debugtrap.

Differential Revision: https://reviews.llvm.org/D134365
2022-10-13 19:27:47 +08:00
WANG Xuerui 4e2dfd3589 [LoongArch] Updates for the LoongArch ELF psABI v2.01 revision
The e_flags of existing object files are all 0x3 which happens to be
compatible. From this commit on, all LoongArch objects produced with
upstream LLVM will be of object file ABI v1, which is already supported
by binutils' master branch (to be released as 2.40), and is allowed by
the same binutils version to interlink with v0 objects so the existing
distributions have time to migrate.

Differential Revision: https://reviews.llvm.org/D134601
2022-10-13 19:12:26 +08:00
gonglingqin ec2640bf3a [LoongArch] Handle missing CondCodes
Support SETLE/SETEQ and expand SETGE/SETNE/SETGT

Differential Revision: https://reviews.llvm.org/D135511
2022-10-12 21:26:57 +08:00
gonglingqin b1d7a95e4e [LoongArch] Add earlyclobber of destination register to atomic instructions
If the AM* atomic memory access instruction has the same register number as
rd and rj, the execution will trigger an Instruction Non-defined Exception.
If the AM* atomic memory access instruction has the same register number as
rd and rk, the execution result is uncertain.

Reference: https://github.com/loongson/LoongArch-Documentation

Differential Revision: https://reviews.llvm.org/D135641
2022-10-12 21:09:21 +08:00
Weining Lu 42b70793a1 Reland "[Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC"
Reference: https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html

k: A memory operand whose address is formed by a base register and
(optionally scaled) index register.

m: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as st.w and ld.w.

ZB: An address that is held in a general-purpose register. The offset
is zero.

ZC: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as ll.w and sc.w.

Note:
The INLINEASM SDNode flags in below tests are updated because the new
introduced enum `Constraint_k` is added before `Constraint_m`.
  llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
  llvm/test/CodeGen/X86/callbr-asm-kill.mir

This patch passes `ninja check-all` on a X86 machine with all official
targets and the LoongArch target enabled.

Differential Revision: https://reviews.llvm.org/D134638
2022-10-11 19:51:48 +08:00
wanglei 64c42a4d70 [LoongArch] Define getSetCCResultType for setting vector setCC type
To avoid trigger "No default SetCC type for vectors!" Assertion.

Differential Revision: https://reviews.llvm.org/D135527
2022-10-11 19:05:14 +08:00
wanglei d1b526fb95 [LoongArch] Add codegen support of GlobalTLSAddress lowering
There are static and dynamic TLS address lowering in DAG stage according
to different TLS models.

TLS address will be lowered to pseudo instruction and then expanded by
the `LoongArch Pre-RA pseudo instruction expansion` pass.

Differential Revision: https://reviews.llvm.org/D134713
2022-10-11 18:10:13 +08:00
gonglingqin 5593d36356 [LoongArch] Expand fptrunc store from f64 to f32
Differential Revision: https://reviews.llvm.org/D135510
2022-10-09 17:55:42 +08:00
WANG Xuerui 31327c29fb [LoongArch] Don't merge FrameIndex accesses into [F]{LD,ST}X
Otherwise eliminateFrameIndex cannot figure out how to fixup the stack
offset with its stateless logic, because there wouldn't be an immediate
slot for it to trivially write to, and it may not be easy to transform
the surrounding code to make it work.

This fixes a fairly common crash when compiling moderately complex code with
Clang.

Differential Revision: https://reviews.llvm.org/D135251
2022-10-09 13:04:21 +08:00
gonglingqin f4ccb577f8 [LoongArch] Do not assert value type in isFPImmLegal
This patch fixes the failure of llvm/test/CodeGen/Generic/vector.ll and
CodeGen/PowerPC/2007-11-19-VectorSplitting.ll for a LoongArch native build.

Differential Revision: https://reviews.llvm.org/D134798
2022-10-08 14:50:48 +08:00
gonglingqin 853a1b7236 [LoongArch] Clean up redundant code introduced by conflict resolution. NFC 2022-09-30 16:45:21 +08:00
Fangrui Song 04a65d62a0 Revert D134638 "[Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC"
This reverts commit b7baddc755.

Broke CodeGen/X86/callbr-asm-kill.mir
We shall pay attention when adding new constraints.
2022-09-29 00:54:56 -07:00
Weining Lu b7baddc755 [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC
k: A memory operand whose address is formed by a base register and
(optionally scaled) index register.

m: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as st.w and ld.w.

ZB: An address that is held in a general-purpose register. The offset
is zero.

ZC: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as ll.w and sc.w.

Differential Revision: https://reviews.llvm.org/D134638
2022-09-29 15:02:08 +08:00
gonglingqin dc3c5a78f2 [LoongArch] Add fp_to_sint support for soft floating point
Differential Revision: https://reviews.llvm.org/D134692
2022-09-29 10:25:35 +08:00
WANG Xuerui 3155f6c508 [LoongArch] Expand llvm.stacksave and llvm.stackrestore
As in commit bfb00d4c1c ("[RISCV] Allow lowering of dynamic_stackalloc, stacksave, stackrestore").

Differential Revision: https://reviews.llvm.org/D134435
2022-09-29 09:07:44 +08:00
wanglei 036b170c24 [LoongArch] Produce a R_LARCH_32_PCREL relocation
LoongArchELFObjectWriter::getRelocType check IsPCRel for FK_Data_4
(which we produce a R_LARCH_32_PCREL relocation for if IsPCRel).

R_LARCH_32_PCREL is required for FDE relocation.

Differential Revision: https://reviews.llvm.org/D134715
2022-09-29 09:04:44 +08:00
wanglei 7b1bdfbeb0 [LoongArch] Override TargetSubtargetInfo::getSelectionDAGInfo
The target selection DAG lowering information is needed for
SelectionDAGBuilder to lower a call like memcmp into an optimized
form.

Differential Revision: https://reviews.llvm.org/D134712
2022-09-29 08:46:53 +08:00
wanglei 983a0ae5cf [LoongArch] Specify registers used in DWARF exception handling
Defines LoongArch registers for getExceptionPointerRegister() and
getExceptionSelectorRegister().

Differential Revision: https://reviews.llvm.org/D134709
2022-09-28 17:53:16 +08:00
gonglingqin 95d2367647 [LoongArch] Expand FSIN/FCOS/FSINCOS/FPOW/FREM
Differential Revision: https://reviews.llvm.org/D134628
2022-09-28 09:42:41 +08:00
wanglei 823ce6ad18 [LoongArch] Add some comments for expand pseudo-inst pass. NFC
Differential Revision: https://reviews.llvm.org/D134708
2022-09-27 20:26:07 +08:00
WANG Xuerui c2a44b591e [LoongArch] Support lowering frames larger than 2048 bytes
Differential Revision: https://reviews.llvm.org/D134582
2022-09-27 18:58:33 +08:00
gonglingqin a6d699b55d [LoongArch] Add codegen support for strict_fsetccs and any_fsetcc
Differential Revision: https://reviews.llvm.org/D134274
2022-09-26 13:05:36 +08:00
wanglei 75265c7f49 [LoongArch] Lower BlockAddress/JumpTable
This patch uses a unified interface for lower GlobalAddress ConstantPool
BlockAddress and JumpTable.

This patch allows lowering addresses by using PC-relative addressing
for DSO-local symbols, and accessing the address through the global
offset table for DSO-preemptable symbols.

Remove hardcoded `MininumJumpTableEntries` for test lower JumpTable.

Also updated some test cases using ConstantPool, due to the addition of
relocation information.

Differential Revision: https://reviews.llvm.org/D134431
2022-09-26 10:52:54 +08:00
WANG Xuerui ad6fe32032 [LoongArch] Support 'generic' as a valid CPU name
As the LoongArch port is largely modeled after RISCV it has the same
behavior of not accepting `generic` as a CPU name. For better
compatibility with consumers of LLVM (e.g. mesa) follow D121149's suit
and treat `generic` the same as an empty CPU name.

Differential Revision: https://reviews.llvm.org/D134412
2022-09-26 10:20:13 +08:00
WANG Xuerui d2ac89b64e [LoongArch] Support fastcc and treat it as ccc
As explained in D68559 the `fastcc` calling convention may be requested
under certain conditions, hence the need for supporting it. But unlike
RISCV we actually treat it exactly like ccc, without actually inventing
any performance hack right here. And CSKY does the same thing.

This is going to fix a few more test cases with native LoongArch builds.

Differential Revision: https://reviews.llvm.org/D134443
2022-09-26 10:15:00 +08:00
WANG Xuerui f89f0990db [LoongArch] Support llvm.thread.pointer
For `__builtin_thread_pointer` to work, among other things.

Similar to D76828 for RISCV.

Differential Revision: https://reviews.llvm.org/D134368
2022-09-26 09:56:42 +08:00
Weining Lu 394f30919a [Clang][LoongArch] Add inline asm support for constraints f/l/I/K
This patch adds support for constraints `f`, `l`, `I`, `K` according
to [1]. The remain constraints (`k`, `m`, `ZB`, `ZC`) will be added
later as they are a little more complex than the others.
f: A floating-point register (if available).
l: A signed 16-bit constant.
I: A signed 12-bit constant (for arithmetic instructions).
K: An unsigned 12-bit constant (for logic instructions).

For now, no need to support register alias (e.g. `$a0`) in llvm as
clang will correctly decode the usage of register name aliases into
their official names. And AFAIK, the not yet upstreamed `rustc` for
LoongArch will always use official register names (e.g. `$r4`).

[1] https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html

Differential Revision: https://reviews.llvm.org/D134157
2022-09-26 08:49:58 +08:00
gonglingqin ac295597a8 [LoongArch] Add codegen support for atomicrmw add/sub/nand/and/or/xor operation
Differential Revision: https://reviews.llvm.org/D133755
2022-09-23 09:32:11 +08:00
gonglingqin 7328ff75ba [LoongArch] Add codegen support for fmaxnum_ieee and fminnum_ieee
Thanks for @xry111's previous bug fixes.
See https://github.com/loongson/llvm-project/pull/1 for more details.

Differential Revision: https://reviews.llvm.org/D133478
2022-09-20 19:22:32 +08:00
Sergei Barannikov c6acb4eb0f [SDAG] Add `getCALLSEQ_END` overload taking `uint64_t`s
All in-tree targets pass pointer-sized ConstantSDNodes to the
method. This overload reduced amount of boilerplate code a bit.  This
also makes getCALLSEQ_END consistent with getCALLSEQ_START, which
already takes uint64_ts.
2022-09-15 14:02:12 -04:00
wanglei a65557d4b3 [LoongArch] Fixup value adjustment in applyFixup
A complete implementation of `applyFixup` for D132323.

Makes `LoongArchAsmBackend::shouldForceRelocation` to determine
if the relocation types must be forced.

This patch also adds range and alignment checks for `b*` instructions'
operands, at which point the offset to a label is known.

Differential Revision: https://reviews.llvm.org/D132818
2022-09-15 21:00:22 +08:00
gonglingqin 7fd7d48b4b [LoongArch] Categorize code by function. NFC.
Differential Revision: https://reviews.llvm.org/D133754
2022-09-14 09:48:26 +08:00
gonglingqin 3de3439bd7 [LoongArch] Add codegen support for ISD::FMA
Differential Revision: https://reviews.llvm.org/D133281
2022-09-13 10:04:41 +08:00
gonglingqin da8c9521ee [LoongArch] Add codegen support for frint
According to the revised description in `LoongArch Reference Manual v1.02`,
frint.[s/d] does not judge whether floating-point inexact exceptions are
allowed indicated by FCSR, i.e. always executes roundToIntegralExact(x).
What's more, the manual also specifically defines that frint.s/d is only
necessary to be defined in LA64. So ISD::FRINT is legal for LA64.

Differential Revision: https://reviews.llvm.org/D133337
2022-09-09 14:25:34 +08:00
Joe Loser 5e96cea1db [llvm] Use std::size instead of llvm::array_lengthof
LLVM contains a helpful function for getting the size of a C-style
array: `llvm::array_lengthof`. This is useful prior to C++17, but not as
helpful for C++17 or later: `std::size` already has support for C-style
arrays.

Change call sites to use `std::size` instead.

Differential Revision: https://reviews.llvm.org/D133429
2022-09-08 09:01:53 -06:00
gonglingqin d5f7a2182d [LoongArch] Add codegen support for atomicrmw xchg operation on LA32
Depends on D131228

Differential Revision: https://reviews.llvm.org/D131229
2022-09-08 13:57:53 +08:00
gonglingqin b60f801607 [LoongArch] Add codegen support for atomicrmw xchg operation on LA64
In order to avoid the patch being too large, the atomicrmw xchg operation
on LA32 will be added later

Differential Revision: https://reviews.llvm.org/D131228
2022-09-08 13:57:26 +08:00
gonglingqin 067aab0a85 [LoongArch] Fix annotations not matching predicates. NFC. 2022-09-06 09:14:20 +08:00
wanglei bf47954703 [LoongArch] Add more fixups and relocations
This patch makes the assembler support all modifiers defined in gnu-as.
Also changes some diagnostic information.

Differential Revision: https://reviews.llvm.org/D132633
2022-09-05 14:55:18 +08:00
gonglingqin bc743bf666 [LoongArch] Add codegen support for fcopysign
Differential Revision: https://reviews.llvm.org/D133185
2022-09-05 11:03:54 +08:00
WANG Xuerui 2dd434c3ee [LoongArch] Support lowering br_jt
Jump tables cannot be generated yet, due to missing support for emitting
local addresses.

Differential Revision: https://reviews.llvm.org/D132653
2022-09-02 17:57:50 +08:00
gonglingqin 6e47ebdcec [LoongArch] Support ISD::BR_CC and branch according to condition flag register
Use bceqz/bcnez instead of movcf2gr + bnez/beqz for branch jumps.

Differential Revision: https://reviews.llvm.org/D132824
2022-09-01 10:43:16 +08:00
gonglingqin fb9d67636a [LoongArch] Support floating-point number reciprocal
Differential Revision: https://reviews.llvm.org/D132847
2022-08-31 14:20:46 +08:00
gonglingqin bab04bf72b [LoongArch] Combine add + shl to alsl.[w/d/wu]
Differential Revision: https://reviews.llvm.org/D132718
2022-08-29 09:58:11 +08:00
WANG Xuerui 23b2fbf9ec [LoongArch] Port over minimal applyFixup from RISCV
Many DebugInfo tests now pass with native builds.

Differential Revision: https://reviews.llvm.org/D132323
2022-08-26 17:36:29 +08:00