Skip to content

Commit 2d52a6e

Browse files
dylanmckaydylanmckay
dylanmckay
authored andcommitted
[AVR] When lowering Select8/Select16, put newly generated MBBs in the same spot
Contributed by Dr. Gergő Érdi. Fixes a bug. Raised from (avr-rust/rust-legacy-fork#49). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302973 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 110c682 commit 2d52a6e

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/Target/AVR/AVRISelLowering.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1611,8 +1611,9 @@ AVRTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
16111611
MachineBasicBlock *trueMBB = MF->CreateMachineBasicBlock(LLVM_BB);
16121612
MachineBasicBlock *falseMBB = MF->CreateMachineBasicBlock(LLVM_BB);
16131613

1614-
MachineFunction::iterator I = MBB->getParent()->begin();
1615-
++I;
1614+
MachineFunction::iterator I;
1615+
for (I = MF->begin(); I != MF->end() && &(*I) != MBB; ++I);
1616+
if (I != MF->end()) ++I;
16161617
MF->insert(I, trueMBB);
16171618
MF->insert(I, falseMBB);
16181619

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llc -mcpu=atmega328p < %s -march=avr | FileCheck %s
2+
3+
; CHECK-LABEL: loopy
4+
define internal fastcc void @loopy() {
5+
6+
; In this case, when we expand `Select8`/`Select16`, we should be
7+
; replacing the existing MBB instead of adding a new one.
8+
;
9+
; https://github.com/avr-rust/rust/issues/49
10+
11+
; CHECK: LBB0_1:
12+
; CHECK: LBB0_2:
13+
; CHECK-NOT: LBB0_3:
14+
start:
15+
br label %bb7.preheader
16+
17+
bb7.preheader: ; preds = %bb10, %start
18+
%i = phi i8 [ 0, %start ], [ %j, %bb10 ]
19+
%j = phi i8 [ 1, %start ], [ %next, %bb10 ]
20+
br label %bb10
21+
22+
bb4: ; preds = %bb10
23+
ret void
24+
25+
bb10: ; preds = %bb7.preheader
26+
tail call fastcc void @observe(i8 %i, i8 1)
27+
%0 = icmp ult i8 %j, 20
28+
%1 = zext i1 %0 to i8
29+
%next = add i8 %j, %1
30+
br i1 %0, label %bb7.preheader, label %bb4
31+
32+
}
33+
34+
declare void @observe(i8, i8);
35+

0 commit comments

Comments
 (0)