1## Test invalid instructions on both loongarch32 and loongarch64 target. 2 3# RUN: not llvm-mc --triple=loongarch32 %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK64 4# RUN: not llvm-mc --triple=loongarch64 %s 2>&1 --defsym=LA64=1 | FileCheck %s 5 6## Out of range immediates 7## uimm2 8bytepick.w $a0, $a0, $a0, -1 9# CHECK: :[[#@LINE-1]]:27: error: immediate must be an integer in the range [0, 3] 10bytepick.w $a0, $a0, $a0, 4 11# CHECK: :[[#@LINE-1]]:27: error: immediate must be an integer in the range [0, 3] 12 13## uimm2_plus1 14alsl.w $a0, $a0, $a0, 0 15# CHECK: :[[#@LINE-1]]:23: error: immediate must be an integer in the range [1, 4] 16alsl.w $a0, $a0, $a0, 5 17# CHECK: :[[#@LINE-1]]:23: error: immediate must be an integer in the range [1, 4] 18 19## uimm5 20slli.w $a0, $a0, -1 21# CHECK: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [0, 31] 22srli.w $a0, $a0, -1 23# CHECK: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [0, 31] 24srai.w $a0, $a0, 32 25# CHECK: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [0, 31] 26rotri.w $a0, $a0, 32 27# CHECK: :[[#@LINE-1]]:19: error: immediate must be an integer in the range [0, 31] 28bstrins.w $a0, $a0, 31, -1 29# CHECK: :[[#@LINE-1]]:25: error: immediate must be an integer in the range [0, 31] 30bstrpick.w $a0, $a0, 32, 0 31# CHECK: :[[#@LINE-1]]:22: error: immediate must be an integer in the range [0, 31] 32preld -1, $a0, 0 33# CHECK: :[[#@LINE-1]]:7: error: immediate must be an integer in the range [0, 31] 34preld 32, $a0, 0 35# CHECK: :[[#@LINE-1]]:7: error: immediate must be an integer in the range [0, 31] 36 37## uimm12 38andi $a0, $a0, -1 39# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [0, 4095] 40xori $a0, $a0, 4096 41# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [0, 4095] 42 43## uimm12_ori 44ori $a0, $a0, 4096 45# CHECK: :[[#@LINE-1]]:15: error: operand must be a symbol with modifier (e.g. %abs_lo12) or an integer in the range [0, 4095] 46 47## simm12 48slti $a0, $a0, -2049 49# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] 50sltui $a0, $a0, 2048 51# CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] 52preld 0, $a0, 2048 53# CHECK: :[[#@LINE-1]]:15: error: immediate must be an integer in the range [-2048, 2047] 54 55## simm12_addlike 56addi.w $a0, $a0, -2049 57# CHECK: :[[#@LINE-1]]:18: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 58ld.b $a0, $a0, 2048 59# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 60ld.h $a0, $a0, 2048 61# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 62ld.w $a0, $a0, 2048 63# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 64ld.bu $a0, $a0, -2049 65# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 66ld.hu $a0, $a0, -2049 67# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 68st.b $a0, $a0, 2048 69# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 70st.h $a0, $a0, 2048 71# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 72st.w $a0, $a0, -2049 73# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047] 74 75## simm14_lsl2 76ll.w $a0, $a0, -32772 77# CHECK: :[[#@LINE-1]]:16: error: immediate must be a multiple of 4 in the range [-32768, 32764] 78ll.w $a0, $a0, -32769 79# CHECK: :[[#@LINE-1]]:16: error: immediate must be a multiple of 4 in the range [-32768, 32764] 80sc.w $a0, $a0, 32767 81# CHECK: :[[#@LINE-1]]:16: error: immediate must be a multiple of 4 in the range [-32768, 32764] 82sc.w $a0, $a0, 32768 83# CHECK: :[[#@LINE-1]]:16: error: immediate must be a multiple of 4 in the range [-32768, 32764] 84 85## simm16_lsl2 86beq $a0, $a0, -0x20004 87# CHECK: :[[#@LINE-1]]:15: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 88bne $a0, $a0, -0x20004 89# CHECK: :[[#@LINE-1]]:15: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 90blt $a0, $a0, -0x1FFFF 91# CHECK: :[[#@LINE-1]]:15: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 92bge $a0, $a0, -0x1FFFF 93# CHECK: :[[#@LINE-1]]:15: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 94bltu $a0, $a0, 0x1FFFF 95# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 96bgeu $a0, $a0, 0x1FFFF 97# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 98jirl $a0, $a0, 0x20000 99# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %b16) or an integer in the range [-131072, 131068] 100 101## simm20 102pcaddu12i $a0, 0x80000 103# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-524288, 524287] 104 105## simm20_pcaddi 106pcaddi $a0, -0x80001 107# CHECK: :[[#@LINE-1]]:13: error: operand must be a symbol with modifier (e.g. %pcrel_20) or an integer in the range [-524288, 524287] 108 109## simm20_lu12iw 110lu12i.w $a0, -0x80001 111# CHECK: :[[#@LINE-1]]:14: error: operand must be a symbol with modifier (e.g. %abs_hi20) or an integer in the range [-524288, 524287] 112 113## simm20_pcalau12i 114pcalau12i $a0, 0x80000 115# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_hi20) or an integer in the range [-524288, 524287] 116 117## simm21_lsl2 118beqz $a0, -0x400001 119# CHECK: :[[#@LINE-1]]:11: error: operand must be a symbol with modifier (e.g. %b21) or an integer in the range [-4194304, 4194300] 120bnez $a0, -0x3FFFFF 121# CHECK: :[[#@LINE-1]]:11: error: operand must be a symbol with modifier (e.g. %b21) or an integer in the range [-4194304, 4194300] 122beqz $a0, 0x3FFFFF 123# CHECK: :[[#@LINE-1]]:11: error: operand must be a symbol with modifier (e.g. %b21) or an integer in the range [-4194304, 4194300] 124bnez $a0, 0x400000 125# CHECK: :[[#@LINE-1]]:11: error: operand must be a symbol with modifier (e.g. %b21) or an integer in the range [-4194304, 4194300] 126 127## simm26_lsl2 128b -0x8000001 129# CHECK: :[[#@LINE-1]]:3: error: operand must be a bare symbol name or an immediate must be a multiple of 4 in the range [-134217728, 134217724] 130b 0x1 131# CHECK: :[[#@LINE-1]]:3: error: operand must be a bare symbol name or an immediate must be a multiple of 4 in the range [-134217728, 134217724] 132bl 0x7FFFFFF 133# CHECK: :[[#@LINE-1]]:4: error: operand must be a bare symbol name or an immediate must be a multiple of 4 in the range [-134217728, 134217724] 134bl 0x8000000 135# CHECK: :[[#@LINE-1]]:4: error: operand must be a bare symbol name or an immediate must be a multiple of 4 in the range [-134217728, 134217724] 136 137## Invalid mnemonics 138nori $a0, $a0, 0 139# CHECK: :[[#@LINE-1]]:1: error: unrecognized instruction mnemonic 140andni $a0, $a0, 0 141# CHECK: :[[#@LINE-1]]:1: error: unrecognized instruction mnemonic 142orni $a0, $a0, 0 143# CHECK: :[[#@LINE-1]]:1: error: unrecognized instruction mnemonic 144 145## Invalid register names 146add.w $foo, $a0, $a0 147# CHECK: :[[#@LINE-1]]:8: error: invalid operand for instruction 148sub.w $a8, $a0, $a0 149# CHECK: :[[#@LINE-1]]:8: error: invalid operand for instruction 150addi.w $x0, $a0, 0 151# CHECK: :[[#@LINE-1]]:9: error: invalid operand for instruction 152alsl.w $t9, $a0, $a0, 1 153# CHECK: :[[#@LINE-1]]:9: error: invalid operand for instruction 154lu12i.w $s10, 0 155# CHECK: :[[#@LINE-1]]:10: error: invalid operand for instruction 156 157.ifndef LA64 158## LoongArch64 mnemonics 159add.d $a0, $a0, $a0 160# CHECK64: :[[#@LINE-1]]:1: error: instruction requires the following: LA64 Basic Integer and Privilege Instruction Set 161addi.d $a0, $a0, 0 162# CHECK64: :[[#@LINE-1]]:1: error: instruction requires the following: LA64 Basic Integer and Privilege Instruction Set 163.endif 164 165## Invalid operand types 166slt $a0, $a0, 0 167# CHECK: :[[#@LINE-1]]:15: error: invalid operand for instruction 168slti $a0, 0, 0 169# CHECK: :[[#@LINE-1]]:11: error: invalid operand for instruction 170 171## Too many operands 172andi $a0, $a0, 0, 0 173# CHECK: :[[#@LINE-1]]:19: error: invalid operand for instruction 174 175## Too few operands 176and $a0, $a0 177# CHECK: :[[#@LINE-1]]:1: error: too few operands for instruction 178andi $a0, $a0 179# CHECK: :[[#@LINE-1]]:1: error: too few operands for instruction 180 181## Instructions outside the base integer ISA 182## TODO: Test instructions in LSX/LASX/LBT/LVZ after their introduction. 183 184## Using floating point registers when integer registers are expected 185sll.w $a0, $a0, $fa0 186# CHECK: :[[#@LINE-1]]:18: error: invalid operand for instruction 187 188## msbw < lsbw 189# CHECK: :[[#@LINE+1]]:21: error: msb is less than lsb 190bstrins.w $a0, $a0, 1, 2 191# CHECK: ^~~~ 192 193# CHECK: :[[#@LINE+1]]:22: error: msb is less than lsb 194bstrpick.w $a0, $a0, 30, 31 195# CHECK: ^~~~~~ 196