This is an archive of the discontinued LLVM Phabricator instance.

Consolidate MemRefs handling from BranchFolding and correct latent bug
ClosedPublic

Authored by reames on Jan 5 2016, 9:48 PM.

Details

Summary

Move the logic from BranchFolding to use the shared infrastructure for merging MMOs introduced in 256909. This has the effect of making BranchFolding more capable.

In the process, fix a latent bug. The existing handling for merging didn't handle the case where one of the instructions being merged had overflowed and dropped MemRefs. This was a latent bug in the places the code was commoned from, but potentially reachable in BranchFolding.

Once this is in, we're left with a single place to consider implementing MMO unique-ing as proposed in http://reviews.llvm.org/D15230.

Diff Detail

Repository
rL LLVM

Event Timeline

reames updated this revision to Diff 44087.Jan 5 2016, 9:48 PM
reames retitled this revision from to Consolidate MemRefs handling from BranchFolding and correct latent bug.
reames updated this object.
reames added reviewers: atrick, flyingforyou.
reames added a subscriber: llvm-commits.
atrick accepted this revision.Jan 6 2016, 9:01 AM
atrick edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 6 2016, 9:01 AM
gberry added a subscriber: gberry.Jan 6 2016, 9:08 AM

This seems reasonable to me. A couple of minor comments/questions below.

lib/CodeGen/BranchFolding.cpp
796 ↗(On Diff #44087)

I think dropMemRefs() is dead after this change, so it could also be removed.

lib/CodeGen/MachineInstr.cpp
881 ↗(On Diff #44087)

Isn't this going to do pointer equality comparisons instead of the MachineMemOperand::operator==() comparisons that hasIdenticalMMOs() was doing? I don't think these are equivalent since as far as I can tell there is no uniqueing of MachineMemOperands done at creation.

887 ↗(On Diff #44087)

Perhaps NumMemRefs + Other.NumMemRefs would be better?

reames added inline comments.Jan 6 2016, 11:18 AM
lib/CodeGen/BranchFolding.cpp
796 ↗(On Diff #44087)

Good catch.

lib/CodeGen/MachineInstr.cpp
881 ↗(On Diff #44087)

Really good catch. Yep, this was a bug on my part. Will fix.

reames added inline comments.Jan 6 2016, 11:29 AM
lib/CodeGen/BranchFolding.cpp
796 ↗(On Diff #44087)

Actually, after further though, I'm going to leave the routine. The semantic operation it performs is useful and not really clear from any of the other accessors.

I may change my mind when I try to actually introduce the poison state, but that can be part of that review.

gberry added inline comments.Jan 6 2016, 11:31 AM
lib/CodeGen/BranchFolding.cpp
796 ↗(On Diff #44087)

Yeah, I had a similar thought after I sent the original comment.

This revision was automatically updated to reflect the committed changes.