Skip to content

[RISCV] Improve Errors for GPRNoX0 Reg Class #126397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/Target/RISCV/RISCVRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ def GPRX5 : GPRRegisterClass<(add X5)> {
let DiagnosticString = "register must be t0 (x5)";
}

def GPRNoX0 : GPRRegisterClass<(sub GPR, X0)>;
def GPRNoX0 : GPRRegisterClass<(sub GPR, X0)> {
let DiagnosticType = "InvalidRegClassGPRX0";
let DiagnosticString = "register must be a GPR excluding zero (x0)";
}

def GPRNoX0X2 : GPRRegisterClass<(sub GPR, X0, X2)> {
let DiagnosticType = "InvalidRegClassGPRNoX0X2";
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/MC/RISCV/rv32c-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ c.xor t2, a0 # CHECK: :[[@LINE]]:8: error: invalid operand for instruction
c.sub a0, s8 # CHECK: :[[@LINE]]:12: error: invalid operand for instruction

## GPRNoX0
c.lwsp x0, 4(sp) # CHECK: :[[@LINE]]:9: error: invalid operand for instruction
c.lwsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: invalid operand for instruction
c.jr x0 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction
c.jalr zero # CHECK: :[[@LINE]]:9: error: invalid operand for instruction
c.lwsp x0, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excluding zero (x0)
c.lwsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excluding zero (x0)
c.jr x0 # CHECK: :[[@LINE]]:7: error: register must be a GPR excluding zero (x0)
c.jalr zero # CHECK: :[[@LINE]]:9: error: register must be a GPR excluding zero (x0)
c.addi x0, x0, 1 # CHECK: :[[@LINE]]:13: error: immediate must be zero
c.li zero, 2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RVC Hint Instructions{{$}}
c.slli zero, zero, 4 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction
c.mv zero, s0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RVC Hint Instructions{{$}}
c.mv ra, x0 # CHECK: :[[@LINE]]:11: error: invalid operand for instruction
c.mv ra, x0 # CHECK: :[[@LINE]]:11: error: register must be a GPR excluding zero (x0)
c.add ra, ra, x0 # CHECK: :[[@LINE]]:16: error: invalid operand for instruction
c.add zero, zero, sp # CHECK: :[[@LINE]]:14: error: invalid operand for instruction

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/RISCV/rv64c-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ c.addw a0, a7 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction
c.subw a0, a6 # CHECK: :[[@LINE]]:14: error: invalid operand for instruction

## GPRNoX0
c.ldsp x0, 4(sp) # CHECK: :[[@LINE]]:9: error: invalid operand for instruction
c.ldsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: invalid operand for instruction
c.ldsp x0, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excluding zero (x0)
c.ldsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excluding zero (x0)

# Out of range immediates

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/RISCV/rvc-hints-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ c.li x0, 42 # CHECK: :[[@LINE]]:10: error: immediate must be an integer in the r

c.lui x0, 0 # CHECK: :[[@LINE]]:11: error: immediate must be in [0xfffe0, 0xfffff] or [1, 31]

c.mv x0, x0 # CHECK: :[[@LINE]]:10: error: invalid operand for instruction
c.mv x0, x0 # CHECK: :[[@LINE]]:10: error: register must be a GPR excluding zero (x0)

c.add x0, x0 # CHECK: :[[@LINE]]:11: error: invalid operand for instruction
c.add x0, x0 # CHECK: :[[@LINE]]:11: error: register must be a GPR excluding zero (x0)

c.slli x0, 0 # CHECK-RV32: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
c.slli x0, 32 # CHECK-RV32: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
Expand Down
117 changes: 78 additions & 39 deletions llvm/test/MC/RISCV/xqcia-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,143 +4,173 @@
# RUN: not llvm-mc -triple riscv32 -mattr=-experimental-xqcia < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-MINUS %s

# CHECK: :[[@LINE+1]]:20: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:20: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:20: error: invalid operand for instruction
qc.slasat x10, x3, 17

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.slasat x10, x3

# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.slasat x0, x3, x17

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.slasat x10, x0, x17

# CHECK: :[[@LINE+1]]:20: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:20: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:20: error: invalid operand for instruction
qc.slasat x10, x3, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.slasat x10, x3, x17


# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.sllsat x23, x25, 27

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.sllsat x23, x25

# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.sllsat x0, x25, x27

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.sllsat x23, x0, x27

# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.sllsat x23, x25, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.sllsat x23, x25, x27


# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.addsat x17, x14, 7

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.addsat x17, x14

# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.addsat x0, x14, x7

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.addsat x17, x0, x7

# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.addsat x17, x14, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.addsat x17, x14, x7


# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.addusat x8, x18, 28

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.addusat x8, x18

# CHECK: :[[@LINE+1]]:12: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:12: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:12: error: invalid operand for instruction
qc.addusat x0, x18, x28

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.addusat x8, x0, x28

# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.addusat x8, x18, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.addusat x8, x18, x28


# CHECK: :[[@LINE+1]]:20: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:20: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:20: error: invalid operand for instruction
qc.subsat x22, x2, 12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.subsat x22, x2

# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.subsat x0, x2, x12

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.subsat x22, x0, x12

# CHECK: :[[@LINE+1]]:20: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:20: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:20: error: invalid operand for instruction
qc.subsat x22, x2, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.subsat x22, x2, x12


# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.subusat x9, x14, 17

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.subusat x9, x14

# CHECK: :[[@LINE+1]]:12: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:12: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:12: error: invalid operand for instruction
qc.subusat x0, x14, x17

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.subusat x9, x0, x17

# CHECK: :[[@LINE+1]]:21: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:21: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:21: error: invalid operand for instruction
qc.subusat x9, x14, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.subusat x9, x14, x17


# CHECK: :[[@LINE+1]]:18: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:18: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:18: error: invalid operand for instruction
qc.wrap x3, x30, 23

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.wrap x3, x30

# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:9: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.wrap x0, x30, x23

# CHECK: :[[@LINE+1]]:18: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:18: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:18: error: invalid operand for instruction
qc.wrap x3, x30, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.wrap x3, x30, x23


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:10: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.wrapi x0, 12, 2047

# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:10: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.wrapi x0, x12, 2047

# CHECK: :[[@LINE+1]]:14: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:14: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:14: error: invalid operand for instruction
qc.wrapi x6, x0, 2047

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
Expand All @@ -153,48 +183,57 @@ qc.wrapi x6, x12, 2048
qc.wrapi x6, x12, 2047


# CHECK: :[[@LINE+1]]:13: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:13: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:13: error: invalid operand for instruction
qc.norm x3, 7

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.norm x3

# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:9: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.norm x0, x7

# CHECK: :[[@LINE+1]]:13: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:13: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:13: error: invalid operand for instruction
qc.norm x3, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.norm x3, x7


# CHECK: :[[@LINE+1]]:15: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:15: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:15: error: invalid operand for instruction
qc.normu x11, 17

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.normu x11

# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:10: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.normu x0, x17

# CHECK: :[[@LINE+1]]:15: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:15: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:15: error: invalid operand for instruction
qc.normu x11, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
qc.normu x11, x17


# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.normeu x26, 31

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.normeu x26

# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.normeu x0, x31

# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:16: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:16: error: invalid operand for instruction
qc.normeu x26, x0

# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcia' (Qualcomm uC Arithmetic Extension)
Expand Down
9 changes: 6 additions & 3 deletions llvm/test/MC/RISCV/xqciac-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# RUN: not llvm-mc -triple riscv32 -mattr=-experimental-xqciac < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-EXT %s

# CHECK: :[[@LINE+1]]:14: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:14: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:14: error: invalid operand for instruction
qc.c.muliadd x5, x10, 4

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
Expand All @@ -17,7 +18,8 @@ qc.c.muliadd x10, x15, 32
qc.c.muliadd x10, x15, 20


# CHECK: :[[@LINE+1]]:12: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:12: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:12: error: invalid operand for instruction
qc.muliadd x0, x10, 1048577

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
Expand All @@ -30,7 +32,8 @@ qc.muliadd x10, x15, 8589934592
qc.muliadd x10, x15, 577


# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
# CHECK-PLUS: :[[@LINE+2]]:11: error: register must be a GPR excluding zero (x0)
# CHECK-MINUS: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.shladd 0, x10, 1048577

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
Expand Down
Loading