Skip to content

Commit fdef795

Browse files
quic-garvgupttopperc
authored andcommitted
[RISCV] Fix assertion failure when zcmp extension is enabled.
Before accessing "getOpcode" thorugh machine instruction, check if the iterator has reached the end of Machine basic block otherwise we will crash at the assertion `!NodePtr->isKnownSentinel()`. The above assertion is hit in "Prologue/Epilogue Insertion & Frame Finalization pass". Reviewed By: craig.topper, wangpc Differential Revision: https://reviews.llvm.org/D158256
1 parent 2b6160e commit fdef795

File tree

2 files changed

+160
-1
lines changed

2 files changed

+160
-1
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
773773
if (FirstSPAdjustAmount)
774774
StackSize = FirstSPAdjustAmount;
775775

776-
if (RVFI->isPushable(MF) && MBBI->getOpcode() == RISCV::CM_POP) {
776+
if (RVFI->isPushable(MF) && MBBI != MBB.end() &&
777+
MBBI->getOpcode() == RISCV::CM_POP) {
777778
// Use available stack adjustment in pop instruction to deallocate stack
778779
// space.
779780
unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8);
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
2+
# REQUIRES: asserts
3+
# RUN: llc %s -o - -mtriple=riscv32 -mattr=+zcmp -target-abi ilp32 -run-pass=prologepilog \
4+
# RUN: -simplify-mir -verify-machineinstrs | FileCheck %s
5+
6+
--- |
7+
define hidden void @f(fp128 %a) local_unnamed_addr #0 {
8+
entry:
9+
%0 = bitcast fp128 %a to i128
10+
%and.i = lshr i128 %0, 112
11+
%1 = trunc i128 %and.i to i32
12+
%2 = and i32 %1, 32767
13+
%or.i = or i128 poison, 5192296858534827628530496329220096
14+
br label %if.end.i
15+
16+
if.end.i: ; preds = %entry
17+
br i1 poison, label %exit, label %if.then12.i
18+
19+
if.then12.i: ; preds = %if.end.i
20+
%sub13.i = sub nuw nsw i32 16495, %2
21+
%sh_prom.i = zext i32 %sub13.i to i128
22+
%shr14.i = lshr i128 %or.i, %sh_prom.i
23+
%conv15.i = trunc i128 %shr14.i to i32
24+
br label %exit
25+
26+
exit: ; preds = %if.then12.i, %if.end.i
27+
%retval.0.i = phi i32 [ %conv15.i, %if.then12.i ], [ -1, %if.end.i ]
28+
ret void
29+
}
30+
...
31+
---
32+
name: f
33+
alignment: 2
34+
tracksRegLiveness: true
35+
tracksDebugUserValues: true
36+
liveins:
37+
- { reg: '$x10' }
38+
frameInfo:
39+
maxAlignment: 1
40+
localFrameSize: 32
41+
savePoint: '%bb.2'
42+
restorePoint: '%bb.2'
43+
stack:
44+
- { id: 0, size: 32, alignment: 1, local-offset: -32 }
45+
machineFunctionInfo:
46+
varArgsFrameIndex: 0
47+
varArgsSaveSize: 0
48+
body: |
49+
; CHECK-LABEL: name: f
50+
; CHECK: bb.0.entry:
51+
; CHECK-NEXT: liveins: $x10
52+
; CHECK-NEXT: {{ $}}
53+
; CHECK-NEXT: renamable $x10 = ADDI $x0, -1
54+
; CHECK-NEXT: {{ $}}
55+
; CHECK-NEXT: bb.1.if.end.i:
56+
; CHECK-NEXT: liveins: $x10
57+
; CHECK-NEXT: {{ $}}
58+
; CHECK-NEXT: BNE $x0, $x0, %bb.3
59+
; CHECK-NEXT: PseudoBR %bb.2
60+
; CHECK-NEXT: {{ $}}
61+
; CHECK-NEXT: bb.2.if.then12.i:
62+
; CHECK-NEXT: liveins: $x10
63+
; CHECK-NEXT: {{ $}}
64+
; CHECK-NEXT: $x2 = frame-setup ADDI $x2, -32
65+
; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 32
66+
; CHECK-NEXT: SB $x0, $x2, 31 :: (store (s8) into %stack.0 + 31)
67+
; CHECK-NEXT: SB $x0, $x2, 30 :: (store (s8) into %stack.0 + 30)
68+
; CHECK-NEXT: SB $x0, $x2, 29 :: (store (s8) into %stack.0 + 29)
69+
; CHECK-NEXT: SB $x0, $x2, 28 :: (store (s8) into %stack.0 + 28)
70+
; CHECK-NEXT: SB $x0, $x2, 27 :: (store (s8) into %stack.0 + 27)
71+
; CHECK-NEXT: SB $x0, $x2, 26 :: (store (s8) into %stack.0 + 26)
72+
; CHECK-NEXT: SB $x0, $x2, 25 :: (store (s8) into %stack.0 + 25)
73+
; CHECK-NEXT: SB $x0, $x2, 24 :: (store (s8) into %stack.0 + 24)
74+
; CHECK-NEXT: SB $x0, $x2, 23 :: (store (s8) into %stack.0 + 23)
75+
; CHECK-NEXT: SB $x0, $x2, 22 :: (store (s8) into %stack.0 + 22)
76+
; CHECK-NEXT: SB $x0, $x2, 21 :: (store (s8) into %stack.0 + 21)
77+
; CHECK-NEXT: SB $x0, $x2, 20 :: (store (s8) into %stack.0 + 20)
78+
; CHECK-NEXT: SB $x0, $x2, 19 :: (store (s8) into %stack.0 + 19)
79+
; CHECK-NEXT: SB $x0, $x2, 18 :: (store (s8) into %stack.0 + 18)
80+
; CHECK-NEXT: SB $x0, $x2, 17 :: (store (s8) into %stack.0 + 17)
81+
; CHECK-NEXT: SB $x0, $x2, 16 :: (store (s8) into %stack.0 + 16)
82+
; CHECK-NEXT: SB renamable $x10, $x2, 0 :: (store (s8) into %stack.0)
83+
; CHECK-NEXT: SB renamable $x10, $x2, 4 :: (store (s8) into %stack.0 + 4)
84+
; CHECK-NEXT: renamable $x11 = SRLI renamable $x10, 24
85+
; CHECK-NEXT: SB renamable $x11, $x2, 3 :: (store (s8) into %stack.0 + 3)
86+
; CHECK-NEXT: renamable $x12 = SRLI renamable $x10, 16
87+
; CHECK-NEXT: SB renamable $x12, $x2, 2 :: (store (s8) into %stack.0 + 2)
88+
; CHECK-NEXT: renamable $x13 = SRLI renamable $x10, 8
89+
; CHECK-NEXT: SB renamable $x13, $x2, 1 :: (store (s8) into %stack.0 + 1)
90+
; CHECK-NEXT: SB renamable $x10, $x2, 8 :: (store (s8) into %stack.0 + 8)
91+
; CHECK-NEXT: SB renamable $x11, $x2, 7 :: (store (s8) into %stack.0 + 7)
92+
; CHECK-NEXT: SB renamable $x12, $x2, 6 :: (store (s8) into %stack.0 + 6)
93+
; CHECK-NEXT: SB renamable $x13, $x2, 5 :: (store (s8) into %stack.0 + 5)
94+
; CHECK-NEXT: SB killed renamable $x10, $x2, 12 :: (store (s8) into %stack.0 + 12)
95+
; CHECK-NEXT: SB renamable $x11, $x2, 11 :: (store (s8) into %stack.0 + 11)
96+
; CHECK-NEXT: SB renamable $x12, $x2, 10 :: (store (s8) into %stack.0 + 10)
97+
; CHECK-NEXT: SB renamable $x13, $x2, 9 :: (store (s8) into %stack.0 + 9)
98+
; CHECK-NEXT: SB killed renamable $x11, $x2, 15 :: (store (s8) into %stack.0 + 15)
99+
; CHECK-NEXT: SB killed renamable $x12, $x2, 14 :: (store (s8) into %stack.0 + 14)
100+
; CHECK-NEXT: SB killed renamable $x13, $x2, 13 :: (store (s8) into %stack.0 + 13)
101+
; CHECK-NEXT: $x2 = frame-destroy ADDI $x2, 32
102+
; CHECK-NEXT: {{ $}}
103+
; CHECK-NEXT: bb.3.exit:
104+
; CHECK-NEXT: PseudoRET
105+
bb.0.entry:
106+
liveins: $x10
107+
108+
renamable $x10 = ADDI $x0, -1
109+
110+
bb.1.if.end.i:
111+
liveins: $x10
112+
113+
BNE $x0, $x0, %bb.3
114+
PseudoBR %bb.2
115+
116+
bb.2.if.then12.i:
117+
liveins: $x10
118+
119+
SB $x0, %stack.0, 31 :: (store (s8) into %stack.0 + 31)
120+
SB $x0, %stack.0, 30 :: (store (s8) into %stack.0 + 30)
121+
SB $x0, %stack.0, 29 :: (store (s8) into %stack.0 + 29)
122+
SB $x0, %stack.0, 28 :: (store (s8) into %stack.0 + 28)
123+
SB $x0, %stack.0, 27 :: (store (s8) into %stack.0 + 27)
124+
SB $x0, %stack.0, 26 :: (store (s8) into %stack.0 + 26)
125+
SB $x0, %stack.0, 25 :: (store (s8) into %stack.0 + 25)
126+
SB $x0, %stack.0, 24 :: (store (s8) into %stack.0 + 24)
127+
SB $x0, %stack.0, 23 :: (store (s8) into %stack.0 + 23)
128+
SB $x0, %stack.0, 22 :: (store (s8) into %stack.0 + 22)
129+
SB $x0, %stack.0, 21 :: (store (s8) into %stack.0 + 21)
130+
SB $x0, %stack.0, 20 :: (store (s8) into %stack.0 + 20)
131+
SB $x0, %stack.0, 19 :: (store (s8) into %stack.0 + 19)
132+
SB $x0, %stack.0, 18 :: (store (s8) into %stack.0 + 18)
133+
SB $x0, %stack.0, 17 :: (store (s8) into %stack.0 + 17)
134+
SB $x0, %stack.0, 16 :: (store (s8) into %stack.0 + 16)
135+
SB renamable $x10, %stack.0, 0 :: (store (s8) into %stack.0)
136+
SB renamable $x10, %stack.0, 4 :: (store (s8) into %stack.0 + 4)
137+
renamable $x11 = SRLI renamable $x10, 24
138+
SB renamable $x11, %stack.0, 3 :: (store (s8) into %stack.0 + 3)
139+
renamable $x12 = SRLI renamable $x10, 16
140+
SB renamable $x12, %stack.0, 2 :: (store (s8) into %stack.0 + 2)
141+
renamable $x13 = SRLI renamable $x10, 8
142+
SB renamable $x13, %stack.0, 1 :: (store (s8) into %stack.0 + 1)
143+
SB renamable $x10, %stack.0, 8 :: (store (s8) into %stack.0 + 8)
144+
SB renamable $x11, %stack.0, 7 :: (store (s8) into %stack.0 + 7)
145+
SB renamable $x12, %stack.0, 6 :: (store (s8) into %stack.0 + 6)
146+
SB renamable $x13, %stack.0, 5 :: (store (s8) into %stack.0 + 5)
147+
SB killed renamable $x10, %stack.0, 12 :: (store (s8) into %stack.0 + 12)
148+
SB renamable $x11, %stack.0, 11 :: (store (s8) into %stack.0 + 11)
149+
SB renamable $x12, %stack.0, 10 :: (store (s8) into %stack.0 + 10)
150+
SB renamable $x13, %stack.0, 9 :: (store (s8) into %stack.0 + 9)
151+
SB killed renamable $x11, %stack.0, 15 :: (store (s8) into %stack.0 + 15)
152+
SB killed renamable $x12, %stack.0, 14 :: (store (s8) into %stack.0 + 14)
153+
SB killed renamable $x13, %stack.0, 13 :: (store (s8) into %stack.0 + 13)
154+
155+
bb.3.exit:
156+
PseudoRET
157+
158+
...

0 commit comments

Comments
 (0)