This is an archive of the discontinued LLVM Phabricator instance.

SROA: Don't insert instructions before a PHI
ClosedPublic

Authored by majnemer on Sep 1 2014, 1:30 AM.

Details

Summary

SROA may decide that it needs to insert a bitcast and would set it's
insertion point before a PHI. This will create an invalid module
right quick.

Instead, choose the first insertion point in the basic block that holds
our PHI.

The only testcase that I've got relies on a very specific uselist, I
haven't managed to come up with something nice and simple.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 13136.Sep 1 2014, 1:30 AM
majnemer retitled this revision from to SROA: Don't insert instructions before a PHI.
majnemer updated this object.
majnemer added a reviewer: chandlerc.
majnemer added a subscriber: Unknown Object (MLST).
chandlerc edited edge metadata.Sep 1 2014, 1:40 AM

Needs a test case. Importantly, one triggering both the landing pad case and the PHI node case. =]

majnemer updated this revision to Diff 13137.Sep 1 2014, 3:58 AM
majnemer edited edge metadata.
  • Address review comments.

I don't think it's possible to hit the landingpad case because it can't coexist with a phi. I've added a testcase which reliably triggers the bug.

chandlerc accepted this revision.Sep 1 2014, 1:30 PM
chandlerc edited edge metadata.

Minor tweaks to the test below, thanks!

test/Transforms/SROA/phi-and-select.ll
572 ↗(On Diff #13137)

Need a CHECK-LABEL here.

I would also summarize the salient point of the test -- that we have a foldable PHI feeding a speculatable PHI which requires the rewriting of the speculated PHI to handle insertion when the incoming pointer is itself from a PHI node.

This revision is now accepted and ready to land.Sep 1 2014, 1:30 PM
majnemer closed this revision.Sep 1 2014, 2:29 PM
majnemer updated this revision to Diff 13147.

Closed by commit rL216891 (authored by @majnemer).