This is an archive of the discontinued LLVM Phabricator instance.

[NFC][X86] `canonicalizeShuffleWithBinOps()`: refactor and generalize, NFC
Needs ReviewPublic

Authored by lebedev.ri on Jan 16 2023, 4:28 PM.

Details

Summary

This is completely NFC.
Follow-ups will enhance this xform to handle binary ops where one operand must be ignored,
and to make those changes easier to review, this is the refactoring-only change.

Diff Detail

Event Timeline

lebedev.ri created this revision.Jan 16 2023, 4:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2023, 4:28 PM
lebedev.ri requested review of this revision.Jan 16 2023, 4:28 PM
RKSimon added inline comments.Jan 17 2023, 8:43 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
40498

Given we know that N0 is a binop - all this generic zip/enumate iteration code seems unnecessary tbh.

@RKSimon if you prefer, you may write these changes by yourself. I can abandon these patches.

llvm/lib/Target/X86/X86ISelLowering.cpp
40498

This is a generalization. Currently, the code does exactly the same,
but the implicit loop is manually unrolled. With unrolled loops,
you suffer the cost of duplicate LOC, having double the LOC to verify for correctness,
and verify that they do the right thing for right "iteration" (operand).
Doing that is counter-productive and anti-general.

In fact, that is the whole reason why LLVM is seeing such an explosion of code size,
because everything is special-coded, instead of having a "few" general utils,
that are both easy to prove to be correct, and don't incur bloat,
and are easy to use, and make easier to write new code.

lebedev.ri marked an inline comment as done.Jan 17 2023, 8:59 AM
lebedev.ri added inline comments.
llvm/lib/Target/X86/X86ISelLowering.cpp
40498

(to be most specific: the code to deal unops is still a specialization of the code
to deal with binops, they can be deduplicated further.)

@RKSimon if you prefer, you may write these changes by yourself. I can abandon these patches.

If you can wait a couple of days - I'm happy to get this done.

@RKSimon if you prefer, you may write these changes by yourself. I can abandon these patches.

If you can wait a couple of days - I'm happy to get this done.

I just don't understand why would anyone write this any other way.
Manual loop unrolling results in more code, and worse code.

lebedev.ri added inline comments.Jan 17 2023, 3:15 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
40504

(Note how we immediately make use of the .index() part in D141806)

@RKSimon just so we can save everyone's time, can you please explain how you request this to look?

Use less smart functions.
@RKSimon is this what you had in mind?