[PATCH] D82474: [VectorCombine] try to form vector compare and binop to eliminate scalar ops

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 09:10:03 PDT 2020


spatel created this revision.
spatel added reviewers: RKSimon, lebedev.ri, craig.topper.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.

binop i1 (cmp Pred (ext X, Index0), C0), (cmp Pred (ext X, Index1), C1)
-->
vcmp = cmp Pred X, VecC
ext (binop vNi1 vcmp, (shuffle vcmp, Index1)), Index0

This is a larger pattern than the existing extractelement folds because we can't reasonably vectorize the sub-patterns with constants based on cost model calcs (it doesn't usually make sense to replace a single extracted scalar op with constant operand with a vector op). I salvaged as much of the existing logic as I could, but there might be better ways to share and reduce code.

The motivating case from PR43745:
https://bugs.llvm.org/show_bug.cgi?id=43745
...is the special case of a 2-way reduction. We tried to get SLP to handle that particular pattern in D59710 <https://reviews.llvm.org/D59710>, but that caused crashing and regressions. This patch is more general, but hopefully safer.

The v2f64 test with SSE2 surprised me - the cost model accounting looks like this:
OldCost = 0 (free extract of f64 at index 0) + 1 (extract of f64 at index 1) + 2 (scalar fcmps) + 1 (and of bools) = 4
NewCost = 2 (vector fcmp) + 1 (shuffle) + 1 (vector 'and') + 1 (extract of bool) = 5

There's no code comment explanation for the more expensive vector fcmp in the cost model table, but I assume that's based on some ancient SSE2 implementation where it wasn't the cheapest:

  static const CostTblEntry SSE2CostTbl[] = {
    { ISD::SETCC,   MVT::v2f64,   2 },
    { ISD::SETCC,   MVT::f64,     1 },


https://reviews.llvm.org/D82474

Files:
  llvm/lib/Transforms/Vectorize/VectorCombine.cpp
  llvm/test/Transforms/PhaseOrdering/X86/vector-reductions.ll
  llvm/test/Transforms/VectorCombine/X86/extract-cmp-binop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82474.273053.patch
Type: text/x-patch
Size: 16373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200624/09ba545b/attachment.bin>


More information about the llvm-commits mailing list