Skip to content

Commit 1dd0811

Browse files
authored
[RISCV] Do not append duplicate Zilsd GPRPair CSR (llvm#200463)
`determineCalleeSaves` can run more than once and as a result we were appending duplicate `Zilsd GPRPair CSR's`. Skip a pair if it is already present in the CSR set.
1 parent f561d59 commit 1dd0811

2 files changed

Lines changed: 141 additions & 1 deletion

File tree

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,10 +1704,15 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
17041704
// Append GPRPair registers for pairs where both sub-registers are in CSR
17051705
// list. Iterate through all GPRPairs and check if both sub-regs are CSRs.
17061706
for (MCPhysReg Pair : RISCV::GPRPairRegClass) {
1707+
// Do not append a pair that's already in the CSR list.
1708+
if (CSRSet.contains(Pair))
1709+
continue;
17071710
MCPhysReg EvenReg = TRI.getSubReg(Pair, RISCV::sub_gpr_even);
17081711
MCPhysReg OddReg = TRI.getSubReg(Pair, RISCV::sub_gpr_odd);
1709-
if (CSRSet.contains(EvenReg) && CSRSet.contains(OddReg))
1712+
if (CSRSet.contains(EvenReg) && CSRSet.contains(OddReg)) {
17101713
NewCSRs.push_back(Pair);
1714+
CSRSet.insert(Pair);
1715+
}
17111716
}
17121717

17131718
MRI.setCalleeSavedRegs(NewCSRs);
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
2+
# RUN: llc -mtriple riscv32 -mattr=+zcmp,+zilsd --run-pass=prologepilog %s -verify-machineinstrs -o - \
3+
# RUN: | FileCheck %s
4+
5+
--- |
6+
declare i32 @foo()
7+
declare void @bar()
8+
9+
; Function Attrs: nounwind optsize
10+
define void @zilsd_dup_csr(ptr %p, i32 %a) #1 {
11+
entry:
12+
%call1 = call i32 @foo()
13+
%0 = alloca i8, i32 %a, align 8
14+
store ptr %0, ptr %p, align 8
15+
tail call void @bar()
16+
ret void
17+
}
18+
19+
...
20+
---
21+
name: zilsd_dup_csr
22+
alignment: 2
23+
exposesReturnsTwice: false
24+
legalized: false
25+
regBankSelected: false
26+
selected: false
27+
failedISel: false
28+
tracksRegLiveness: true
29+
hasWinCFI: false
30+
noPhis: true
31+
isSSA: false
32+
noVRegs: true
33+
hasFakeUses: false
34+
callsEHReturn: false
35+
callsUnwindInit: false
36+
hasEHContTarget: false
37+
hasEHScopes: false
38+
hasEHFunclets: false
39+
isOutlined: false
40+
debugInstrRef: false
41+
failsVerification: false
42+
tracksDebugUserValues: true
43+
registers: []
44+
liveins:
45+
- { reg: '$x10', virtual-reg: '' }
46+
- { reg: '$x11', virtual-reg: '' }
47+
calleeSavedRegisters: [ '$x1', '$x8', '$x9', '$x18', '$x19', '$x20', '$x21',
48+
'$x22', '$x23', '$x24', '$x25', '$x26', '$x27',
49+
'$x8_x9', '$x18_x19', '$x20_x21', '$x22_x23', '$x24_x25',
50+
'$x26_x27' ]
51+
frameInfo:
52+
isFrameAddressTaken: false
53+
isReturnAddressTaken: false
54+
hasStackMap: false
55+
hasPatchPoint: false
56+
stackSize: 0
57+
offsetAdjustment: 0
58+
maxAlignment: 1
59+
adjustsStack: true
60+
hasCalls: true
61+
framePointerPolicy: none
62+
stackProtector: ''
63+
functionContext: ''
64+
maxCallFrameSize: 0
65+
cvBytesOfCalleeSavedRegisters: 0
66+
hasOpaqueSPAdjustment: false
67+
hasVAStart: false
68+
hasMustTailInVarArgFunc: false
69+
hasTailCall: true
70+
isCalleeSavedInfoValid: false
71+
localFrameSize: 0
72+
fixedStack: []
73+
stack:
74+
- { id: 0, name: '', type: variable-sized, offset: 0, alignment: 1, stack-id: default,
75+
callee-saved-register: '', callee-saved-restored: true, local-offset: 0,
76+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
77+
entry_values: []
78+
callSites: []
79+
debugValueSubstitutions: []
80+
constants: []
81+
machineFunctionInfo:
82+
varArgsFrameIndex: 0
83+
varArgsSaveSize: 0
84+
body: |
85+
bb.0.entry:
86+
liveins: $x10, $x11
87+
88+
; CHECK-LABEL: name: zilsd_dup_csr
89+
; CHECK: liveins: $x10, $x11, $x1, $x18_x19
90+
; CHECK-NEXT: {{ $}}
91+
; CHECK-NEXT: frame-setup CM_PUSH 4, 16, implicit-def $x2, implicit $x2, implicit $x1
92+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 32
93+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x1, -4
94+
; CHECK-NEXT: frame-setup SD_RV32 killed $x8_x9, $x2, 8 :: (store (s64) into %stack.1)
95+
; CHECK-NEXT: frame-setup SD_RV32 killed $x18_x19, $x2, 0 :: (store (s64) into %stack.2)
96+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x8, -24
97+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x9, -20
98+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x18, -32
99+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x19, -28
100+
; CHECK-NEXT: $x8 = frame-setup ADDI $x2, 32
101+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa $x8, 0
102+
; CHECK-NEXT: renamable $x9 = COPY $x11
103+
; CHECK-NEXT: renamable $x18 = COPY $x10
104+
; CHECK-NEXT: PseudoCALL target-flags(riscv-call) @foo, csr_ilp32_lp64, implicit-def dead $x1, implicit-def $x2, implicit-def dead $x10
105+
; CHECK-NEXT: renamable $x9 = nuw ADDI killed renamable $x9, 15
106+
; CHECK-NEXT: renamable $x9 = ANDI killed renamable $x9, -16
107+
; CHECK-NEXT: renamable $x10 = SUB $x2, killed renamable $x9
108+
; CHECK-NEXT: $x2 = COPY renamable $x10
109+
; CHECK-NEXT: SW killed renamable $x10, killed renamable $x18, 0 :: (store (s32) into %ir.p, align 8)
110+
; CHECK-NEXT: $x2 = frame-destroy ADDI $x8, -32
111+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION def_cfa $x2, 32
112+
; CHECK-NEXT: $x8_x9 = frame-destroy LD_RV32 $x2, 8 :: (load (s64) from %stack.1)
113+
; CHECK-NEXT: $x18_x19 = frame-destroy LD_RV32 $x2, 0 :: (load (s64) from %stack.2)
114+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION restore $x8
115+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION restore $x9
116+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION restore $x18
117+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION restore $x19
118+
; CHECK-NEXT: frame-destroy CM_POP 4, 16, implicit-def $x2, implicit $x2, implicit-def $x1
119+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION restore $x1
120+
; CHECK-NEXT: frame-destroy CFI_INSTRUCTION def_cfa_offset 0
121+
; CHECK-NEXT: PseudoTAIL target-flags(riscv-call) @bar, csr_ilp32_lp64, implicit $x2
122+
renamable $x9 = COPY $x11
123+
renamable $x18 = COPY $x10
124+
ADJCALLSTACKDOWN 0, 0, implicit-def dead $x2, implicit $x2
125+
PseudoCALL target-flags(riscv-call) @foo, csr_ilp32_lp64, implicit-def dead $x1, implicit-def $x2, implicit-def dead $x10
126+
ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
127+
ADJCALLSTACKDOWN 0, 0, implicit-def dead $x2, implicit $x2
128+
renamable $x9 = nuw ADDI killed renamable $x9, 15
129+
renamable $x9 = ANDI killed renamable $x9, -16
130+
renamable $x10 = SUB $x2, killed renamable $x9
131+
$x2 = COPY renamable $x10
132+
ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
133+
SW killed renamable $x10, killed renamable $x18, 0 :: (store (s32) into %ir.p, align 8)
134+
PseudoTAIL target-flags(riscv-call) @bar, csr_ilp32_lp64, implicit $x2
135+
...

0 commit comments

Comments
 (0)