This is an archive of the discontinued LLVM Phabricator instance.

[x86] Teach the backend to fold more read-modify-write memory operands to instructions.
ClosedPublic

Authored by chandlerc on Aug 24 2017, 8:41 PM.

Details

Summary

These can't be reasonably matched in tablegen due to the handling of
flags, so we have to do this in C++ code. We only did it for inc and
dec historically, this starts fleshing that out to more interesting
instructions. Notably, this handles transfering operands to add and
sub.

Currently this forces them into a register. The next patch will add
support for keeping immediate operands as immediates. Then I'll extend
this beyond just add and sub.

I'm not super thrilled by the repeated switches in the code but
everything else I tried was really ugly or problematic.

Many thanks to Craig Topper for the suggestions about where to even
begin here and how to make this stuff work.

Diff Detail

Repository
rL LLVM

Event Timeline

chandlerc created this revision.Aug 24 2017, 8:41 PM
craig.topper added inline comments.Aug 24 2017, 10:16 PM
lib/Target/X86/X86ISelDAGToDAG.cpp
2032 ↗(On Diff #112655)

he->the

2044 ↗(On Diff #112655)

Maybe just put back the if statement we had before?

if (MemVT != MVT::i64 && MemVT != MVT::i32 && MemVT != MVT::i16 && MemVT != MVT::8)

return false;
chandlerc marked 2 inline comments as done.

Updates based on review.

Both changes made.

craig.topper added inline comments.Aug 24 2017, 11:12 PM
lib/Target/X86/X86ISelDAGToDAG.cpp
2040 ↗(On Diff #112661)

You can delete this check now. Sorry I meant to mention that.

Another update from review.

chandlerc marked an inline comment as done.Aug 24 2017, 11:30 PM
chandlerc added inline comments.
lib/Target/X86/X86ISelDAGToDAG.cpp
2040 ↗(On Diff #112661)

Doh, of course. Done.

This revision is now accepted and ready to land.Aug 25 2017, 9:42 AM
This revision was automatically updated to reflect the committed changes.
chandlerc marked an inline comment as done.