Index: lib/Target/RISCV/RISCVInstrInfo.td =================================================================== --- lib/Target/RISCV/RISCVInstrInfo.td +++ lib/Target/RISCV/RISCVInstrInfo.td @@ -615,6 +615,27 @@ def : InstAlias<"csrrc $rd, $csr, $imm", (CSRRCI GPR:$rd, csr_sysreg:$csr, uimm5:$imm)>; } +// The following FP csr instructions are alias instructions from the base ISA. +// They should be supported even if the F extension is not enabled. +// CSR Addresses: 0x003 == fcsr, 0x002 == frm, 0x001 == fflags +// NOTE: "frcsr", "frrm", and "frflags" are more specialized version of "csrr". +def : InstAlias<"frcsr $rd", (CSRRS GPR:$rd, 0x003, X0), 2>; +def : InstAlias<"fscsr $rd, $rs", (CSRRW GPR:$rd, 0x003, GPR:$rs)>; +def : InstAlias<"fscsr $rs", (CSRRW X0, 0x003, GPR:$rs), 2>; + +def : InstAlias<"frrm $rd", (CSRRS GPR:$rd, 0x002, X0), 2>; +def : InstAlias<"fsrm $rd, $rs", (CSRRW GPR:$rd, 0x002, GPR:$rs)>; +def : InstAlias<"fsrm $rs", (CSRRW X0, 0x002, GPR:$rs), 2>; +def : InstAlias<"fsrmi $rd, $imm", (CSRRWI GPR:$rd, 0x002, uimm5:$imm)>; +def : InstAlias<"fsrmi $imm", (CSRRWI X0, 0x002, uimm5:$imm), 2>; + +def : InstAlias<"frflags $rd", (CSRRS GPR:$rd, 0x001, X0), 2>; +def : InstAlias<"fsflags $rd, $rs", (CSRRW GPR:$rd, 0x001, GPR:$rs)>; +def : InstAlias<"fsflags $rs", (CSRRW X0, 0x001, GPR:$rs), 2>; +def : InstAlias<"fsflagsi $rd, $imm", (CSRRWI GPR:$rd, 0x001, uimm5:$imm)>; +def : InstAlias<"fsflagsi $imm", (CSRRWI X0, 0x001, uimm5:$imm), 2>; + + def : InstAlias<"sfence.vma", (SFENCE_VMA X0, X0)>; def : InstAlias<"sfence.vma $rs", (SFENCE_VMA GPR:$rs, X0)>; Index: lib/Target/RISCV/RISCVInstrInfoF.td =================================================================== --- lib/Target/RISCV/RISCVInstrInfoF.td +++ lib/Target/RISCV/RISCVInstrInfoF.td @@ -220,26 +220,6 @@ def : InstAlias<"fge.s $rd, $rs, $rt", (FLE_S GPR:$rd, FPR32:$rt, FPR32:$rs), 0>; -// The following csr instructions actually alias instructions from the base ISA. -// However, it only makes sense to support them when the F extension is enabled. -// CSR Addresses: 0x003 == fcsr, 0x002 == frm, 0x001 == fflags -// NOTE: "frcsr", "frrm", and "frflags" are more specialized version of "csrr". -def : InstAlias<"frcsr $rd", (CSRRS GPR:$rd, 0x003, X0), 2>; -def : InstAlias<"fscsr $rd, $rs", (CSRRW GPR:$rd, 0x003, GPR:$rs)>; -def : InstAlias<"fscsr $rs", (CSRRW X0, 0x003, GPR:$rs), 2>; - -def : InstAlias<"frrm $rd", (CSRRS GPR:$rd, 0x002, X0), 2>; -def : InstAlias<"fsrm $rd, $rs", (CSRRW GPR:$rd, 0x002, GPR:$rs)>; -def : InstAlias<"fsrm $rs", (CSRRW X0, 0x002, GPR:$rs), 2>; -def : InstAlias<"fsrmi $rd, $imm", (CSRRWI GPR:$rd, 0x002, uimm5:$imm)>; -def : InstAlias<"fsrmi $imm", (CSRRWI X0, 0x002, uimm5:$imm), 2>; - -def : InstAlias<"frflags $rd", (CSRRS GPR:$rd, 0x001, X0), 2>; -def : InstAlias<"fsflags $rd, $rs", (CSRRW GPR:$rd, 0x001, GPR:$rs)>; -def : InstAlias<"fsflags $rs", (CSRRW X0, 0x001, GPR:$rs), 2>; -def : InstAlias<"fsflagsi $rd, $imm", (CSRRWI GPR:$rd, 0x001, uimm5:$imm)>; -def : InstAlias<"fsflagsi $imm", (CSRRWI X0, 0x001, uimm5:$imm), 2>; - // fmv.w.x and fmv.x.w were previously known as fmv.s.x and fmv.x.s. Both // spellings should be supported by standard tools. def : MnemonicAlias<"fmv.s.x", "fmv.w.x">; Index: lib/Target/RISCV/RISCVSystemOperands.td =================================================================== --- lib/Target/RISCV/RISCVSystemOperands.td +++ lib/Target/RISCV/RISCVSystemOperands.td @@ -71,11 +71,9 @@ // User Floating-Point CSRs //===-------------------------- -let FeaturesRequired = [{ {RISCV::FeatureStdExtF} }] in { def : SysReg<"fflags", 0x001>; def : SysReg<"frm", 0x002>; def : SysReg<"fcsr", 0x003>; -} //===-------------------------- // User Counter/Timers Index: test/MC/RISCV/csr-aliases.s =================================================================== --- test/MC/RISCV/csr-aliases.s +++ test/MC/RISCV/csr-aliases.s @@ -1,117 +1,67 @@ # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f -riscv-no-aliases - \ +# RUN: | llvm-objdump -d -riscv-no-aliases - \ # RUN: | FileCheck -check-prefix=CHECK-INST %s # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ +# RUN: | llvm-objdump -d - \ # RUN: | FileCheck -check-prefix=CHECK-ALIAS %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-f < %s \ -# RUN: | llvm-objdump -d -mattr=-f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=-f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f -riscv-no-aliases - \ +# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \ +# RUN: | llvm-objdump -d -riscv-no-aliases - \ # RUN: | FileCheck -check-prefix=CHECK-INST %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ +# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \ +# RUN: | llvm-objdump -d - \ # RUN: | FileCheck -check-prefix=CHECK-ALIAS %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=-f < %s \ -# RUN: | llvm-objdump -d -mattr=-f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=-f - \ -# RUN: | FileCheck -check-prefix=CHECK-EXT-F-OFF %s # CHECK-INST: csrrs t0, fcsr, zero # CHECK-ALIAS: frcsr t0 -# CHECK-EXT-F: frcsr t0 -# CHECK-EXT-F-OFF: csrr t0, 3 csrrs t0, 3, zero # CHECK-INST: csrrw t1, fcsr, t2 # CHECK-ALIAS: fscsr t1, t2 -# CHECK-EXT-F-ON: fscsr t1, t2 -# CHECK-EXT-F-OFF: csrrw t1, 3, t2 csrrw t1, 3, t2 # CHECK-INST: csrrw zero, fcsr, t2 # CHECK-ALIAS: fscsr t2 -# CHECK-EXT-F-ON: fscsr t2 -# CHECK-EXT-F-OFF: csrw 3, t2 csrrw zero, 3, t2 # CHECK-INST: csrrw zero, fcsr, t2 # CHECK-ALIAS: fscsr t2 -# CHECK-EXT-F-ON: fscsr t2 -# CHECK-EXT-F-OFF: csrw 3, t2 csrrw zero, 3, t2 # CHECK-INST: csrrw t0, frm, zero # CHECK-ALIAS: fsrm t0, zero -# CHECK-EXT-F-ON: fsrm t0, zero -# CHECK-EXT-F-OFF: csrrw t0, 2, zero csrrw t0, 2, zero # CHECK-INST: csrrw t0, frm, t1 # CHECK-ALIAS: fsrm t0, t1 -# CHECK-EXT-F-ON: fsrm t0, t1 -# CHECK-EXT-F-OFF: csrrw t0, 2, t1 csrrw t0, 2, t1 # CHECK-INST: csrrwi t0, frm, 31 # CHECK-ALIAS: fsrmi t0, 31 -# CHECK-EXT-F-ON: fsrmi t0, 31 -# CHECK-EXT-F-OFF: csrrwi t0, 2, 31 csrrwi t0, 2, 31 # CHECK-INST: csrrwi zero, frm, 31 # CHECK-ALIAS: fsrmi 31 -# CHECK-EXT-F-ON: fsrmi 31 -# CHECK-EXT-F-OFF: csrwi 2, 31 csrrwi zero, 2, 31 # CHECK-INST: csrrs t0, fflags, zero # CHECK-ALIAS: frflags t0 -# CHECK-EXT-F-ON: frflags t0 -# CHECK-EXT-F-OFF: csrr t0, 1 csrrs t0, 1, zero # CHECK-INST: csrrw t0, fflags, t2 # CHECK-ALIAS: fsflags t0, t2 -# CHECK-EXT-F-ON: fsflags t0, t2 -# CHECK-EXT-F-OFF: csrrw t0, 1, t2 csrrw t0, 1, t2 # CHECK-INST: csrrw zero, fflags, t2 # CHECK-ALIAS: fsflags t2 -# CHECK-EXT-F-ON: fsflags t2 -# CHECK-EXT-F-OFF: csrw 1, t2 csrrw zero, 1, t2 # CHECK-INST: csrrwi t0, fflags, 31 # CHECK-ALIAS: fsflagsi t0, 31 -# CHECK-EXT-F: fsflagsi t0, 31 -# CHECK-EXT-F-OFF: csrrwi t0, 1, 31 csrrwi t0, 1, 31 # CHECK-INST: csrrwi zero, fflags, 31 # CHECK-ALIAS: fsflagsi 31 -# CHECK-EXT-F: fsflagsi 31 -# CHECK-EXT-F-OFF: csrwi 1, 31 csrrwi zero, 1, 31 Index: test/MC/RISCV/rv32-user-csr-names.s =================================================================== --- test/MC/RISCV/rv32-user-csr-names.s +++ test/MC/RISCV/rv32-user-csr-names.s @@ -455,3 +455,50 @@ csrrs t1, hpmcounter31h, zero # uimm12 csrrs t2, 0xC9F, zero + + +# User Floating Point CSRs + +# fflags +# name +# CHECK-INST: csrrs t1, fflags, zero +# CHECK-ENC: encoding: [0x73,0x23,0x10,0x00] +# CHECK-INST-ALIAS: frflags t1 +# uimm12 +# CHECK-INST: csrrs t2, fflags, zero +# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x00] +# CHECK-INST-ALIAS: frflags t2 +# name +csrrs t1, fflags, zero +# uimm12 +csrrs t2, 0x001, zero + +# frm +# name +# CHECK-INST: csrrs t1, frm, zero +# CHECK-ENC: encoding: [0x73,0x23,0x20,0x00] +# CHECK-INST-ALIAS: frrm t1 +# uimm12 +# CHECK-INST: csrrs t2, frm, zero +# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x00] +# CHECK-INST-ALIAS: frrm t2 +# name +csrrs t1, frm, zero +# uimm12 +csrrs t2, 0x002, zero + +# fcsr +# name +# CHECK-INST: csrrs t1, fcsr, zero +# CHECK-ENC: encoding: [0x73,0x23,0x30,0x00] +# CHECK-INST-ALIAS: frcsr t1 +# uimm12 +# CHECK-INST: csrrs t2, fcsr, zero +# CHECK-ENC: encoding: [0xf3,0x23,0x30,0x00] +# CHECK-INST-ALIAS: frcsr t2 +# name +csrrs t1, fcsr, zero +# uimm12 +csrrs t2, 0x003, zero + + Index: test/MC/RISCV/rv32i-valid.s =================================================================== --- test/MC/RISCV/rv32i-valid.s +++ test/MC/RISCV/rv32i-valid.s @@ -292,7 +292,7 @@ # CHECK-ASM-AND-OBJ: csrrs s0, cycle, zero # CHECK-ASM: encoding: [0x73,0x24,0x00,0xc0] csrrs s0, 0xc00, x0 -# CHECK-ASM-AND-OBJ: csrrs s3, 1, s5 +# CHECK-ASM-AND-OBJ: csrrs s3, fflags, s5 # CHECK-ASM: encoding: [0xf3,0xa9,0x1a,0x00] csrrs s3, 0x001, s5 # CHECK-ASM-AND-OBJ: csrrc sp, ustatus, ra Index: test/MC/RISCV/rvf-user-csr-names.s =================================================================== --- test/MC/RISCV/rvf-user-csr-names.s +++ /dev/null @@ -1,71 +0,0 @@ -# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -mattr=+f -show-encoding \ -# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+f < %s \ -# RUN: | llvm-objdump -d - \ -# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS-NO-F %s -# -# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -mattr=+f -show-encoding \ -# RUN: | FileCheck -check-prefixes=CHECK-INST,CHECK-ENC %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d -mattr=+f - \ -# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s -# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+f < %s \ -# RUN: | llvm-objdump -d - \ -# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS-NO-F %s - -################################## -# User Floating Pont CSRs -################################## - -# fflags -# name -# CHECK-INST: csrrs t1, fflags, zero -# CHECK-ENC: encoding: [0x73,0x23,0x10,0x00] -# CHECK-INST-ALIAS: frflags t1 -# CHECK-INST-ALIAS-NO-F: csrr t1, 1 -# uimm12 -# CHECK-INST: csrrs t2, fflags, zero -# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x00] -# CHECK-INST-ALIAS: frflags t2 -# CHECK-INST-ALIAS-NO-F: csrr t2, 1 -# name -csrrs t1, fflags, zero -# uimm12 -csrrs t2, 0x001, zero - -# frm -# name -# CHECK-INST: csrrs t1, frm, zero -# CHECK-ENC: encoding: [0x73,0x23,0x20,0x00] -# CHECK-INST-ALIAS: frrm t1 -# CHECK-INST-ALIAS-NO-F: csrr t1, 2 -# uimm12 -# CHECK-INST: csrrs t2, frm, zero -# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x00] -# CHECK-INST-ALIAS: frrm t2 -# CHECK-INST-ALIAS-NO-F: csrr t2, 2 -# name -csrrs t1, frm, zero -# uimm12 -csrrs t2, 0x002, zero - -# fcsr -# name -# CHECK-INST: csrrs t1, fcsr, zero -# CHECK-ENC: encoding: [0x73,0x23,0x30,0x00] -# CHECK-INST-ALIAS: frcsr t1 -# CHECK-INST-ALIAS-NO-F: csrr t1, 3 -# uimm12 -# CHECK-INST: csrrs t2, fcsr, zero -# CHECK-ENC: encoding: [0xf3,0x23,0x30,0x00] -# CHECK-INST-ALIAS: frcsr t2 -# CHECK-INST-ALIAS-NO-F: csrr t2, 3 -# name -csrrs t1, fcsr, zero -# uimm12 -csrrs t2, 0x003, zero - - Index: test/MC/RISCV/user-csr-names-invalid.s =================================================================== --- test/MC/RISCV/user-csr-names-invalid.s +++ test/MC/RISCV/user-csr-names-invalid.s @@ -1,7 +1,5 @@ -# RUN: not llvm-mc -triple riscv32 < %s 2>&1 \ -# RUN: | FileCheck -check-prefix=CHECK-NEED-F %s # RUN: not llvm-mc -triple riscv64 < %s 2>&1 \ -# RUN: | FileCheck -check-prefixes=CHECK-NEED-RV32,CHECK-NEED-F %s +# RUN: | FileCheck -check-prefixes=CHECK-NEED-RV32 %s # These user mode CSR register names are RV32 only. @@ -38,10 +36,3 @@ csrrs t1, hpmcounter29h, zero # CHECK-NEED-RV32: :[[@LINE]]:11: error: system register use requires an option to be enabled csrrs t1, hpmcounter30h, zero # CHECK-NEED-RV32: :[[@LINE]]:11: error: system register use requires an option to be enabled csrrs t1, hpmcounter31h, zero # CHECK-NEED-RV32: :[[@LINE]]:11: error: system register use requires an option to be enabled - -# These user mode CSR register names require F extension. - -csrrs t1, fflags, zero # CHECK-NEED-F: :[[@LINE]]:11: error: system register use requires an option to be enabled -csrrs t1, frm, zero # CHECK-NEED-F: :[[@LINE]]:11: error: system register use requires an option to be enabled -csrrs t1, fcsr, zero # CHECK-NEED-F: :[[@LINE]]:11: error: system register use requires an option to be enabled -