Skip to content

Commit 0fd7555

Browse files
committed
[MERGE #6045 @LouisLaf] Small FG peeps improvement
Merge pull request #6045 from LouisLaf:fgpeeps Branch to next instr wasn't catching the case where this is an uncoalesced label in the way. This triggered an assert in the globopt (issue #5953) which did rely onthe peep to kick in. Fixed it by skipping over labels.
2 parents 3d8465b + f8adb1b commit 0fd7555

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lib/Backend/Peeps.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,25 @@ Peeps::PeepBranch(IR::BranchInstr *branchInstr, bool *const peepedRef)
438438
//
439439
// Remove branch-to-next
440440
//
441+
IR::Instr * instrSkip = instrNext;
442+
while (instrSkip != targetInstr && instrSkip->IsLabelInstr())
443+
{
444+
// Skip adjacent labels
445+
instrSkip = instrSkip->GetNextRealInstrOrLabel();
446+
}
447+
if (instrSkip->IsLabelInstr())
448+
{
449+
if (instrNext == instrSkip)
450+
{
451+
instrSkip = nullptr;
452+
}
453+
else
454+
{
455+
IR::Instr *instrTmp = instrSkip;
456+
instrSkip = instrNext;
457+
instrNext = instrTmp;
458+
}
459+
}
441460
if (targetInstr == instrNext)
442461
{
443462
if (!branchInstr->IsLowered())
@@ -532,7 +551,14 @@ Peeps::PeepBranch(IR::BranchInstr *branchInstr, bool *const peepedRef)
532551
// The branch removal could have exposed a branch to next opportunity.
533552
return Peeps::PeepBranch(instrPrev->AsBranchInstr());
534553
}
535-
return instrNext;
554+
if (instrSkip)
555+
{
556+
return instrSkip;
557+
}
558+
else
559+
{
560+
return instrNext;
561+
}
536562
}
537563
}
538564
else if (branchInstr->IsConditional())

0 commit comments

Comments
 (0)