[InstCombine] use commutative matchers for patterns with commutative operators
authorSanjay Patel <spatel@rotateright.com>
Sun, 18 Dec 2016 18:49:48 +0000 (18:49 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 18 Dec 2016 18:49:48 +0000 (18:49 +0000)
commit2b9d4b4daf773e0a6ce0a3002c6e4125d6bd1c21
treed7781e100c8667c9d695e138ae95cce2619104a2
parent373f9a6a0c95fcdb6ee99eea8450d3cb546921a7
[InstCombine] use commutative matchers for patterns with commutative operators

Background/motivation - I was circling back around to:
https://llvm.org/bugs/show_bug.cgi?id=28296

I made a simple patch for that and noticed some regressions, so added test cases for
those with rL281055, and this is hopefully the minimal fix for just those cases.

But as you can see from the surrounding untouched folds, we are missing commuted patterns
all over the place, and of course there are no regression tests to cover any of those cases.

We could sprinkle "m_c_" dust all over this file and catch most of the missing folds, but
then we still wouldn't have test coverage, and we'd still miss some fraction of commuted
patterns because they require adjustments to the match order.

I'm aware of the concern about the potential compile-time performance impact of adding
matches like this (currently being discussed on llvm-dev), but I don't think there's any
evidence yet to suggest that handling commutative pattern matching more thoroughly is not
a worthwhile goal of InstCombine.

Differential Revision: https://reviews.llvm.org/D24419

llvm-svn: 290067
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/or-xor.ll
llvm/test/Transforms/InstCombine/or.ll
llvm/test/Transforms/InstCombine/xor2.ll