[PATCH] D92317: [LV] ExtractValue instruction costs

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 06:12:54 PST 2020


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: dmgreen, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
SjoerdMeijer requested review of this revision.

Instruction ExtractValue wasn't handled in `LoopVectorizationCostModel::getInstructionCost()`. As a result, it was modeled as a mul which may not be really accurate. Since it typically takes 1 instruction to extract a value from a vector we now model this with a cost of 1.

This is a follow-up of D92208 <https://reviews.llvm.org/D92208>, that required changing this regression test.


https://reviews.llvm.org/D92317

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll


Index: llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll
@@ -9,8 +9,8 @@
 ; leaving cost 3 for scalarizing the result + 2 for executing the op with VF 2.
 
 ; CM: LV: Scalar loop costs: 7.
-; CM: LV: Found an estimated cost of 19 for VF 2 For instruction:   %a = extractvalue { i64, i64 } %sv, 0
-; CM-NEXT: LV: Found an estimated cost of 19 for VF 2 For instruction:   %b = extractvalue { i64, i64 } %sv, 1
+; CM: LV: Found an estimated cost of 1 for VF 2 For instruction:   %a = extractvalue { i64, i64 } %sv, 0
+; CM-NEXT: LV: Found an estimated cost of 1 for VF 2 For instruction:   %b = extractvalue { i64, i64 } %sv, 1
 
 ; Check that the extractvalue operands are actually free in vector code.
 
@@ -58,8 +58,8 @@
 declare float @pow(float, float) readnone nounwind
 
 ; CM: LV: Scalar loop costs: 16.
-; CM: LV: Found an estimated cost of 5 for VF 2 For instruction:   %a = extractvalue { float, float } %sv, 0
-; CM-NEXT: LV: Found an estimated cost of 5 for VF 2 For instruction:   %b = extractvalue { float, float } %sv, 1
+; CM: LV: Found an estimated cost of 1 for VF 2 For instruction:   %a = extractvalue { float, float } %sv, 0
+; CM-NEXT: LV: Found an estimated cost of 1 for VF 2 For instruction:   %b = extractvalue { float, float } %sv, 1
 
 ; FORCED-LABEL: define void @test_getVectorCallCost
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6853,6 +6853,9 @@
       return std::min(CallCost, getVectorIntrinsicCost(CI, VF));
     return CallCost;
   }
+  case Instruction::ExtractValue:
+    // Assume we need 1 instruction to extract a value from a vector.
+    return 1;
   default:
     // The cost of executing VF copies of the scalar instruction. This opcode
     // is unknown. Assume that it is the same as 'mul'.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92317.308346.patch
Type: text/x-patch
Size: 2208 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201130/09cef649/attachment.bin>


More information about the llvm-commits mailing list