This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Combine (x op 0) -> x for operations with a right identity of 0
ClosedPublic

Authored by paquette on Mar 23 2020, 1:39 PM.

Details

Summary

Implement identity combines for operations like the following:

%a = G_SUB %b, 0

This can just be replaced with %b.

Over CTMark, this gives some minor size improvements at -O3.

Diff Detail

Event Timeline

paquette created this revision.Mar 23 2020, 1:39 PM
arsenm added inline comments.Mar 23 2020, 1:45 PM
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

The people on your twitter poll are insane and MO is the clearly dominant abbreviation

llvm/include/llvm/Target/GlobalISel/Combine.td
198

Why not also handle add at the same time?

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

Why not just getConstantVRegVal?

1554–1556

CombinerHelper seems to be reproducing bits that should belong in MIPatternMatch but I guess this case is fine. MIPatternMatch doesn't try to do any look throughs now.

We should really have an isZeroConstant that will also handle splat vectors

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
5–6

... at the end of the function

aemerson added inline comments.
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

Yes, this is terrible. And for that reason, I'm out.

paquette marked 2 inline comments as done.Mar 23 2020, 4:33 PM
paquette added inline comments.
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

58.93 twitter users agree that MOP is the morally superior abbreviation

llvm/include/llvm/Target/GlobalISel/Combine.td
198

Sure. It didn't show up too often, but I'll add it.

paquette updated this revision to Diff 252182.Mar 23 2020, 5:26 PM
paquette retitled this revision from [GlobalISel] Combine (x - 0) -> x to [GlobalISel] Combine (x op 0) -> x for operations with a right identity of 0.
paquette edited the summary of this revision. (Show Details)
  • Just do every right identity I can think of instead of just G_SUB
  • Use mi_match
  • Keep MOP because it's the right thing to do
arsenm added inline comments.Mar 24 2020, 12:09 PM
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

There's no word beginning with P here

aemerson requested changes to this revision.Mar 24 2020, 12:39 PM
aemerson added a subscriber: aemerson.

I'm back in.

This revision now requires changes to proceed.Mar 24 2020, 12:39 PM

71% of 92 twitter users (65.32 humans) agree that MOP is clearly better than MO, I'm going to stand by my principles here

MOP is

  • Cleaner (it's a mop!)
  • Contains the most important letter in "operand" (P)
  • More fun to say

71% of 92 twitter users (65.32 humans) agree that MOP is clearly better than MO, I'm going to stand by my principles here

MOP is

  • Cleaner (it's a mop!)
  • Contains the most important letter in "operand" (P)
  • More fun to say

I am more objecting to the capitalization for something that is not an acronym. MO>MOp>>MOP

paquette updated this revision to Diff 252419.Mar 24 2020, 1:51 PM

fix obvious misuse of mi_match

keep MOP

aemerson resigned from this revision.Mar 24 2020, 2:14 PM

Changed my mind again, I won't be a part of this.

You know, matchEqualDefs in this very file already uses MOP

arsenm accepted this revision.Mar 30 2020, 1:49 PM

LGTM but MOp still better than MOP

This revision is now accepted and ready to land.Mar 30 2020, 1:49 PM

LGTM too. One day I'm going to change all MOPs to MOp when you're not looking anyway.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2020, 5:30 PM
dsanders added inline comments.Mar 31 2020, 10:17 AM
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

FWIW, I'd prefer it if we didn't invent unconventional conventions when there already is a conventional convention

Also,
grep -rw MO llvm/ | wc -l

5113

grep -rw MOP llvm/ | wc -l

100

grep -rw MOp llvm/ | wc -l

21

:-)

qcolombet added inline comments.
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
226

+1.
MO has been the convention for quite some time now.