Skip to content

Commit aaac4e0

Browse files
committed
Merging r354672:
------------------------------------------------------------------------ r354672 | petarj | 2019-02-22 06:53:58 -0800 (Fri, 22 Feb 2019) | 13 lines [mips][micromips] fix filling delay slots for PseudoIndirectBranch_MM Filling a delay slot in 32bit jump instructions with a 16bit instruction can cause issues. According to the documentation such an operation is unpredictable. This patch adds opcode Mips::PseudoIndirectBranch_MM alongside Mips::PseudoIndirectBranch and other instructions that are expanded to jr instruction and do not allow a 16bit instruction in their delay slots. Patch by Mirko Brkusanin. Differential Revision: https://reviews.llvm.org/D58507 ------------------------------------------------------------------------ llvm-svn: 358920
1 parent 79c29c6 commit aaac4e0

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
726726
// but we don't have enough information to make that decision.
727727
if (InMicroMipsMode && TII->getInstSizeInBytes(*CurrI) == 2 &&
728728
(Opcode == Mips::JR || Opcode == Mips::PseudoIndirectBranch ||
729+
Opcode == Mips::PseudoIndirectBranch_MM ||
729730
Opcode == Mips::PseudoReturn || Opcode == Mips::TAILCALL))
730731
continue;
731732
// Instructions LWP/SWP and MOVEP should not be in a delay slot as that
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=mipsel-linux-gnu -mattr=+micromips -relocation-model=pic < %s | FileCheck %s
3+
4+
; Test that the delay slot filler correctly handles indirect branches for
5+
; microMIPS in regard to incorrectly using 16bit instructions in delay slots of
6+
; 32bit instructions.
7+
8+
define i32 @test(i32 signext %x, i32 signext %c) {
9+
; CHECK-LABEL: test:
10+
; CHECK: # %bb.0: # %entry
11+
; CHECK-NEXT: lui $2, %hi(_gp_disp)
12+
; CHECK-NEXT: addiu $2, $2, %lo(_gp_disp)
13+
; CHECK-NEXT: addiur2 $5, $5, -1
14+
; CHECK-NEXT: sltiu $1, $5, 4
15+
; CHECK-NEXT: beqz $1, $BB0_3
16+
; CHECK-NEXT: addu $3, $2, $25
17+
; CHECK-NEXT: $BB0_1: # %entry
18+
; CHECK-NEXT: li16 $2, 0
19+
; CHECK-NEXT: sll16 $5, $5, 2
20+
; CHECK-NEXT: lw $6, %got($JTI0_0)($3)
21+
; CHECK-NEXT: addu16 $5, $5, $6
22+
; CHECK-NEXT: lw $5, %lo($JTI0_0)($5)
23+
; CHECK-NEXT: addu16 $3, $5, $3
24+
; CHECK-NEXT: jr $3
25+
; CHECK-NEXT: nop
26+
; CHECK-NEXT: $BB0_2: # %sw.bb2
27+
; CHECK-NEXT: addiur2 $2, $4, 1
28+
; CHECK-NEXT: jrc $ra
29+
; CHECK-NEXT: $BB0_3:
30+
; CHECK-NEXT: move $2, $4
31+
; CHECK-NEXT: jrc $ra
32+
; CHECK-NEXT: $BB0_4: # %sw.bb3
33+
; CHECK-NEXT: addius5 $4, 2
34+
; CHECK-NEXT: move $2, $4
35+
; CHECK-NEXT: jrc $ra
36+
; CHECK-NEXT: $BB0_5: # %sw.bb5
37+
; CHECK-NEXT: addius5 $4, 3
38+
; CHECK-NEXT: move $2, $4
39+
; CHECK-NEXT: $BB0_6: # %for.cond.cleanup
40+
; CHECK-NEXT: jrc $ra
41+
entry:
42+
switch i32 %c, label %sw.epilog [
43+
i32 4, label %sw.bb5
44+
i32 1, label %for.cond.cleanup
45+
i32 2, label %sw.bb2
46+
i32 3, label %sw.bb3
47+
]
48+
49+
sw.bb2:
50+
%add = add nsw i32 %x, 1
51+
br label %sw.epilog
52+
53+
sw.bb3:
54+
%add4 = add nsw i32 %x, 2
55+
br label %sw.epilog
56+
57+
sw.bb5:
58+
%add6 = add nsw i32 %x, 3
59+
br label %sw.epilog
60+
61+
sw.epilog:
62+
%a.0 = phi i32 [ %add6, %sw.bb5 ], [ %add4, %sw.bb3 ], [ %add, %sw.bb2 ], [ %x, %entry ]
63+
br label %for.cond.cleanup
64+
65+
for.cond.cleanup:
66+
%a.028 = phi i32 [ %a.0, %sw.epilog ], [ 0, %entry ]
67+
ret i32 %a.028
68+
}

0 commit comments

Comments
 (0)