llvm-project/llvm/test/CodeGen/LoongArch/inline-asm-constraint-error.ll
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

41 lines
1.5 KiB
LLVM

; RUN: not llc --mtriple=loongarch32 < %s 2>&1 | FileCheck %s
; RUN: not llc --mtriple=loongarch64 < %s 2>&1 | FileCheck %s
define void @constraint_l() {
; CHECK: error: value out of range for constraint 'l'
tail call void asm sideeffect "lu12i.w $$a0, $0", "l"(i32 32768)
; CHECK: error: value out of range for constraint 'l'
tail call void asm sideeffect "lu12i.w $$a0, $0", "l"(i32 -32769)
ret void
}
define void @constraint_I() {
; CHECK: error: value out of range for constraint 'I'
tail call void asm sideeffect "addi.w $$a0, $$a0, $0", "I"(i32 2048)
; CHECK: error: value out of range for constraint 'I'
tail call void asm sideeffect "addi.w $$a0, $$a0, $0", "I"(i32 -2049)
ret void
}
define void @constraint_K() {
; CHECK: error: value out of range for constraint 'K'
tail call void asm sideeffect "andi.w $$a0, $$a0, $0", "K"(i32 4096)
; CHECK: error: value out of range for constraint 'K'
tail call void asm sideeffect "andi.w $$a0, $$a0, $0", "K"(i32 -1)
ret void
}
define void @constraint_f() nounwind {
; CHECK: error: couldn't allocate input reg for constraint 'f'
tail call void asm "fadd.s $$fa0, $$fa0, $0", "f"(float 0.0)
; CHECK: error: couldn't allocate input reg for constraint 'f'
tail call void asm "fadd.s $$fa0, $$fa0, $0", "f"(double 0.0)
ret void
}
define void @constraint_r_vec() nounwind {
; CHECK: error: couldn't allocate input reg for constraint 'r'
tail call void asm "add.w $$a0, $$a0, $0", "r"(<4 x i32> zeroinitializer)
ret void
}