[InstCombine] safely allow non-commutative binop identity constant folds
authorSanjay Patel <spatel@rotateright.com>
Tue, 10 Jul 2018 15:12:31 +0000 (15:12 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 10 Jul 2018 15:12:31 +0000 (15:12 +0000)
commit509a1e7a9b444bccc88b57685a0e664f61c37f0e
treeb7c00d106ebc4c670f95ff9edc987ee8e4feab3b
parentac7d10bb0854c8df3ddff0d73c3c6be401150f93
[InstCombine] safely allow non-commutative binop identity constant folds

This was originally intended with D48893, but as discussed there, we
have to make the folds safe from producing extra poison. This should
give the single binop folds the same capabilities as the existing
folds for 2-binops+shuffle.

LLVM binary opcode review: there are a total of 18 binops. There are 7
commutative binops (add, mul, and, or, xor, fadd, fmul) which we already
fold. We're able to fold 6 more opcodes with this patch (shl, lshr, ashr,
fdiv, udiv, sdiv). There are no folds for srem/urem/frem AFAIK. We don't
bother with sub/fsub with constant operand 1 because those are
canonicalized to add/fadd. 7 + 6 + 3 + 2 = 18.

llvm-svn: 336684
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/shuffle_select.ll