diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -598,6 +598,17 @@ return RISCVAsmParser::isSymbolDiff(getImm()); } + bool isImmXLenLI_Restricted() const { + int64_t Imm; + RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; + if (!isImm()) + return false; + bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK); + // 'la imm' supports constant immediates only. + return IsConstantImm && (VK == RISCVMCExpr::VK_RISCV_None) && + (isRV64Imm() || (isInt<32>(Imm) || isUInt<32>(Imm))); + } + bool isUImmLog2XLen() const { int64_t Imm; RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; @@ -1356,6 +1367,17 @@ return generateImmOutOfRangeError(Operands, ErrorInfo, std::numeric_limits::min(), std::numeric_limits::max()); + case Match_InvalidImmXLenLI_Restricted: + if (isRV64()) { + SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); + return Error(ErrorLoc, "operand either must be a constant 64-bit integer " + "or a bare symbol name"); + } + return generateImmOutOfRangeError( + Operands, ErrorInfo, std::numeric_limits::min(), + std::numeric_limits::max(), + "operand either must be a bare symbol name or an immediate integer in " + "the range"); case Match_InvalidImmZero: { SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc(); return Error(ErrorLoc, "immediate must be zero"); @@ -3392,6 +3414,8 @@ switch (Inst.getOpcode()) { default: break; + case RISCV::PseudoLLAImm: + case RISCV::PseudoLAImm: case RISCV::PseudoLI: { MCRegister Reg = Inst.getOperand(0).getReg(); const MCOperand &Op1 = Inst.getOperand(1); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -407,6 +407,11 @@ let ParserMatchClass = ImmXLenAsmOperand<"", "LI">; } +// Accepts subset of LI operands, used by LAImm and LLAImm +def ixlenimm_li_restricted : Operand { + let ParserMatchClass = ImmXLenAsmOperand<"", "LI_Restricted">; +} + // Standalone (codegen-only) immleaf patterns. // A 6-bit constant greater than 32. @@ -1605,6 +1610,11 @@ def PseudoLLA : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [], "lla", "$dst, $src">; +// Refer to comment on PseudoLI for explanation of Size=32 +let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 8, isCodeGenOnly = 0, + isAsmParserOnly = 1 in +def PseudoLLAImm : Pseudo<(outs GPR:$dst), (ins ixlenimm_li_restricted:$imm), [], + "lla", "$dst, $imm">; def : Pat<(riscv_lla tglobaladdr:$in), (PseudoLLA tglobaladdr:$in)>; def : Pat<(riscv_lla tblockaddress:$in), (PseudoLLA tblockaddress:$in)>; def : Pat<(riscv_lla tjumptable:$in), (PseudoLLA tjumptable:$in)>; @@ -1622,6 +1632,12 @@ def PseudoLA : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [], "la", "$dst, $src">; +// Refer to comment on PseudoLI for explanation of Size=32 +let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 32, + isCodeGenOnly = 0, isAsmParserOnly = 1 in +def PseudoLAImm : Pseudo<(outs GPR:$rd), (ins ixlenimm_li_restricted:$imm), [], + "la", "$rd, $imm">; + let hasSideEffects = 0, mayLoad = 1, mayStore = 0, Size = 8, isCodeGenOnly = 0, isAsmParserOnly = 1 in def PseudoLA_TLS_IE : Pseudo<(outs GPR:$dst), (ins bare_symbol:$src), [], diff --git a/llvm/test/MC/RISCV/lla-invalid.s b/llvm/test/MC/RISCV/lla-invalid.s deleted file mode 100644 --- a/llvm/test/MC/RISCV/lla-invalid.s +++ /dev/null @@ -1,7 +0,0 @@ -# RUN: not llvm-mc -triple=riscv32 < %s 2>&1 | FileCheck %s -# RUN: not llvm-mc -triple=riscv64 < %s 2>&1 | FileCheck %s - -# Non bare symbols must be rejected -lla a2, %lo(a_symbol) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla a2, %hi(a_symbol) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla a2, foo@plt # CHECK: :[[@LINE]]:17: error: '@plt' operand not valid for instruction diff --git a/llvm/test/MC/RISCV/rv32i-aliases-invalid.s b/llvm/test/MC/RISCV/rv32i-aliases-invalid.s --- a/llvm/test/MC/RISCV/rv32i-aliases-invalid.s +++ b/llvm/test/MC/RISCV/rv32i-aliases-invalid.s @@ -9,6 +9,31 @@ li x0, -2147483649 # CHECK: :[[@LINE]]:8: error: immediate must be an integer in the range [-2147483648, 4294967295] li t4, foo # CHECK: :[[@LINE]]:8: error: immediate must be an integer in the range [-2147483648, 4294967295] +la x0, 4294967296 # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x0, -2147483649 # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la a1, foo+foo # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %hi(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %lo(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %hi(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +la x1, %lo(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] + +lla x0, 4294967296 # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x0, -2147483649 # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla a1, foo+foo # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %hi(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %lo(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %hi(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla x1, %lo(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a bare symbol name or an immediate integer in the range [-2147483648, 4294967295] +lla a2, foo@plt # CHECK: :[[@LINE]]:17: error: '@plt' operand not valid for instruction + negw x1, x2 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}} sext.w x3, x4 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}} zext.w x3, x4 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV64I Base Instruction Set{{$}} diff --git a/llvm/test/MC/RISCV/rv32i-aliases-valid.s b/llvm/test/MC/RISCV/rv32i-aliases-valid.s --- a/llvm/test/MC/RISCV/rv32i-aliases-valid.s +++ b/llvm/test/MC/RISCV/rv32i-aliases-valid.s @@ -113,6 +113,105 @@ # CHECK-OBJ-NOALIAS: addi a0, zero, 8 li a0, CONST +# CHECK-INST: addi a0, zero, 0 +# CHECK-ALIAS: li a0, 0 +la x10, 0 +lla x10, 0 +# CHECK-INST: addi a0, zero, 1 +# CHECK-ALIAS: li a0, 1 +la x10, 1 +lla x10, 1 +# CHECK-INST: addi a0, zero, -1 +# CHECK-ALIAS: li a0, -1 +la x10, -1 +lla x10, -1 +# CHECK-INST: addi a0, zero, 2047 +# CHECK-ALIAS: li a0, 2047 +la x10, 2047 +lla x10, 2047 +# CHECK-INST: addi a0, zero, -2047 +# CHECK-ALIAS: li a0, -2047 +la x10, -2047 +lla x10, -2047 +# CHECK-INST: addi a1, zero, 1 +# CHECK-INST: slli a1, a1, 11 +# CHECK-ALIAS: li a1, 1 +# CHECK-ALIAS: slli a1, a1, 11 +la x11, 2048 +lla x11, 2048 +# CHECK-INST: addi a1, zero, -2048 +# CHECK-ALIAS: li a1, -2048 +la x11, -2048 +lla x11, -2048 +# CHECK-EXPAND: lui a1, 1 +# CHECK-EXPAND: addi a1, a1, -2047 +la x11, 2049 +lla x11, 2049 +# CHECK-EXPAND: lui a1, 1048575 +# CHECK-EXPAND: addi a1, a1, 2047 +la x11, -2049 +lla x11, -2049 +# CHECK-EXPAND: lui a1, 1 +# CHECK-EXPAND: addi a1, a1, -1 +la x11, 4095 +lla x11, 4095 +# CHECK-EXPAND: lui a1, 1048575 +# CHECK-EXPAND: addi a1, a1, 1 +la x11, -4095 +lla x11, -4095 +# CHECK-EXPAND: lui a2, 1 +la x12, 4096 +lla x12, 4096 +# CHECK-EXPAND: lui a2, 1048575 +la x12, -4096 +lla x12, -4096 +# CHECK-EXPAND: lui a2, 1 +# CHECK-EXPAND: addi a2, a2, 1 +la x12, 4097 +lla x12, 4097 +# CHECK-EXPAND: lui a2, 1048575 +# CHECK-EXPAND: addi a2, a2, -1 +la x12, -4097 +lla x12, -4097 +# CHECK-EXPAND: lui a2, 524288 +# CHECK-EXPAND: addi a2, a2, -1 +la x12, 2147483647 +lla x12, 2147483647 +# CHECK-EXPAND: lui a2, 524288 +# CHECK-EXPAND: addi a2, a2, 1 +la x12, -2147483647 +lla x12, -2147483647 +# CHECK-EXPAND: lui a2, 524288 +la x12, -2147483648 +lla x12, -2147483648 +# CHECK-EXPAND: lui a2, 524288 +la x12, -0x80000000 +lla x12, -0x80000000 + +# CHECK-EXPAND: lui a2, 524288 +la x12, 0x80000000 +lla x12, 0x80000000 +# CHECK-INST: addi a2, zero, -1 +# CHECK-ALIAS: li a2, -1 +la x12, 0xFFFFFFFF +lla x12, 0xFFFFFFFF + +.equ CONSTANT, 0x123456 +# CHECK-EXPAND: lui a0, 291 +# CHECK-EXPAND: addi a0, a0, 1110 +la a0, CONSTANT +lla a0, CONSTANT +# CHECK-EXPAND: lui a0, 291 +# CHECK-EXPAND: addi a0, a0, 1111 +la a0, CONSTANT+1 +lla a0, CONSTANT+1 + +.equ CONSTANT, 0x654321 +# CHECK-EXPAND: lui a0, 1620 +# CHECK-EXPAND: addi a0, a0, 801 +la a0, CONSTANT +lla a0, CONSTANT + # CHECK-INST: csrrs t4, instreth, zero # CHECK-ALIAS: rdinstreth t4 rdinstreth x29 diff --git a/llvm/test/MC/RISCV/rv64i-aliases-invalid.s b/llvm/test/MC/RISCV/rv64i-aliases-invalid.s --- a/llvm/test/MC/RISCV/rv64i-aliases-invalid.s +++ b/llvm/test/MC/RISCV/rv64i-aliases-invalid.s @@ -5,6 +5,29 @@ li t5, 0x10000000000000000 # CHECK: :[[@LINE]]:8: error: unknown operand li t4, foo # CHECK: :[[@LINE]]:8: error: operand must be a constant 64-bit integer +la t5, 0x10000000000000000 # CHECK: :[[@LINE]]:8: error: unknown operand +la x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %hi(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %lo(1234) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %hi(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la x1, %lo(foo) # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name +la a1, foo+foo # CHECK: :[[@LINE]]:8: error: operand either must be a constant 64-bit integer or a bare symbol name + +lla t5, 0x10000000000000000 # CHECK: :[[@LINE]]:9: error: unknown operand +lla x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %hi(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %lo(1234) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %hi(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla x1, %lo(foo) # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla a1, foo+foo # CHECK: :[[@LINE]]:9: error: operand either must be a constant 64-bit integer or a bare symbol name +lla a2, foo@plt # CHECK: :[[@LINE]]:17: error: '@plt' operand not valid for instruction + rdinstreth x29 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV32I Base Instruction Set{{$}} rdcycleh x27 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV32I Base Instruction Set{{$}} rdtimeh x28 # CHECK: :[[@LINE]]:1: error: instruction requires the following: RV32I Base Instruction Set{{$}} diff --git a/llvm/test/MC/RISCV/rv64i-aliases-valid.s b/llvm/test/MC/RISCV/rv64i-aliases-valid.s --- a/llvm/test/MC/RISCV/rv64i-aliases-valid.s +++ b/llvm/test/MC/RISCV/rv64i-aliases-valid.s @@ -225,6 +225,231 @@ # CHECK-OBJ-NOALIAS: addi a0, zero, 8 li a0, CONST +# CHECK-INST: addi a0, zero, 0 +# CHECK-ALIAS: li a0, 0 +la x10, 0 +lla x10, 0 +# CHECK-INST: addi a0, zero, 1 +# CHECK-ALIAS: li a0, 1 +la x10, 1 +lla x10, 1 +# CHECK-INST: addi a0, zero, -1 +# CHECK-ALIAS: li a0, -1 +la x10, -1 +lla x10, -1 +# CHECK-INST: addi a0, zero, 2047 +# CHECK-ALIAS: li a0, 2047 +la x10, 2047 +lla x10, 2047 +# CHECK-INST: addi a0, zero, -2047 +# CHECK-ALIAS: li a0, -2047 +la x10, -2047 +lla x10, -2047 +# CHECK-INST: addi a1, zero, 1 +# CHECK-INST: slli a1, a1, 11 +# CHECK-ALIAS: li a1, 1 +# CHECK-ALIAS: slli a1, a1, 11 +la x11, 2048 +lla x11, 2048 +# CHECK-INST: addi a1, zero, -2048 +# CHECK-ALIAS: li a1, -2048 +la x11, -2048 +lla x11, -2048 +# CHECK-EXPAND: lui a1, 1 +# CHECK-EXPAND: addiw a1, a1, -2047 +la x11, 2049 +lla x11, 2049 +# CHECK-EXPAND: lui a1, 1048575 +# CHECK-EXPAND: addiw a1, a1, 2047 +la x11, -2049 +lla x11, -2049 +# CHECK-EXPAND: lui a1, 1 +# CHECK-EXPAND: addiw a1, a1, -1 +la x11, 4095 +lla x11, 4095 +# CHECK-EXPAND: lui a1, 1048575 +# CHECK-EXPAND: addiw a1, a1, 1 +la x11, -4095 +lla x11, -4095 +# CHECK-EXPAND: lui a2, 1 +la x12, 4096 +lla x12, 4096 +# CHECK-EXPAND: lui a2, 1048575 +la x12, -4096 +lla x12, -4096 +# CHECK-EXPAND: lui a2, 1 +# CHECK-EXPAND: addiw a2, a2, 1 +la x12, 4097 +lla x12, 4097 +# CHECK-EXPAND: lui a2, 1048575 +# CHECK-EXPAND: addiw a2, a2, -1 +la x12, -4097 +lla x12, -4097 +# CHECK-EXPAND: lui a2, 524288 +# CHECK-EXPAND: addiw a2, a2, -1 +la x12, 2147483647 +lla x12, 2147483647 +# CHECK-EXPAND: lui a2, 524288 +# CHECK-EXPAND: addiw a2, a2, 1 +la x12, -2147483647 +lla x12, -2147483647 +# CHECK-EXPAND: lui a2, 524288 +la x12, -2147483648 +lla x12, -2147483648 +# CHECK-EXPAND: lui a2, 524288 +la x12, -0x80000000 +lla x12, -0x80000000 + +# CHECK-INST: addi a2, zero, 1 +# CHECK-INST-NEXT: slli a2, a2, 31 +# CHECK-ALIAS: li a2, 1 +# CHECK-ALIAS-NEXT: slli a2, a2, 31 +la x12, 0x80000000 +lla x12, 0x80000000 +# CHECK-INST: addi a2, zero, -1 +# CHECK-INST-NEXT: srli a2, a2, 32 +# CHECK-ALIAS: li a2, -1 +# CHECK-ALIAS-NEXT: srli a2, a2, 32 +la x12, 0xFFFFFFFF +lla x12, 0xFFFFFFFF + +# CHECK-INST: addi t0, zero, 1 +# CHECK-INST-NEXT: slli t0, t0, 32 +# CHECK-ALIAS: li t0, 1 +# CHECK-ALIAS-NEXT: slli t0, t0, 32 +la t0, 0x100000000 +lla t0, 0x100000000 +# CHECK-INST: addi t1, zero, -1 +# CHECK-INST-NEXT: slli t1, t1, 63 +# CHECK-ALIAS: li t1, -1 +# CHECK-ALIAS-NEXT: slli t1, t1, 63 +la t1, 0x8000000000000000 +lla t1, 0x8000000000000000 +# CHECK-INST: addi t1, zero, -1 +# CHECK-INST-NEXT: slli t1, t1, 63 +# CHECK-ALIAS: li t1, -1 +# CHECK-ALIAS-NEXT: slli t1, t1, 63 +la t1, -0x8000000000000000 +lla t1, -0x8000000000000000 +# CHECK-EXPAND: lui t2, 9321 +# CHECK-EXPAND-NEXT: addiw t2, t2, -1329 +# CHECK-EXPAND-NEXT: slli t2, t2, 35 +la t2, 0x1234567800000000 +lla t2, 0x1234567800000000 +# CHECK-INST: addi t3, zero, 7 +# CHECK-INST-NEXT: slli t3, t3, 36 +# CHECK-INST-NEXT: addi t3, t3, 11 +# CHECK-INST-NEXT: slli t3, t3, 24 +# CHECK-INST-NEXT: addi t3, t3, 15 +# CHECK-ALIAS: li t3, 7 +# CHECK-ALIAS-NEXT: slli t3, t3, 36 +# CHECK-ALIAS-NEXT: addi t3, t3, 11 +# CHECK-ALIAS-NEXT: slli t3, t3, 24 +# CHECK-ALIAS-NEXT: addi t3, t3, 15 +la t3, 0x700000000B00000F +lla t3, 0x700000000B00000F +# CHECK-EXPAND: lui t4, 583 +# CHECK-EXPAND-NEXT: addiw t4, t4, -1875 +# CHECK-EXPAND-NEXT: slli t4, t4, 14 +# CHECK-EXPAND-NEXT: addi t4, t4, -947 +# CHECK-EXPAND-NEXT: slli t4, t4, 12 +# CHECK-EXPAND-NEXT: addi t4, t4, 1511 +# CHECK-EXPAND-NEXT: slli t4, t4, 13 +# CHECK-EXPAND-NEXT: addi t4, t4, -272 +la t4, 0x123456789abcdef0 +lla t4, 0x123456789abcdef0 +# CHECK-INST: addi t5, zero, -1 +# CHECK-ALIAS: li t5, -1 +la t5, 0xFFFFFFFFFFFFFFFF +lla t5, 0xFFFFFFFFFFFFFFFF +# CHECK-EXPAND: lui t6, 262145 +# CHECK-EXPAND-NEXT: slli t6, t6, 1 +la t6, 0x80002000 +lla t6, 0x80002000 +# CHECK-EXPAND: lui t0, 262145 +# CHECK-EXPAND-NEXT: slli t0, t0, 2 +la x5, 0x100004000 +lla x5, 0x100004000 +# CHECK-EXPAND: lui t1, 4097 +# CHECK-EXPAND-NEXT: slli t1, t1, 20 +la x6, 0x100100000000 +lla x6, 0x100100000000 +# CHECK-EXPAND: lui t2, 983056 +# CHECK-EXPAND-NEXT: srli t2, t2, 16 +la x7, 0xFFFFFFFFF001 +lla x7, 0xFFFFFFFFF001 +# CHECK-EXPAND: lui s0, 1044481 +# CHECK-EXPAND-NEXT: slli s0, s0, 12 +# CHECK-EXPAND-NEXT: srli s0, s0, 24 +la x8, 0xFFFFFFF001 +lla x8, 0xFFFFFFF001 +# CHECK-EXPAND: lui s1, 4097 +# CHECK-EXPAND-NEXT: slli s1, s1, 20 +# CHECK-EXPAND-NEXT: addi s1, s1, -3 +la x9, 0x1000FFFFFFFD +lla x9, 0x1000FFFFFFFD +# CHECK-INST: addi a0, zero, -1 +# CHECK-INST-NEXT: slli a0, a0, 36 +# CHECK-INST-NEXT: addi a0, a0, 1 +# CHECK-INST-NEXT: slli a0, a0, 25 +# CHECK-INST-NEXT: addi a0, a0, -1 +# CHECK-ALIAS: li a0, -1 +# CHECK-ALIAS-NEXT: slli a0, a0, 36 +# CHECK-ALIAS-NEXT: addi a0, a0, 1 +# CHECK-ALIAS-NEXT: slli a0, a0, 25 +# CHECK-ALIAS-NEXT: addi a0, a0, -1 +la x10, 0xE000000001FFFFFF +lla x10, 0xE000000001FFFFFF +# CHECK-INST: addi a1, zero, -2047 +# CHECK-INST-NEXT: slli a1, a1, 27 +# CHECK-INST-NEXT: addi a1, a1, -1 +# CHECK-INST-NEXT: slli a1, a1, 12 +# CHECK-INST-NEXT: addi a1, a1, 2047 +# CHECK-ALIAS: li a1, -2047 +# CHECK-ALIAS-NEXT: slli a1, a1, 27 +# CHECK-ALIAS-NEXT: addi a1, a1, -1 +# CHECK-ALIAS-NEXT: slli a1, a1, 12 +# CHECK-ALIAS-NEXT: addi a1, a1, 2047 +la x11, 0xFFFC007FFFFFF7FF +lla x11, 0xFFFC007FFFFFF7FF + +# CHECK-INST: lui a2, 349525 +# CHECK-INST-NEXT: addiw a2, a2, 1365 +# CHECK-INST-NEXT: slli a2, a2, 1 +# CHECK-ALIAS: lui a2, 349525 +# CHECK-ALIAS-NEXT: addiw a2, a2, 1365 +# CHECK-ALIAS-NEXT: slli a2, a2, 1 +la x12, 0xaaaaaaaa +lla x12, 0xaaaaaaaa + +# CHECK-INST: lui a3, 699051 +# CHECK-INST-NEXT: addiw a3, a3, -1365 +# CHECK-INST-NEXT: slli a3, a3, 1 +# CHECK-ALIAS: lui a3, 699051 +# CHECK-ALIAS-NEXT: addiw a3, a3, -1365 +# CHECK-ALIAS-NEXT: slli a3, a3, 1 +la x13, 0xffffffff55555556 +lla x13, 0xffffffff55555556 + +# CHECK-S-OBJ-NOALIAS: lui t0, 524288 +# CHECK-S-OBJ-NOALIAS-NEXT: addi t0, t0, -1365 +# CHECK-S-OBJ: lui t0, 524288 +# CHECK-S-OBJ-NEXT: addi t0, t0, -1365 +la x5, -2147485013 +lla x5, -2147485013 + +.equ CONSTANT, 0x123456 +# CHECK-EXPAND: lui a0, 291 +# CHECK-EXPAND: addiw a0, a0, 1110 +la a0, CONSTANT +lla a0, CONSTANT + +.equ CONSTANT, 0x654321 +# CHECK-EXPAND: lui a0, 1620 +# CHECK-EXPAND: addiw a0, a0, 801 +la a0, CONSTANT +lla a0, CONSTANT + # CHECK-INST: subw t6, zero, ra # CHECK-ALIAS: negw t6, ra negw x31, x1 diff --git a/llvm/test/MC/RISCV/rvi-pseudos-invalid.s b/llvm/test/MC/RISCV/rvi-pseudos-invalid.s --- a/llvm/test/MC/RISCV/rvi-pseudos-invalid.s +++ b/llvm/test/MC/RISCV/rvi-pseudos-invalid.s @@ -1,16 +1,6 @@ # RUN: not llvm-mc %s -triple=riscv32 2>&1 | FileCheck %s # RUN: not llvm-mc %s -triple=riscv64 2>&1 | FileCheck %s -lla x1, 1234 # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %hi(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %lo(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %hi(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -lla x1, %lo(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name - lga x1, 1234 # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name lga x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name lga x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name @@ -21,21 +11,9 @@ lga x1, %hi(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name lga x1, %lo(foo) # CHECK: :[[@LINE]]:9: error: operand must be a bare symbol name -la x1, 1234 # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %pcrel_hi(1234) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %pcrel_lo(1234) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %pcrel_hi(foo) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %pcrel_lo(foo) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %hi(1234) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %lo(1234) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %hi(foo) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name -la x1, %lo(foo) # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name - sw a2, %hi(a_symbol), a3 # CHECK: :[[@LINE]]:8: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047] sw a2, %lo(a_symbol), a3 # CHECK: :[[@LINE]]:23: error: invalid operand for instruction sw a2, %lo(a_symbol)(a4), a3 # CHECK: :[[@LINE]]:27: error: invalid operand for instruction # Too few operands must be rejected sw a2, a_symbol # CHECK: :[[@LINE]]:1: error: too few operands for instruction - -la a1, foo+foo # CHECK: :[[@LINE]]:8: error: operand must be a bare symbol name