[PATCH] D59995: [LV] Exclude loop-invariant inputs from scalar cost computation.

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 5 01:06:21 PDT 2019


Ayal added a comment.

The culprit here is the assumption made by `TTI.getOperandsScalarizationOverhead(Operands, VF)` that all its Operands will be vectorized according to VF, and would thus require extraction to feed a scalarized/replicated user. But any such Operand might not get vectorized, and possibly must not get vectorized, e.g., due to an incompatible type as demonstrated by PR41294 and the testcase. In some cases an Operand will obviously not be vectorized, such as if it's loop-invariant or live-in. More generally, LV uses the following:

  auto needsExtract = [&](Instruction *I) -> bool {
    return TheLoop->contains(I) && !isScalarAfterVectorization(I, VF);
  };

which would require passing not only `TheLoop` into `getScalarizationOverhead(I, VF, TTI)` but also the CM --- better turn this static function into a method of CM?

Note that there's also `CM.isProfitableToScalarize(I, VF))`, but it relies on having computed costs, so difficult to use when computing the cost (of a User). Skipping it would only affect accuracy of resulting cost, considering Operands that can be vectorized but will not be due to profitability.

Fixing `getVectorCallCost` deserves another testcase.
Seems like `getVectorIntrinsicCost` also requires fixing?

Would be good to hoist such invariant instructions

  %a = extractvalue { i64, i64 } %sv, 0
  %b = extractvalue { i64, i64 } %sv, 1

out of the loop before LV, or at-least have LV recognize them as uniform.



================
Comment at: llvm/test/Transforms/LoopVectorize/AArch64/instructions-with-struct-ops.ll:3
+; RUN: opt -loop-vectorize -force-vector-width=2 -force-vector-interleave=1 %s -S | FileCheck --check-prefix=FORCED %s
+
+; Check scalar cost for extractelement. The constant and loop invariant operands are free,
----------------
Record PR41294 in comment, file name, or testcase function name.


================
Comment at: llvm/test/Transforms/LoopVectorize/AArch64/instructions-with-struct-ops.ll:4
+
+; Check scalar cost for extractelement. The constant and loop invariant operands are free,
+; leaving cost 3 for scalarizing the result + 2 for executing the op with VF 2.
----------------
`for extractelement` >> `for extractvalue`


================
Comment at: llvm/test/Transforms/LoopVectorize/AArch64/instructions-with-struct-ops.ll:10
+
+; Check that the extractlement operands are actually free in vector code.
+
----------------
`the extractelement` >> `the extractvalue`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59995/new/

https://reviews.llvm.org/D59995





More information about the llvm-commits mailing list