Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 783ea2a

Browse files
[Mips][FastISel] Do not duplicate condition while lowering branches
This change fixes the issue that arises when we duplicate condition from the predecessor block. If the condition's arguments are not considered alive across the blocks, fast regalloc gets confused and starts generating reloads from the slots that have never been spilled to. This change also leads to smaller code given that, unlike on architectures with condition codes, on Mips we can branch directly on register value, thus we gain nothing by duplication. Patch by Dragan Mladjenovic. Differential Revision: https://reviews.llvm.org/D48642 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336084 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 16f1820 commit 783ea2a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/Target/Mips/MipsFastISel.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,9 @@ bool MipsFastISel::selectBranch(const Instruction *I) {
951951
//
952952
MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
953953
MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
954-
BI->getCondition();
955954
// For now, just try the simplest case where it's fed by a compare.
956955
if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
957-
unsigned CondReg = createResultReg(&Mips::GPR32RegClass);
958-
if (!emitCmp(CondReg, CI))
959-
return false;
956+
unsigned CondReg = getRegForValue(CI);
960957
BuildMI(*BrBB, FuncInfo.InsertPt, DbgLoc, TII.get(Mips::BGTZ))
961958
.addReg(CondReg)
962959
.addMBB(TBB);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -march=mipsel -relocation-model=pic -O0 -fast-isel=true -mcpu=mips32r2 \
3+
; RUN: < %s -verify-machineinstrs | FileCheck %s
4+
5+
6+
define i32 @foobar(i32*) {
7+
bb0:
8+
; CHECK-LABEL: foobar:
9+
; CHECK: # %bb.0: # %bb0
10+
; CHECK: lw $[[REG0:[0-9]+]], 0($4)
11+
; CHECK-NEXT: sltiu $[[REG1:[0-9]+]], $[[REG0]], 1
12+
; CHECK: sw $[[REG1]], [[SPILL:[0-9]+]]($sp) # 4-byte Folded Spill
13+
%1 = load i32, i32* %0 , align 4
14+
%2 = icmp eq i32 %1, 0
15+
store atomic i32 0, i32* %0 monotonic, align 4
16+
br label %bb1
17+
bb1:
18+
; CHECK: # %bb.1: # %bb1
19+
; CHECK-NEXT: lw $[[REG2:[0-9]+]], [[SPILL]]($sp) # 4-byte Folded Reload
20+
; CHECK-NEXT: bgtz $[[REG2]], $BB0_3
21+
br i1 %2, label %bb2, label %bb3
22+
bb2:
23+
; CHECK: $BB0_3: # %bb2
24+
; CHECK-NEXT: addiu $2, $zero, 1
25+
ret i32 1
26+
bb3:
27+
ret i32 0
28+
}

0 commit comments

Comments
 (0)