Skip to content

Commit d014bf4

Browse files
toppercmahesh-attarde
authored andcommitted
[RISCV] Accept c.slli/c.srli/c.srli with a 0 immediate as hints. (llvm#150689)
These encodings were previously assigned to c.slli64/srli64/srai64, and designated as hints for RV32 and RV64. Those mnemonics no longer appear in the ISA manual after RV128 was removed. The spec now says that c.slli/c.srli/c.srai with an immediate of 0 is a hint. This patch updates the assembler to accept this. I've left the old spelling for backwards compatibility but we disassemble a shift with a zero immediate. The C_SLLI64_HINT/C_SRLI_HINT/C_SRAI_HINT instructions are removed and the predicates for C_SLLI/C_SRLI/C_SRAI not accept a 0 immediate. Fixes llvm#150304
1 parent ea92ff1 commit d014bf4

File tree

6 files changed

+69
-78
lines changed

6 files changed

+69
-78
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class Bcz<bits<3> funct3, string OpcodeStr>
266266
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
267267
class Shift_right<bits<2> funct2, string OpcodeStr>
268268
: RVInst16CB<0b100, 0b01, (outs GPRC:$rd),
269-
(ins GPRC:$rs1, uimmlog2xlennonzero:$imm),
269+
(ins GPRC:$rs1, uimmlog2xlen:$imm),
270270
OpcodeStr, "$rs1, $imm"> {
271271
let Constraints = "$rs1 = $rd";
272272
let Inst{12} = imm{5};
@@ -494,7 +494,7 @@ def C_BNEZ : Bcz<0b111, "c.bnez">, Sched<[WriteJmp, ReadJmp]>;
494494

495495
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
496496
def C_SLLI : RVInst16CI<0b000, 0b10, (outs GPR:$rd_wb),
497-
(ins GPR:$rd, uimmlog2xlennonzero:$imm),
497+
(ins GPR:$rd, uimmlog2xlen:$imm),
498498
"c.slli", "$rd, $imm">,
499499
Sched<[WriteShiftImm, ReadShiftImm]> {
500500
let Constraints = "$rd = $rd_wb";
@@ -612,40 +612,20 @@ def C_NOP_HINT : RVInst16CI<0b000, 0b01, (outs), (ins simm6nonzero:$imm),
612612
let rd = 0;
613613
}
614614

615-
def C_SLLI64_HINT : RVInst16CI<0b000, 0b10, (outs GPR:$rd_wb), (ins GPR:$rd),
616-
"c.slli64", "$rd">,
617-
Sched<[WriteShiftImm, ReadShiftImm]> {
618-
let Constraints = "$rd = $rd_wb";
619-
let imm = 0;
620-
}
621-
622-
def C_SRLI64_HINT : RVInst16CB<0b100, 0b01, (outs GPRC:$rd),
623-
(ins GPRC:$rs1),
624-
"c.srli64", "$rs1">,
625-
Sched<[WriteShiftImm, ReadShiftImm]> {
626-
let Constraints = "$rs1 = $rd";
627-
let Inst{6-2} = 0;
628-
let Inst{11-10} = 0b00;
629-
let Inst{12} = 0;
630-
}
631-
632-
def C_SRAI64_HINT : RVInst16CB<0b100, 0b01, (outs GPRC:$rd),
633-
(ins GPRC:$rs1),
634-
"c.srai64", "$rs1">,
635-
Sched<[WriteShiftImm, ReadShiftImm]> {
636-
let Constraints = "$rs1 = $rd";
637-
let Inst{6-2} = 0;
638-
let Inst{11-10} = 0b01;
639-
let Inst{12} = 0;
640-
}
641-
642615
} // Predicates = [HasStdExtZca], hasSideEffects = 0, mayLoad = 0,
643616
// mayStore = 0
644617

645618
//===----------------------------------------------------------------------===//
646619
// Assembler Pseudo Instructions
647620
//===----------------------------------------------------------------------===//
648621

622+
let Predicates = [HasStdExtZca] in {
623+
// Legacy aliases.
624+
def : InstAlias<"c.slli64 $rd", (C_SLLI GPR:$rd, 0), 0>;
625+
def : InstAlias<"c.srli64 $rs1", (C_SRLI GPRC:$rs1, 0), 0>;
626+
def : InstAlias<"c.srai64 $rs1", (C_SRAI GPRC:$rs1, 0), 0>;
627+
}
628+
649629
let Predicates = [HasStdExtC, HasStdExtZihintntl] in {
650630
def : InstAlias<"c.ntl.p1", (C_ADD X0, X2)>;
651631
def : InstAlias<"c.ntl.pall", (C_ADD X0, X3)>;

llvm/test/MC/Disassembler/RISCV/c_slli.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# RUN: -M no-aliases --show-encoding < %s 2>&1 | \
1515
# RUN: FileCheck --check-prefix=NOHINTS %s
1616

17-
# GOOD: c.slli64 zero
17+
# GOOD: c.slli zero, 0
1818
# NOHINTS: invalid instruction encoding
1919
0x02 0x00
2020

@@ -302,7 +302,7 @@
302302
# NOHINTS: invalid instruction encoding
303303
0x7E 0x10
304304

305-
# GOOD: c.slli64 ra
305+
# GOOD: c.slli ra, 0
306306
0x82 0x00
307307

308308
# GOOD: c.slli ra, 1
@@ -526,7 +526,7 @@
526526
# GOOD64: c.slli ra, 63
527527
0xFE 0x10
528528

529-
# GOOD: c.slli64 sp
529+
# GOOD: c.slli sp, 0
530530
0x02 0x01
531531

532532
# GOOD: c.slli sp, 1
@@ -750,7 +750,7 @@
750750
# GOOD64: c.slli sp, 63
751751
0x7E 0x11
752752

753-
# GOOD: c.slli64 gp
753+
# GOOD: c.slli gp, 0
754754
0x82 0x01
755755

756756
# GOOD: c.slli gp, 1
@@ -974,7 +974,7 @@
974974
# GOOD64: c.slli gp, 63
975975
0xFE 0x11
976976

977-
# GOOD: c.slli64 tp
977+
# GOOD: c.slli tp, 0
978978
0x02 0x02
979979

980980
# GOOD: c.slli tp, 1
@@ -1198,7 +1198,7 @@
11981198
# GOOD64: c.slli tp, 63
11991199
0x7E 0x12
12001200

1201-
# GOOD: c.slli64 t0
1201+
# GOOD: c.slli t0, 0
12021202
0x82 0x02
12031203

12041204
# GOOD: c.slli t0, 1
@@ -1422,7 +1422,7 @@
14221422
# GOOD64: c.slli t0, 63
14231423
0xFE 0x12
14241424

1425-
# GOOD: c.slli64 t1
1425+
# GOOD: c.slli t1, 0
14261426
0x02 0x03
14271427

14281428
# GOOD: c.slli t1, 1
@@ -1646,7 +1646,7 @@
16461646
# GOOD64: c.slli t1, 63
16471647
0x7E 0x13
16481648

1649-
# GOOD: c.slli64 t2
1649+
# GOOD: c.slli t2, 0
16501650
0x82 0x03
16511651

16521652
# GOOD: c.slli t2, 1
@@ -1870,7 +1870,7 @@
18701870
# GOOD64: c.slli t2, 63
18711871
0xFE 0x13
18721872

1873-
# GOOD: c.slli64 s0
1873+
# GOOD: c.slli s0, 0
18741874
0x02 0x04
18751875

18761876
# GOOD: c.slli s0, 1
@@ -2094,7 +2094,7 @@
20942094
# GOOD64: c.slli s0, 63
20952095
0x7E 0x14
20962096

2097-
# GOOD: c.slli64 s1
2097+
# GOOD: c.slli s1, 0
20982098
0x82 0x04
20992099

21002100
# GOOD: c.slli s1, 1
@@ -2318,7 +2318,7 @@
23182318
# GOOD64: c.slli s1, 63
23192319
0xFE 0x14
23202320

2321-
# GOOD: c.slli64 a0
2321+
# GOOD: c.slli a0, 0
23222322
0x02 0x05
23232323

23242324
# GOOD: c.slli a0, 1
@@ -2542,7 +2542,7 @@
25422542
# GOOD64: c.slli a0, 63
25432543
0x7E 0x15
25442544

2545-
# GOOD: c.slli64 a1
2545+
# GOOD: c.slli a1, 0
25462546
0x82 0x05
25472547

25482548
# GOOD: c.slli a1, 1
@@ -2766,7 +2766,7 @@
27662766
# GOOD64: c.slli a1, 63
27672767
0xFE 0x15
27682768

2769-
# GOOD: c.slli64 a2
2769+
# GOOD: c.slli a2, 0
27702770
0x02 0x06
27712771

27722772
# GOOD: c.slli a2, 1
@@ -2990,7 +2990,7 @@
29902990
# GOOD64: c.slli a2, 63
29912991
0x7E 0x16
29922992

2993-
# GOOD: c.slli64 a3
2993+
# GOOD: c.slli a3, 0
29942994
0x82 0x06
29952995

29962996
# GOOD: c.slli a3, 1
@@ -3214,7 +3214,7 @@
32143214
# GOOD64: c.slli a3, 63
32153215
0xFE 0x16
32163216

3217-
# GOOD: c.slli64 a4
3217+
# GOOD: c.slli a4, 0
32183218
0x02 0x07
32193219

32203220
# GOOD: c.slli a4, 1
@@ -3438,7 +3438,7 @@
34383438
# GOOD64: c.slli a4, 63
34393439
0x7E 0x17
34403440

3441-
# GOOD: c.slli64 a5
3441+
# GOOD: c.slli a5, 0
34423442
0x82 0x07
34433443

34443444
# GOOD: c.slli a5, 1
@@ -3662,7 +3662,7 @@
36623662
# GOOD64: c.slli a5, 63
36633663
0xFE 0x17
36643664

3665-
# GOOD: c.slli64 a6
3665+
# GOOD: c.slli a6, 0
36663666
0x02 0x08
36673667

36683668
# GOOD: c.slli a6, 1
@@ -3886,7 +3886,7 @@
38863886
# GOOD64: c.slli a6, 63
38873887
0x7E 0x18
38883888

3889-
# GOOD: c.slli64 a7
3889+
# GOOD: c.slli a7, 0
38903890
0x82 0x08
38913891

38923892
# GOOD: c.slli a7, 1
@@ -4110,7 +4110,7 @@
41104110
# GOOD64: c.slli a7, 63
41114111
0xFE 0x18
41124112

4113-
# GOOD: c.slli64 s2
4113+
# GOOD: c.slli s2, 0
41144114
0x02 0x09
41154115

41164116
# GOOD: c.slli s2, 1
@@ -4334,7 +4334,7 @@
43344334
# GOOD64: c.slli s2, 63
43354335
0x7E 0x19
43364336

4337-
# GOOD: c.slli64 s3
4337+
# GOOD: c.slli s3, 0
43384338
0x82 0x09
43394339

43404340
# GOOD: c.slli s3, 1
@@ -4558,7 +4558,7 @@
45584558
# GOOD64: c.slli s3, 63
45594559
0xFE 0x19
45604560

4561-
# GOOD: c.slli64 s4
4561+
# GOOD: c.slli s4, 0
45624562
0x02 0x0A
45634563

45644564
# GOOD: c.slli s4, 1
@@ -4782,7 +4782,7 @@
47824782
# GOOD64: c.slli s4, 63
47834783
0x7E 0x1A
47844784

4785-
# GOOD: c.slli64 s5
4785+
# GOOD: c.slli s5, 0
47864786
0x82 0x0A
47874787

47884788
# GOOD: c.slli s5, 1
@@ -5006,7 +5006,7 @@
50065006
# GOOD64: c.slli s5, 63
50075007
0xFE 0x1A
50085008

5009-
# GOOD: c.slli64 s6
5009+
# GOOD: c.slli s6, 0
50105010
0x02 0x0B
50115011

50125012
# GOOD: c.slli s6, 1
@@ -5230,7 +5230,7 @@
52305230
# GOOD64: c.slli s6, 63
52315231
0x7E 0x1B
52325232

5233-
# GOOD: c.slli64 s7
5233+
# GOOD: c.slli s7, 0
52345234
0x82 0x0B
52355235

52365236
# GOOD: c.slli s7, 1
@@ -5454,7 +5454,7 @@
54545454
# GOOD64: c.slli s7, 63
54555455
0xFE 0x1B
54565456

5457-
# GOOD: c.slli64 s8
5457+
# GOOD: c.slli s8, 0
54585458
0x02 0x0C
54595459

54605460
# GOOD: c.slli s8, 1
@@ -5678,7 +5678,7 @@
56785678
# GOOD64: c.slli s8, 63
56795679
0x7E 0x1C
56805680

5681-
# GOOD: c.slli64 s9
5681+
# GOOD: c.slli s9, 0
56825682
0x82 0x0C
56835683

56845684
# GOOD: c.slli s9, 1
@@ -5902,7 +5902,7 @@
59025902
# GOOD64: c.slli s9, 63
59035903
0xFE 0x1C
59045904

5905-
# GOOD: c.slli64 s10
5905+
# GOOD: c.slli s10, 0
59065906
0x02 0x0D
59075907

59085908
# GOOD: c.slli s10, 1
@@ -6126,7 +6126,7 @@
61266126
# GOOD64: c.slli s10, 63
61276127
0x7E 0x1D
61286128

6129-
# GOOD: c.slli64 s11
6129+
# GOOD: c.slli s11, 0
61306130
0x82 0x0D
61316131

61326132
# GOOD: c.slli s11, 1
@@ -6350,7 +6350,7 @@
63506350
# GOOD64: c.slli s11, 63
63516351
0xFE 0x1D
63526352

6353-
# GOOD: c.slli64 t3
6353+
# GOOD: c.slli t3, 0
63546354
0x02 0x0E
63556355

63566356
# GOOD: c.slli t3, 1
@@ -6574,7 +6574,7 @@
65746574
# GOOD64: c.slli t3, 63
65756575
0x7E 0x1E
65766576

6577-
# GOOD: c.slli64 t4
6577+
# GOOD: c.slli t4, 0
65786578
0x82 0x0E
65796579

65806580
# GOOD: c.slli t4, 1
@@ -6798,7 +6798,7 @@
67986798
# GOOD64: c.slli t4, 63
67996799
0xFE 0x1E
68006800

6801-
# GOOD: c.slli64 t5
6801+
# GOOD: c.slli t5, 0
68026802
0x02 0x0F
68036803

68046804
# GOOD: c.slli t5, 1
@@ -7022,7 +7022,7 @@
70227022
# GOOD64: c.slli t5, 63
70237023
0x7E 0x1F
70247024

7025-
# GOOD: c.slli64 t6
7025+
# GOOD: c.slli t6, 0
70267026
0x82 0x0F
70277027

70287028
# GOOD: c.slli t6, 1

llvm/test/MC/RISCV/rv32c-invalid.s

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ c.addi16sp t0, 16 # CHECK: :[[@LINE]]:13: error: register must be sp (x2)
3535

3636
# Out of range immediates
3737

38-
## uimmlog2xlennonzero
39-
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
40-
c.srli a0, 32 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
41-
c.srai a0, 0 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 31]
38+
## uimmlog2xlenn
39+
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [0, 31]
40+
c.srli a0, 32 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [0, 31]
4241

4342
## simm6
4443
c.li t0, 128 # CHECK: :[[@LINE]]:10: error: immediate must be an integer in the range [-32, 31]

llvm/test/MC/RISCV/rv64c-invalid.s

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ c.ldsp zero, 4(sp) # CHECK: :[[@LINE]]:9: error: register must be a GPR excludi
1313

1414
# Out of range immediates
1515

16-
## uimmlog2xlennonzero
17-
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
18-
c.srli a0, -1 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
19-
c.srai a0, 0 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [1, 63]
16+
## uimmlog2xlen
17+
c.slli t0, 64 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [0, 63]
18+
c.srli a0, -1 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [0, 63]
2019

2120
## simm6
2221
c.addiw t0, -33 # CHECK: :[[@LINE]]:13: error: immediate must be an integer in the range [-32, 31]

0 commit comments

Comments
 (0)