Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Branch Folding pass leaves double unconditional branches to a BB. #2914

Closed Quuxplusone closed 16 years ago

Quuxplusone commented 16 years ago
Bugzilla Link PR2669
Status RESOLVED LATER
Importance P normal
Reported by Heikki Kultala (hkultala@cs.tut.fi)
Reported on 2008-08-12 06:58:25 -0700
Last modified on 2008-10-16 01:36:06 -0700
Version 2.3
Hardware PC Linux
CC dalej@apple.com, evan.cheng@apple.com, llvm-bugs@lists.llvm.org, nicholas@mxc.ca
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
BranchFolding::CanFallThru method documentation states:

"This should return false if it can reach the block after it, but it uses an
explicit branch to do so (e.g. a table jump)."

But in the method there is a code

  // If there is some explicit branch to the fallthrough block, it can obviously
  // reach, even though the branch should get folded to fall through implicitly.
  if (MachineFunction::iterator(TBB) == Fallthrough ||
      MachineFunction::iterator(FBB) == Fallthrough) return true;

Which means it returns true where the documentation states it should return
false.

This return value is later used at OptimizeBlock method

          if (CurFallsThru) {
            MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB));
            CurCond.clear();
            TII->InsertBranch(*MBB, NextBB, 0, CurCond);
          }

So it inserts an additional unconditional branch instruction to the following
BB even though there can already be one unconditional branch instruction to
that.

This is not just a performance problem because this also can make further
TargetInstrInfo::AnalyzeBranch and TargetInstrInfo::RemoveBranch calls fail.
Quuxplusone commented 16 years ago

Heikki, please provide a testcase and reopen.