Skip to content

Commit 6de9fc2

Browse files
committed
[Mips] Add the missing judgment when processing function handleMFLOSlot
In function handleMFLOSlot, we may get a variable LastInstInFunction with a value of true from function getNextMachineInstr and IInSlot may be null which would trigger an assert. So we need to skip this case. Fix #118223.
1 parent 9f75b66 commit 6de9fc2

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

llvm/lib/Target/Mips/MipsBranchExpansion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ bool MipsBranchExpansion::handleMFLOSlot(Pred Predicate, Safe SafeInSlot) {
767767
std::pair<Iter, bool> Res = getNextMachineInstr(std::next(I), &*FI);
768768
LastInstInFunction |= Res.second;
769769
IInSlot = Res.first;
770+
if (LastInstInFunction)
771+
continue;
770772
if (!SafeInSlot(*IInSlot, *I)) {
771773
Changed = true;
772774
TII->insertNop(*(I->getParent()), std::next(I), I->getDebugLoc())
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; RUN: llc -filetype=asm < %s -mcpu=mips2 | FileCheck %s -check-prefixes=MIPS2
2+
;
3+
; Created from the following test case (PR121463) with
4+
; clang -cc1 -triple mips-unknown-freebsd -target-cpu mips2 -O2 -emit-llvm test.c -o test.ll
5+
; int l2arc_feed_secs, l2arc_feed_min_ms, l2arc_write_interval_wrote, l2arc_write_interval_next;
6+
; void l2arc_write_interval() {
7+
; int interval;
8+
; if (l2arc_write_interval_wrote)
9+
; interval = l2arc_feed_min_ms / l2arc_feed_secs;
10+
; l2arc_write_interval_next = interval;
11+
; }
12+
13+
target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
14+
target triple = "mips-unknown-freebsd"
15+
16+
@l2arc_write_interval_wrote = local_unnamed_addr global i32 0, align 4
17+
@l2arc_feed_min_ms = local_unnamed_addr global i32 0, align 4
18+
@l2arc_feed_secs = local_unnamed_addr global i32 0, align 4
19+
@l2arc_write_interval_next = local_unnamed_addr global i32 0, align 4
20+
21+
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none)
22+
define dso_local void @l2arc_write_interval() local_unnamed_addr #0 {
23+
; MIPS2-LABEL: l2arc_write_interval:
24+
; MIPS2: # %bb.0: # %entry
25+
; MIPS2-NEXT: lui $1, %hi(l2arc_write_interval_wrote)
26+
; MIPS2-NEXT: lw $1, %lo(l2arc_write_interval_wrote)($1)
27+
; MIPS2-NEXT: beqz $1, $BB0_2
28+
; MIPS2-NEXT: nop
29+
; MIPS2-NEXT: # %bb.1: # %if.then
30+
; MIPS2-NEXT: lui $1, %hi(l2arc_feed_secs)
31+
; MIPS2-NEXT: lw $1, %lo(l2arc_feed_secs)($1)
32+
; MIPS2-NEXT: lui $2, %hi(l2arc_feed_min_ms)
33+
; MIPS2-NEXT: lw $2, %lo(l2arc_feed_min_ms)($2)
34+
; MIPS2-NEXT: div $zero, $2, $1
35+
; MIPS2-NEXT: teq $1, $zero, 7
36+
; MIPS2-NEXT: mflo $2
37+
; MIPS2-NEXT: j $BB0_3
38+
; MIPS2-NEXT: nop
39+
entry:
40+
%0 = load i32, ptr @l2arc_write_interval_wrote, align 4, !tbaa !2
41+
%tobool.not = icmp eq i32 %0, 0
42+
br i1 %tobool.not, label %if.end, label %if.then
43+
44+
if.then: ; preds = %entry
45+
%1 = load i32, ptr @l2arc_feed_min_ms, align 4, !tbaa !2
46+
%2 = load i32, ptr @l2arc_feed_secs, align 4, !tbaa !2
47+
%div = sdiv i32 %1, %2
48+
br label %if.end
49+
50+
if.end: ; preds = %if.then, %entry
51+
%interval.0 = phi i32 [ %div, %if.then ], [ undef, %entry ]
52+
store i32 %interval.0, ptr @l2arc_write_interval_next, align 4, !tbaa !2
53+
ret void
54+
}
55+
56+
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="mips2" "target-features"="+mips2" }
57+
58+
!llvm.module.flags = !{!0}
59+
!llvm.ident = !{!1}
60+
61+
!0 = !{i32 1, !"wchar_size", i32 4}
62+
!1 = !{!"clang version 20.0.0git ([email protected]:yingopq/llvm-project.git c23f2417dc5f6dc371afb07af5627ec2a9d373a0)"}
63+
!2 = !{!3, !3, i64 0}
64+
!3 = !{!"int", !4, i64 0}
65+
!4 = !{!"omnipotent char", !5, i64 0}
66+
!5 = !{!"Simple C/C++ TBAA"}
67+

0 commit comments

Comments
 (0)