[SelectionDAG] Swap commutative binops before constant-based folding
authorHal Finkel <hfinkel@anl.gov>
Sun, 6 Sep 2015 05:42:13 +0000 (05:42 +0000)
committerHal Finkel <hfinkel@anl.gov>
Sun, 6 Sep 2015 05:42:13 +0000 (05:42 +0000)
commit987b4b6f61678a58e344fbed4e5c363ab734815c
tree6e34074735e5b5108453e1dcd95414b7e497c64b
parent9f11e5da345cac0ed3dece4c1c3dee153382fa01
[SelectionDAG] Swap commutative binops before constant-based folding

In searching for a fix for the underlying code-quality bug highlighted by
r246937 (that SDAG simplification can lead to us generating an ISD::OR node
with a constant zero LHS), I ran across this:

We generically canonicalize commutative binary-operation nodes in SDAG getNode
so that, if only one operand is a constant, it will be on the RHS.  However, we
were doing this only after a bunch of constant-based simplification checks that
all assume this canonical form (that any constant will be on the RHS). Moving
the operand-swapping canonicalization prior to these checks seems like the
right thing to do (and, as it turns out, causes SDAG to completely fold away the
computation in test/CodeGen/ARM/2012-11-14-subs_carry.ll, just like InstCombine
would do).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246938 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
test/CodeGen/ARM/2012-11-14-subs_carry.ll