This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Replace trunc for switch as a sink
ClosedPublic

Authored by samparker on Nov 14 2018, 12:43 AM.

Details

Summary

Truncs are treated as sources if their produce a value of the same type as the one we currently trying to promote. Truncs used to be considered as a sink if their operand was the same value type.

We now allow smaller types in the search, so we should search through truncs that produce a smaller value. These truncs can then be converted to an AND mask.

This leaves sinks as being:

  • points where the value in the register is being observed, such as an icmp, switch or store.
  • points where value types have to match, such as calls and returns.
  • zext are included to ease the transformation and are generally removed later on.

During this change, it also became apart from truncating for sinks was broken: if a sink used a source, its type information had already been lost by the time the truncation happens. So I've changed the method of caching the type information. Most of the changes are cosmetic because IRPromoter now holds all the sets as members, so they don't need to be passed around everywhere. Changes that affect code generation:

  • isSink reports false for truncs and true for switches that have a conditon < TypeSize.
  • ReplaceAllUsers has become a method of IRPromoter.
  • TruncTysMap stores a vector of types, one for each operand.
  • visited truncs are converted to AND masks.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.Nov 14 2018, 12:43 AM

Just a very quick first pass....some nitpicks:

I think it might be useful to add this as comments somewhere:

This leaves sinks as being:

  • points where the value in the register is being observed, such as an icmp, switch or store.
  • points where value types have to match, such as calls and returns.
  • zext are included to ease the transformation and are generally removed later on.
lib/Target/ARM/ARMCodeGenPrepare.cpp
222 ↗(On Diff #173993)

Things have evolved a bit... I think i8 and i16 used to be hardcoded constants here. Perhaps now more correct is to say TypeSize?

SjoerdMeijer added inline comments.Nov 14 2018, 6:46 AM
lib/Target/ARM/ARMCodeGenPrepare.cpp
260 ↗(On Diff #173993)

Are we testing switch instructions?

samparker updated this revision to Diff 174576.Nov 19 2018, 2:39 AM

Added some comments and created a test file for switch statements, which includes existing tests plus a couple of new ones.

SjoerdMeijer accepted this revision.EditedNov 19 2018, 2:49 AM

Thanks, looks okay to me.

This revision is now accepted and ready to land.Nov 19 2018, 2:49 AM
This revision was automatically updated to reflect the committed changes.