Skip to content

Commit e7cad7a

Browse files
author
Jozef Kolek
committedJan 13, 2015
[mips][microMIPS] Fix issue with 16b instructions in jr instruction delay slot
16 bit instructions are not allowed in jr delay slot. Same stands for PseudoIndirectBranch and PseudoReturn. Differential Revision: http://reviews.llvm.org/D6815 llvm-svn: 225798
1 parent bd1d69a commit e7cad7a

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed
 

‎llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ namespace {
210210
template<typename IterTy>
211211
bool searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
212212
RegDefsUses &RegDU, InspectMemInstr &IM,
213-
IterTy &Filler) const;
213+
IterTy &Filler, Iter Slot) const;
214214

215215
/// This function searches in the backward direction for an instruction that
216216
/// can be moved to the delay slot. Returns true on success.
@@ -612,7 +612,7 @@ FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
612612
template<typename IterTy>
613613
bool Filler::searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
614614
RegDefsUses &RegDU, InspectMemInstr& IM,
615-
IterTy &Filler) const {
615+
IterTy &Filler, Iter Slot) const {
616616
for (IterTy I = Begin; I != End; ++I) {
617617
// skip debug value
618618
if (I->isDebugValue())
@@ -640,6 +640,15 @@ bool Filler::searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
640640
continue;
641641
}
642642

643+
bool InMicroMipsMode = TM.getSubtarget<MipsSubtarget>().inMicroMipsMode();
644+
const MipsInstrInfo *TII = static_cast<const MipsInstrInfo *>(
645+
TM.getSubtargetImpl()->getInstrInfo());
646+
unsigned Opcode = (*Slot).getOpcode();
647+
if (InMicroMipsMode && TII->GetInstSizeInBytes(&(*I)) == 2 &&
648+
(Opcode == Mips::JR || Opcode == Mips::PseudoIndirectBranch ||
649+
Opcode == Mips::PseudoReturn))
650+
continue;
651+
643652
Filler = I;
644653
return true;
645654
}
@@ -657,7 +666,8 @@ bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot) const {
657666

658667
RegDU.init(*Slot);
659668

660-
if (!searchRange(MBB, ReverseIter(Slot), MBB.rend(), RegDU, MemDU, Filler))
669+
if (!searchRange(MBB, ReverseIter(Slot), MBB.rend(), RegDU, MemDU, Filler,
670+
Slot))
661671
return false;
662672

663673
MBB.splice(std::next(Slot), &MBB, std::next(Filler).base());
@@ -677,7 +687,7 @@ bool Filler::searchForward(MachineBasicBlock &MBB, Iter Slot) const {
677687

678688
RegDU.setCallerSaved(*Slot);
679689

680-
if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Filler))
690+
if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Filler, Slot))
681691
return false;
682692

683693
MBB.splice(std::next(Slot), &MBB, Filler);
@@ -720,7 +730,8 @@ bool Filler::searchSuccBBs(MachineBasicBlock &MBB, Iter Slot) const {
720730
IM.reset(new MemDefsUses(MFI));
721731
}
722732

723-
if (!searchRange(MBB, SuccBB->begin(), SuccBB->end(), RegDU, *IM, Filler))
733+
if (!searchRange(MBB, SuccBB->begin(), SuccBB->end(), RegDU, *IM, Filler,
734+
Slot))
724735
return false;
725736

726737
insertDelayFiller(Filler, BrMap);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc -march=mipsel -mcpu=mips32r2 -mattr=+micromips \
2+
; RUN: -relocation-model=static -O2 < %s | FileCheck %s
3+
4+
@main.L = internal unnamed_addr constant [3 x i8*] [i8* blockaddress(@main, %L1), i8* blockaddress(@main, %L2), i8* null], align 4
5+
@str = private unnamed_addr constant [2 x i8] c"A\00"
6+
@str2 = private unnamed_addr constant [2 x i8] c"B\00"
7+
8+
define i32 @main() #0 {
9+
entry:
10+
br label %L1
11+
12+
L1: ; preds = %entry, %L1
13+
%i.0 = phi i32 [ 0, %entry ], [ %inc, %L1 ]
14+
%puts = tail call i32 @puts(i8* getelementptr inbounds ([2 x i8]* @str, i32 0, i32 0))
15+
%inc = add i32 %i.0, 1
16+
%arrayidx = getelementptr inbounds [3 x i8*]* @main.L, i32 0, i32 %i.0
17+
%0 = load i8** %arrayidx, align 4, !tbaa !1
18+
indirectbr i8* %0, [label %L1, label %L2]
19+
20+
L2: ; preds = %L1
21+
%puts2 = tail call i32 @puts(i8* getelementptr inbounds ([2 x i8]* @str2, i32 0, i32 0))
22+
ret i32 0
23+
}
24+
25+
declare i32 @puts(i8* nocapture readonly) #1
26+
27+
!1 = !{!2, !2, i64 0}
28+
!2 = !{!"any pointer", !3, i64 0}
29+
!3 = !{!"omnipotent char", !4, i64 0}
30+
!4 = !{!"Simple C/C++ TBAA"}
31+
32+
; CHECK: jr
33+
; CHECK-NEXT: nop
34+
35+
%struct.foostruct = type { [3 x float] }
36+
%struct.barstruct = type { %struct.foostruct, float }
37+
@bar_ary = common global [4 x %struct.barstruct] zeroinitializer, align 4
38+
define float* @spooky(i32 signext %i) #0 {
39+
40+
%safe = getelementptr inbounds [4 x %struct.barstruct]* @bar_ary, i32 0, i32 %i, i32 1
41+
store float 1.420000e+02, float* %safe, align 4, !tbaa !1
42+
ret float* %safe
43+
}
44+
45+
; CHECK: spooky:
46+
; CHECK: jr $ra
47+
; CHECK-NEXT: nop
48+

0 commit comments

Comments
 (0)
Please sign in to comment.