This is an archive of the discontinued LLVM Phabricator instance.

FastISel: Avoid adding a successor block twice for degenerate IR.
ClosedPublic

Authored by MatzeB on Aug 25 2015, 6:58 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 33165.Aug 25 2015, 6:58 PM
MatzeB retitled this revision from to FastISel: Avoid adding a successor block twice for degenerate IR..
MatzeB updated this object.
MatzeB added reviewers: mcrosier, ributzka.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
mcrosier edited edge metadata.Aug 26 2015, 5:43 AM

Matthias,
Juergen is probably more familiar with FastISel than I these days, but the patch itself looks reasonable. I'll let Juergen give the final LGTM, however.

Is the degenerate IR a result of not running the optimizers (i.e., using -O0)? I'm just trying to understand how we arrived at this situation to determine if this really is the correct place to address the problem.

Chad

I should think that if the input IR is legal, LLVM must not crash. Therefore, ultimately this defensive patch seems appropriate.

But this patch is in response to PR24581, which is about a function with 'optnone' attribute. The goal of optnone is to approximate -O0 even if you didn't say -O0. If optnone is running something it should not, or failing to run something it really should, it's worth knowing. The set of transformations that 'optnone' turns off was determined in a very ad-hoc way and it's *very* possible that there's a missing or extra check somewhere. I'd like to see some kind of description of how the IR got into this state (or failed to get out of it).

Yes this code is the result of an optnone attribute. But in any case this is legal IR and SelectionDAG handles this case in the same way[1], so there is no reason for FastISel to produce invalid MI.

[1] SelectionDAGBuilder.cpp:

// Update successor info
addSuccessorWithWeight(SwitchBB, CB.TrueBB, CB.TrueWeight);
// TrueBB and FalseBB are always different unless the incoming IR is
// degenerate. This only happens when running llc on weird IR.
if (CB.TrueBB != CB.FalseBB)
  addSuccessorWithWeight(SwitchBB, CB.FalseBB, CB.FalseWeight);
mcrosier accepted this revision.Aug 26 2015, 9:52 AM
mcrosier edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Aug 26 2015, 9:52 AM

LGTM.

Obviously, ignore my first comment about deferring to Juergen.. :) This seems quite reasonable.

This revision was automatically updated to reflect the committed changes.