This is an archive of the discontinued LLVM Phabricator instance.

GlobalISel: Fix matchEqualDefs for instructions with multiple defs
ClosedPublic

Authored by Petar.Avramovic on Aug 3 2021, 8:46 AM.

Details

Summary

Instructions that produceSameValue produce same values for operands with
same index. matchEqualDefs used to return true for any two values from
different instructions that produce same values. Fix this by checking if
values are defined by operands with the same index.

Diff Detail

Event Timeline

Petar.Avramovic created this revision.Aug 3 2021, 8:46 AM
Petar.Avramovic requested review of this revision.Aug 3 2021, 8:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2021, 8:46 AM
foad added a comment.Aug 3 2021, 9:37 AM

Is this a bug fix or just a missed optimization? Surely matchEqualDefs is not required to return true when two defs have the same value?

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2712

Maybe your new code ought to go here? And maybe it should apply to any instruction with multiple return registers, not just unmerge?

Petar.Avramovic retitled this revision from GlobalISel: Fix CombinerHelper::matchEqualDefs() for unmerge to GlobalISel: Fix matchEqualDefs for instructions with multiple defs.
Petar.Avramovic edited the summary of this revision. (Show Details)

Merge the same instructions case with different instructions that produce same values.
Check for all instructions with multiple defs not only g_unmerge.

This is bug fix, matchEqualDefs always returns true when different I1 and I2 produce same values (missing operand index check).

The bug fix looks good to me. Inline comments are just about optimization.

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2671–2676

I'm not sure if it's a good idea to remove this code.

  • I think it's correct(?)
  • It looks like a useful speed optimization if I1 and I2 happen to be the same instruction.
  • It allows returning true if I1 and I2 refer to the same load or store, otherwise we'd return false below.

Thoughts?
Adding Stas who wrote this code.

2732

If findRegisterDefOperandIdx is slow then it might be worth adding a fast case like: "if I1 only has 1 def, return true". But I'm not sure if it's worth it.

I didn't think about I1 and I2 being same load.

Petar.Avramovic added inline comments.Aug 4 2021, 3:00 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
2732

findRegisterDefOperandIdx simply loops through operands, if it is only one def it will match it in first try. Num operands is already calculated so it is probably a little bit faster in theory but I don't think it is worth it.

foad accepted this revision.Aug 4 2021, 3:35 AM

LGTM, thanks!

This revision is now accepted and ready to land.Aug 4 2021, 3:35 AM