Skip to content

Commit 33a598e

Browse files
committed
[RISCV] Fix compressing of ymv instruction
1 parent f57e0e9 commit 33a598e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,16 @@ def : CompressPat<(JALR X0, GPRNoX0:$rs1, 0),
10241024
(C_JR GPRNoX0:$rs1)>;
10251025
} // Predicates = [HasStdExtC, NotCapMode]
10261026

1027+
def NotStdExtYCapMode
1028+
: Predicate<"!(Subtarget->hasStdExtY() && Subtarget->hasCapMode())">,
1029+
AssemblerPredicate<
1030+
(any_of (not FeatureStdExtY),(not FeatureCapMode)),
1031+
"NotHasStdExtYAndCapMode">;
1032+
10271033
let Predicates = [HasStdExtCOrZca] in {
1034+
// `c.mv` in capmode is uncompressed to a capability move so we can't compress
1035+
// an integer move to this instruction in this case.
1036+
let Predicates = [HasStdExtCOrZca, NotStdExtYCapMode] in {
10281037
let isCompressOnly = true in {
10291038
def : CompressPat<(ADD GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
10301039
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
@@ -1033,6 +1042,7 @@ def : CompressPat<(ADD GPRNoX0:$rs1, GPRNoX0:$rs2, X0),
10331042
}
10341043
def : CompressPat<(ADDI GPRNoX0:$rs1, GPRNoX0:$rs2, 0),
10351044
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1045+
}
10361046
def : CompressPat<(EBREAK), (C_EBREAK)>;
10371047
def : CompressPat<(UNIMP), (C_UNIMP)>;
10381048
} // Predicates = [HasStdExtCOrZca]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
3+
; RUN: cat %s > %t.tgtattr
4+
; RUN: echo 'attributes #0 = { nounwind }' >> %t.tgtattr
5+
; RUN: %riscv32y_purecap_llc -mattr=+c,+y,+cap-mode -filetype=obj < %t.tgtattr \
6+
; RUN: | llvm-objdump -d -M no-aliases - | FileCheck %s
7+
; RUN: %riscv64y_purecap_llc -mattr=+c,+y,+cap-mode -filetype=obj < %t.tgtattr \
8+
; RUN: | llvm-objdump -d -M no-aliases - | FileCheck %s
9+
; RUN: %riscv64y_purecap_llc -mattr=+c,+y,+cap-mode,+xcheri-norvc -filetype=obj < %t.tgtattr \
10+
; RUN: | llvm-objdump -d -M no-aliases --mattr=+y - | FileCheck %s --check-prefix=CHECK-NORVC
11+
12+
; RUN: cat %s > %t.fnattr
13+
; RUN: echo 'attributes #0 = { nounwind "target-features"="+c,+y,+cap-mode" }' >> %t.fnattr
14+
; RUN: %riscv32y_purecap_llc -filetype=obj < %t.fnattr \
15+
; RUN: | llvm-objdump -d --mattr=+c -M no-aliases - | FileCheck %s
16+
; RUN: %riscv64y_purecap_llc -filetype=obj < %t.fnattr \
17+
; RUN: | llvm-objdump -d --mattr=+c -M no-aliases - | FileCheck %s
18+
; RUN: cat %s > %t.fnattr
19+
; RUN: echo 'attributes #0 = { nounwind "target-features"="+c,+y,+cap-mode,+xcheri-norvc" }' >> %t.fnattr
20+
; RUN: %riscv64y_purecap_llc -filetype=obj < %t.fnattr \
21+
; RUN: | llvm-objdump -d --mattr=+c -M no-aliases --mattr=+y - | FileCheck %s --check-prefix=CHECK-NORVC
22+
23+
24+
define i32 @loadstore(ptr addrspace(200) %intptrarg, ptr addrspace(200) %ptrptrarg) addrspace(200) #0 {
25+
; CHECK-LABEL: <loadstore>:
26+
; CHECK-NEXT: c.cincoffset16csp csp, -32
27+
; CHECK-NEXT: c.lw a2, 0(ca0)
28+
; CHECK-NEXT: c.li a3, 1
29+
; CHECK-NEXT: c.sw a3, 0(ca0)
30+
; CHECK-NEXT: c.lc ca0, 0(ca1)
31+
; CHECK-NEXT: c.sc ca0, 0(ca1)
32+
; CHECK-NEXT: c.scsp ca0, 16(csp)
33+
; CHECK-NEXT: c.lcsp ca0, 16(csp)
34+
; CHECK-NEXT: c.swsp a2, 0(csp)
35+
; CHECK-NEXT: c.lwsp a0, 0(csp)
36+
; CHECK-NEXT: addi a0, a2, 0
37+
; CHECK-NEXT: c.cincoffset16csp csp, 32
38+
; CHECK-NEXT: c.jr cra
39+
; CHECK-NORVC-LABEL: <loadstore>:
40+
; CHECK-NORVC-NEXT: {{[^a-z.]}}addiy csp, csp, -32
41+
; CHECK-NORVC-NEXT: {{[^a-z.]}}lw a2, 0(ca0)
42+
; CHECK-NORVC-NEXT: {{[^a-z.]}}c.li a3, 1
43+
; CHECK-NORVC-NEXT: {{[^a-z.]}}sw a3, 0(ca0)
44+
; CHECK-NORVC-NEXT: {{[^a-z.]}}ly ca0, 0(ca1)
45+
; CHECK-NORVC-NEXT: {{[^a-z.]}}sy ca0, 0(ca1)
46+
; CHECK-NORVC-NEXT: {{[^a-z.]}}sy ca0, 16(csp)
47+
; CHECK-NORVC-NEXT: {{[^a-z.]}}ly ca0, 16(csp)
48+
; CHECK-NORVC-NEXT: {{[^a-z.]}}sw a2, 0(csp)
49+
; CHECK-NORVC-NEXT: {{[^a-z.]}}lw a0, 0(csp)
50+
; CHECK-NORVC-NEXT: {{[^a-z.]}}addi a0, a2, 0
51+
; CHECK-NORVC-NEXT: {{[^a-z.]}}addiy csp, csp, 32
52+
; CHECK-NORVC-NEXT: {{[^a-z.]}}jalr cnull, 0(cra)
53+
%stackptr = alloca ptr addrspace(200), align 16, addrspace(200)
54+
%stackint = alloca i32, align 16, addrspace(200)
55+
%val = load volatile i32, ptr addrspace(200) %intptrarg
56+
store volatile i32 1, ptr addrspace(200) %intptrarg
57+
%ptrval = load volatile ptr addrspace(200), ptr addrspace(200) %ptrptrarg
58+
store volatile ptr addrspace(200) %ptrval, ptr addrspace(200) %ptrptrarg
59+
store volatile ptr addrspace(200) %ptrval, ptr addrspace(200) %stackptr
60+
%stackptrval = load volatile ptr addrspace(200), ptr addrspace(200) %stackptr
61+
store volatile i32 %val, ptr addrspace(200) %stackint
62+
%stackintval = load volatile i32, ptr addrspace(200) %stackint
63+
ret i32 %val
64+
}

0 commit comments

Comments
 (0)