Skip to content

[Mips] Add the missing judgment when processing function handleMFLOSlot #121463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/lib/Target/Mips/MipsBranchExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ bool MipsBranchExpansion::handleMFLOSlot(Pred Predicate, Safe SafeInSlot) {
std::pair<Iter, bool> Res = getNextMachineInstr(std::next(I), &*FI);
LastInstInFunction |= Res.second;
IInSlot = Res.first;
if (LastInstInFunction)
continue;
if (!SafeInSlot(*IInSlot, *I)) {
Changed = true;
TII->insertNop(*(I->getParent()), std::next(I), I->getDebugLoc())
Expand Down
50 changes: 50 additions & 0 deletions llvm/test/CodeGen/Mips/llvm-ir/sdiv-freebsd.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
; RUN: llc --mtriple=mips-unknown-freebsd -mcpu=mips2 -filetype=asm < %s -mcpu=mips2 | FileCheck %s -check-prefixes=MIPS2
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the IR file simple.
we can use

RUN: llc -filetype=asm --mtriple=mips -mcpu=mips2 < %s | FileCheck %s -check-prefixes=MIPS2

So that we won't need

target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
target triple = "mips-unknown-freebsd"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, applied.

; Created from the following test case (PR121463) with
; clang -cc1 -triple mips-unknown-freebsd -target-cpu mips2 -O2 -emit-llvm test.c -o test.ll
; int l2arc_feed_secs, l2arc_feed_min_ms, l2arc_write_interval_wrote, l2arc_write_interval_next;
; void l2arc_write_interval() {
; int interval = 0;
; if (l2arc_write_interval_wrote)
; interval = l2arc_feed_min_ms / l2arc_feed_secs;
; l2arc_write_interval_next = interval;
; }

@l2arc_write_interval_wrote = local_unnamed_addr global i32 0, align 4
@l2arc_feed_min_ms = local_unnamed_addr global i32 0, align 4
@l2arc_feed_secs = local_unnamed_addr global i32 0, align 4
@l2arc_write_interval_next = local_unnamed_addr global i32 0, align 4

define dso_local void @l2arc_write_interval() local_unnamed_addr #0 {
; MIPS2-LABEL: l2arc_write_interval:
; MIPS2: # %bb.0: # %entry
; MIPS2-NEXT: lui $1, %hi(l2arc_write_interval_wrote)
; MIPS2-NEXT: lw $1, %lo(l2arc_write_interval_wrote)($1)
; MIPS2-NEXT: beqz $1, $BB0_2
; MIPS2-NEXT: nop
; MIPS2-NEXT: # %bb.1: # %if.then
; MIPS2-NEXT: lui $1, %hi(l2arc_feed_secs)
; MIPS2-NEXT: lw $1, %lo(l2arc_feed_secs)($1)
; MIPS2-NEXT: lui $2, %hi(l2arc_feed_min_ms)
; MIPS2-NEXT: lw $2, %lo(l2arc_feed_min_ms)($2)
; MIPS2-NEXT: div $zero, $2, $1
; MIPS2-NEXT: teq $1, $zero, 7
; MIPS2-NEXT: mflo $2
; MIPS2-NEXT: j $BB0_3
; MIPS2-NEXT: nop
entry:
%0 = load i32, ptr @l2arc_write_interval_wrote, align 4
%tobool.not = icmp eq i32 %0, 0
br i1 %tobool.not, label %if.end, label %if.then

if.then: ; preds = %entry
%1 = load i32, ptr @l2arc_feed_min_ms, align 4
%2 = load i32, ptr @l2arc_feed_secs, align 4
%div = sdiv i32 %1, %2
br label %if.end

if.end: ; preds = %if.then, %entry
%interval.0 = phi i32 [ %div, %if.then ], [ 0, %entry ]
store i32 %interval.0, ptr @l2arc_write_interval_next, align 4
ret void
}
Loading