[PATCH] D48893: [Constants, InstCombine] allow RHS (operand 1) identity constants for binops

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 3 12:41:17 PDT 2018


spatel created this revision.
spatel added reviewers: lebedev.ri, RKSimon, efriedma.
Herald added a subscriber: mcrosier.

This is a follow-up to https://reviews.llvm.org/D48830 to allow more shuffle folding using identity constants. Without this patch, we're only returning identity constants for commutative binops, so we miss opportunities to fold shifts and other binops.

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 4 more opcodes with this patch (shl, lshr, ashr, fdiv). Loosening the div/rem constraint in the shuffle fold will allow 2 more opcodes (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 + 4 + 2 + 3 + 2 = 18.

Note that the more flexible definition for the identity constant shown here almost matches the logic of getDefaultConstantForOpcode() in https://reviews.llvm.org/D28907, so that patch could be reduced assuming this is ok and once we figure out how to handle -0.0 with fadd.


https://reviews.llvm.org/D48893

Files:
  include/llvm/IR/Constants.h
  lib/IR/Constants.cpp
  lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  test/Transforms/InstCombine/shuffle_select.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48893.153953.patch
Type: text/x-patch
Size: 7013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180703/c79e8f5e/attachment.bin>


More information about the llvm-commits mailing list