[llvm] 3a2d7d8 - [RISCV] Add Predicate to c.lw/c.sw/c.lwsp/c.swsp InstAliases with no offset.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 26 11:06:07 PDT 2022
Author: Craig Topper
Date: 2022-07-26T11:06:00-07:00
New Revision: 3a2d7d8ad5291102ad98b8269b9c2171d3d58d76
URL: https://github.com/llvm/llvm-project/commit/3a2d7d8ad5291102ad98b8269b9c2171d3d58d76
DIFF: https://github.com/llvm/llvm-project/commit/3a2d7d8ad5291102ad98b8269b9c2171d3d58d76.diff
LOG: [RISCV] Add Predicate to c.lw/c.sw/c.lwsp/c.swsp InstAliases with no offset.
These are aliases that allow the immediate offset to be ommitted.
We had predicates for the RV64, RV32+F, and D versions, but
not the base versions.
I've also re-ordered them to share Predicate lines to improve
readability.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfoC.td
llvm/test/MC/RISCV/rv32c-valid.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
index d204c85d61794..cd1da4360002e 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
@@ -696,52 +696,36 @@ def C_SRAI64_HINT : RVInst16CI<0b100, 0b01, (outs GPRC:$rd_wb),
//===----------------------------------------------------------------------===//
let EmitPriority = 0 in {
-let Predicates = [HasStdExtC, HasStdExtD] in
-def : InstAlias<"c.fld $rd, (${rs1})", (C_FLD FPR64C:$rd, GPRC:$rs1, 0)>;
-
+let Predicates = [HasStdExtC] in {
def : InstAlias<"c.lw $rd, (${rs1})", (C_LW GPRC:$rd, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, HasStdExtF, IsRV32] in
-def : InstAlias<"c.flw $rd, (${rs1})", (C_FLW FPR32C:$rd, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, IsRV64] in
-def : InstAlias<"c.ld $rd, (${rs1})", (C_LD GPRC:$rd, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, HasStdExtD] in
-def : InstAlias<"c.fsd $rs2, (${rs1})", (C_FSD FPR64C:$rs2, GPRC:$rs1, 0)>;
-
def : InstAlias<"c.sw $rs2, (${rs1})", (C_SW GPRC:$rs2, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, HasStdExtF, IsRV32] in
-def : InstAlias<"c.fsw $rs2, (${rs1})", (C_FSW FPR32C:$rs2, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, IsRV64] in
-def : InstAlias<"c.sd $rs2, (${rs1})", (C_SD GPRC:$rs2, GPRC:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, HasStdExtD] in
-def : InstAlias<"c.fldsp $rd, (${rs1})", (C_FLDSP FPR64C:$rd, SP:$rs1, 0)>;
-
def : InstAlias<"c.lwsp $rd, (${rs1})", (C_LWSP GPRC:$rd, SP:$rs1, 0)>;
+def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPRC:$rs2, SP:$rs1, 0)>;
+}
-let Predicates = [HasStdExtC, HasStdExtF, IsRV32] in
-def : InstAlias<"c.flwsp $rd, (${rs1})", (C_FLWSP FPR32C:$rd, SP:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, IsRV64] in
+let Predicates = [HasStdExtC, IsRV64] in {
+def : InstAlias<"c.ld $rd, (${rs1})", (C_LD GPRC:$rd, GPRC:$rs1, 0)>;
+def : InstAlias<"c.sd $rs2, (${rs1})", (C_SD GPRC:$rs2, GPRC:$rs1, 0)>;
def : InstAlias<"c.ldsp $rd, (${rs1})", (C_LDSP GPRC:$rd, SP:$rs1, 0)>;
+def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPRC:$rs2, SP:$rs1, 0)>;
+}
-let Predicates = [HasStdExtC, HasStdExtD] in
-def : InstAlias<"c.fsdsp $rs2, (${rs1})", (C_FSDSP FPR64C:$rs2, SP:$rs1, 0)>;
-
-def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPRC:$rs2, SP:$rs1, 0)>;
-
-let Predicates = [HasStdExtC, HasStdExtF, IsRV32] in
+let Predicates = [HasStdExtC, HasStdExtF, IsRV32] in {
+def : InstAlias<"c.flw $rd, (${rs1})", (C_FLW FPR32C:$rd, GPRC:$rs1, 0)>;
+def : InstAlias<"c.fsw $rs2, (${rs1})", (C_FSW FPR32C:$rs2, GPRC:$rs1, 0)>;
+def : InstAlias<"c.flwsp $rd, (${rs1})", (C_FLWSP FPR32C:$rd, SP:$rs1, 0)>;
def : InstAlias<"c.fswsp $rs2, (${rs1})", (C_FSWSP FPR32C:$rs2, SP:$rs1, 0)>;
+}
-let Predicates = [HasStdExtC, IsRV64] in
-def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPRC:$rs2, SP:$rs1, 0)>;
+let Predicates = [HasStdExtC, HasStdExtD] in {
+def : InstAlias<"c.fld $rd, (${rs1})", (C_FLD FPR64C:$rd, GPRC:$rs1, 0)>;
+def : InstAlias<"c.fsd $rs2, (${rs1})", (C_FSD FPR64C:$rs2, GPRC:$rs1, 0)>;
+def : InstAlias<"c.fldsp $rd, (${rs1})", (C_FLDSP FPR64C:$rd, SP:$rs1, 0)>;
+def : InstAlias<"c.fsdsp $rs2, (${rs1})", (C_FSDSP FPR64C:$rs2, SP:$rs1, 0)>;
}
+} // EmitPriority = 0
-//===----------------------------------------------------------------------===//
+//===----------------------------------------------------------------------===/i
// Compress Instruction tablegen backend.
//===----------------------------------------------------------------------===//
diff --git a/llvm/test/MC/RISCV/rv32c-valid.s b/llvm/test/MC/RISCV/rv32c-valid.s
index 07c935f0721a7..c51ba281a2551 100644
--- a/llvm/test/MC/RISCV/rv32c-valid.s
+++ b/llvm/test/MC/RISCV/rv32c-valid.s
@@ -9,103 +9,155 @@
# RUN: | llvm-objdump --mattr=+c -M no-aliases -d -r - \
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: not llvm-mc -triple riscv32 \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
# TODO: more exhaustive testing of immediate encoding.
# CHECK-ASM-AND-OBJ: c.lwsp ra, 0(sp)
# CHECK-ASM: encoding: [0x82,0x40]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lwsp ra, 0(sp)
# CHECK-ASM-AND-OBJ: c.swsp ra, 252(sp)
# CHECK-ASM: encoding: [0x86,0xdf]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.swsp ra, 252(sp)
# CHECK-ASM-AND-OBJ: c.lw a2, 0(a0)
# CHECK-ASM: encoding: [0x10,0x41]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lw a2, 0(a0)
# CHECK-ASM-AND-OBJ: c.sw a5, 124(a3)
# CHECK-ASM: encoding: [0xfc,0xde]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.sw a5, 124(a3)
-# CHECK-OBJ: c.j 0xfffff808
+# CHECK-ASM-AND-OBJ: c.lwsp s0, 0(sp)
+# CHECK-ASM: encoding: [0x02,0x44]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
+c.lwsp x8, (x2)
+# CHECK-ASM-AND-OBJ: c.swsp s0, 0(sp)
+# CHECK-ASM: encoding: [0x22,0xc0]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
+c.swsp x8, (x2)
+# CHECK-ASM-AND-OBJ: c.lw s0, 0(s1)
+# CHECK-ASM: encoding: [0x80,0x40]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
+c.lw x8, (x9)
+# CHECK-ASM-AND-OBJ: c.sw s0, 0(s1)
+# CHECK-ASM: encoding: [0x80,0xc0]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
+c.sw x8, (x9)
+
+# CHECK-OBJ: c.j 0xfffff810
# CHECK-ASM: c.j -2048
# CHECK-ASM: encoding: [0x01,0xb0]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.j -2048
# CHECK-ASM-AND-OBJ: c.jr a7
# CHECK-ASM: encoding: [0x82,0x88]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.jr a7
# CHECK-ASM-AND-OBJ: c.jalr a1
# CHECK-ASM: encoding: [0x82,0x95]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.jalr a1
-# CHECK-OBJ: c.beqz a3, 0xffffff0e
+# CHECK-OBJ: c.beqz a3, 0xffffff16
# CHECK-ASM: c.beqz a3, -256
# CHECK-ASM: encoding: [0x81,0xd2]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.beqz a3, -256
-# CHECK-OBJ: c.bnez a5, 0x10e
+# CHECK-OBJ: c.bnez a5, 0x116
# CHECK-ASM: c.bnez a5, 254
# CHECK-ASM: encoding: [0xfd,0xef]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.bnez a5, 254
# CHECK-ASM-AND-OBJ: c.li a7, 31
# CHECK-ASM: encoding: [0xfd,0x48]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.li a7, 31
# CHECK-ASM-AND-OBJ: c.addi a3, -32
# CHECK-ASM: encoding: [0x81,0x16]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.addi a3, -32
# CHECK-ASM-AND-OBJ: c.addi16sp sp, -512
# CHECK-ASM: encoding: [0x01,0x71]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.addi16sp sp, -512
# CHECK-ASM-AND-OBJ: c.addi16sp sp, 496
# CHECK-ASM: encoding: [0x7d,0x61]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.addi16sp sp, 496
# CHECK-ASM-AND-OBJ: c.addi4spn a3, sp, 1020
# CHECK-ASM: encoding: [0xf4,0x1f]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.addi4spn a3, sp, 1020
# CHECK-ASM-AND-OBJ: c.addi4spn a3, sp, 4
# CHECK-ASM: encoding: [0x54,0x00]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.addi4spn a3, sp, 4
# CHECK-ASM-AND-OBJ: c.slli a1, 1
# CHECK-ASM: encoding: [0x86,0x05]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.slli a1, 1
# CHECK-ASM-AND-OBJ: c.srli a3, 31
# CHECK-ASM: encoding: [0xfd,0x82]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.srli a3, 31
# CHECK-ASM-AND-OBJ: c.srai a4, 2
# CHECK-ASM: encoding: [0x09,0x87]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.srai a4, 2
# CHECK-ASM-AND-OBJ: c.andi a5, 15
# CHECK-ASM: encoding: [0xbd,0x8b]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.andi a5, 15
# CHECK-ASM-AND-OBJ: c.mv a7, s0
# CHECK-ASM: encoding: [0xa2,0x88]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.mv a7, s0
# CHECK-ASM-AND-OBJ: c.and a1, a2
# CHECK-ASM: encoding: [0xf1,0x8d]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.and a1, a2
# CHECK-ASM-AND-OBJ: c.or a2, a3
# CHECK-ASM: encoding: [0x55,0x8e]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.or a2, a3
# CHECK-ASM-AND-OBJ: c.xor a3, a4
# CHECK-ASM: encoding: [0xb9,0x8e]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.xor a3, a4
# CHECK-ASM-AND-OBJ: c.sub a4, a5
# CHECK-ASM: encoding: [0x1d,0x8f]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.sub a4, a5
# CHECK-ASM-AND-OBJ: c.nop
# CHECK-ASM: encoding: [0x01,0x00]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.nop
# CHECK-ASM-AND-OBJ: c.ebreak
# CHECK-ASM: encoding: [0x02,0x90]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.ebreak
# CHECK-ASM-AND-OBJ: c.lui s0, 1
# CHECK-ASM: encoding: [0x05,0x64]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lui s0, 1
# CHECK-ASM-AND-OBJ: c.lui s0, 31
# CHECK-ASM: encoding: [0x7d,0x64]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lui s0, 31
# CHECK-ASM-AND-OBJ: c.lui s0, 1048544
# CHECK-ASM: encoding: [0x01,0x74]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lui s0, 0xfffe0
# CHECK-ASM-AND-OBJ: c.lui s0, 1048575
# CHECK-ASM: encoding: [0x7d,0x74]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.lui s0, 0xfffff
# CHECK-ASM-AND-OBJ: c.unimp
# CHECK-ASM: encoding: [0x00,0x00]
+# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions)
c.unimp
More information about the llvm-commits
mailing list