This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fix operand-complexity-based canonicalization (PR28296)
ClosedPublic

Authored by spatel on Dec 19 2016, 11:25 AM.

Details

Summary

The code comments didn't match the code logic, and we didn't actually distinguish the fake unary (not/neg/fneg) operators from arguments. Adding another level to the weighting scheme provides more structure and can help simplify the pattern matching in InstCombine and other places.

I fixed regressions that would have shown up from this change in:
rL290067
rL290127

But that doesn't mean there are no pattern-matching logic holes left; some combines may just be missing regression tests.

The cmp predicate changes in the LoopVectorize/minmax_reduction.ll test show a potential missed canonicalization for min/max ops.

Should fix:
https://llvm.org/bugs/show_bug.cgi?id=28296

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 81975.Dec 19 2016, 11:25 AM
spatel retitled this revision from to [InstCombine] fix operand-complexity-based canonicalization (PR28296).
spatel updated this object.
spatel added reviewers: majnemer, efriedma, sanjoy, hfinkel.
spatel added a subscriber: llvm-commits.
sanjoy resigned from this revision.Jan 28 2017, 2:04 PM

I don't understand InstCombine well enough to have an opinion on this.

efriedma added inline comments.Feb 2 2017, 2:45 PM
lib/Transforms/InstCombine/InstCombineInternal.h
54 ↗(On Diff #81975)

UnaryInstruction includes a lot of instructions, many of which are not really obvious; please enumerate the specific instructions you care about.

An explanation for why we want to use this ordering, as opposed to RPO order or something like that, would also be nice.

spatel updated this revision to Diff 86953.Feb 3 2017, 6:43 AM

Patch updated:

  1. Added code comment with examples to explain the general motivation for complexity-based canonicalization. I'm not sure what the trade-offs are vs. other schemes, so I didn't add more. Please let me know if you'd like to see something else here.
  1. Limited 'rank 4' to cast ops and fake unary ops (neg/fneg/not). Cast ops are my motivation for this patch because I've seen problems with those patterns at least 3 times. For reference, the earlier rev included all unary ops, and these are the additional types in that bucket:

Instruction::Alloca
Instruction::Load
Instruction::VAArg
Instruction::ExtractValue

There are less test diffs now because we're not distinguishing loads from others instructions.

  1. Updated test diffs.
efriedma accepted this revision.Feb 3 2017, 11:43 AM

LGTM.

This revision is now accepted and ready to land.Feb 3 2017, 11:43 AM
This revision was automatically updated to reflect the committed changes.