This is an archive of the discontinued LLVM Phabricator instance.

MachineCombiner: consider all uses in getLatency()
AbandonedPublic

Authored by artagnon on May 18 2023, 3:32 AM.

Details

Summary

getLatency() was considering only the first use when computing operand
latency. Fix this.

Diff Detail

Event Timeline

artagnon created this revision.May 18 2023, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 3:32 AM
artagnon requested review of this revision.May 18 2023, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 3:32 AM
barannikov88 requested changes to this revision.May 18 2023, 3:43 AM
barannikov88 added a subscriber: barannikov88.
barannikov88 added inline comments.
llvm/lib/CodeGen/MachineCombiner.cpp
224

This change is not correct. MI->uses() is misnomer, it returns everything apart explicit defs. I.e. it returns explicit uses, implicit uses, and implicit defs.

279

This, too. MI->defs()` returns only explicit defs, it does not include implicit ones.

This revision now requires changes to proceed.May 18 2023, 3:43 AM

This will still work because virtual registers cannot be implicit operands, and there is a check for virtualness above.
Still, using defs and uses should be avoided because they have unexpected behavior.
I hope they can be removed someday and then reimplemented correctly w.r.t. implicit operands.

artagnon updated this revision to Diff 523321.May 18 2023, 3:49 AM

Address review by barannikov88

artagnon marked 2 inline comments as done.May 18 2023, 3:50 AM

Shouldn't there be any test changes?
I'm not familiar with this pass and can't help with further review.

llvm/lib/CodeGen/MachineCombiner.cpp
286

(Assuming iterating over all uses is necessary.)
If the register is used by a single instruction multiple times, findRegisterUseOperandIdx will always find the first use.
I think UseMO : MRI->use_[nodbg_]operands(MO.getReg()) should be used instead in the for loop, and UseMO.getOperandNo() here.

artagnon updated this revision to Diff 523345.May 18 2023, 5:03 AM

Address review comments. There are no test changes, but Embench shows a minor improvement in one test.

artagnon marked an inline comment as done.May 18 2023, 5:04 AM

There are no test changes, but Embench shows a minor improvement in one test.

Can this test be reduced and added to the review? I'm afraid this can't proceed without test coverage.

llvm/lib/CodeGen/MachineCombiner.cpp
286

This now gets the operand number of the defining instruction. We need the operand number of the using instruction here; it is likely to be different.
Please consider using use_nodbg_operands. You can get the UseInstr from it by calling UseMO.getParent().

barannikov88 added inline comments.May 18 2023, 5:20 AM
llvm/lib/CodeGen/MachineCombiner.cpp
286

(FWIW NewRoot->findRegisterDefOperandIdx(MO.getReg()) could probably also be simplified to MO.getOperandNo(), but I'm sure. Perhaps there was a reason for not doing so. This is not a change request.)

286

but I'm sure
but I'm not sure

There are no test changes, but Embench shows a minor improvement in one test.

Can this test be reduced and added to the review? I'm afraid this can't proceed without test coverage.

I just re-verified, and there are no benchmark changes either. I'm not sure how to cook up a test for this change.

artagnon abandoned this revision.Jun 2 2023, 7:58 AM