From 487399a60f9e4e8263317038d779caa6b68ea61a Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 22 May 2013 09:57:57 +0000 Subject: [PATCH] [SystemZ] Fix thinko in long branch pass MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The original version of the pass could underestimate the length of a backward branch in cases like: alignment to N bytes or more ... relaxable branch A ... foo: (aligned to M= Target.Address) { + if (Address - Target.Address <= MaxBackwardRange) return false; } else { - if (Target.Address - Terminator.Address <= MaxForwardRange) + if (Target.Address - Address <= MaxForwardRange) return false; } @@ -296,7 +300,7 @@ bool SystemZLongBranch::mustRelaxBranch(const TerminatorInfo &Terminator) { bool SystemZLongBranch::mustRelaxABranch() { for (SmallVector::iterator TI = Terminators.begin(), TE = Terminators.end(); TI != TE; ++TI) - if (mustRelaxBranch(*TI)) + if (mustRelaxBranch(*TI, TI->Address)) return true; return false; } @@ -337,12 +341,22 @@ void SystemZLongBranch::relaxBranch(TerminatorInfo &Terminator) { ++LongBranches; } -// Relax any branches that need to be relaxed, under current assumptions. +// Run a shortening pass and relax any branches that need to be relaxed. void SystemZLongBranch::relaxBranches() { - for (SmallVector::iterator TI = Terminators.begin(), - TE = Terminators.end(); TI != TE; ++TI) - if (mustRelaxBranch(*TI)) - relaxBranch(*TI); + SmallVector::iterator TI = Terminators.begin(); + BlockPosition Position(MF->getAlignment()); + for (SmallVector::iterator BI = MBBs.begin(), BE = MBBs.end(); + BI != BE; ++BI) { + skipNonTerminators(Position, *BI); + for (unsigned BTI = 0, BTE = BI->NumTerminators; BTI != BTE; ++BTI) { + assert(Position.Address <= TI->Address && + "Addresses shouldn't go forwards"); + if (mustRelaxBranch(*TI, Position.Address)) + relaxBranch(*TI); + skipTerminator(Position, *TI, false); + ++TI; + } + } } bool SystemZLongBranch::runOnMachineFunction(MachineFunction &F) { -- 2.34.1