LoopVectorize: For scalars and void types there is no need to compute vector insert...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 23 Dec 2012 13:19:18 +0000 (13:19 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 23 Dec 2012 13:19:18 +0000 (13:19 +0000)
Fixes an assert during the build of oggenc in the test suite.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171000 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Vectorize/LoopVectorize.cpp

index 5b1db0b9d147f9644b2c141d3b5c2b8475f21ef1..ddb7f2607e57168c4ef6af21aa6e3456844a0a8b 100644 (file)
@@ -2181,18 +2181,16 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) {
     // elements, times the vector width.
     unsigned Cost = 0;
 
-    bool IsVoid = RetTy->isVoidTy();
-
-    unsigned InsCost = (IsVoid ? 0 :
-                        VTTI->getVectorInstrCost(Instruction::InsertElement,
-                                           VectorTy));
-
-    unsigned ExtCost = VTTI->getVectorInstrCost(Instruction::ExtractElement,
-                                          VectorTy);
-
-    // The cost of inserting the results plus extracting each one of the
-    // operands.
-    Cost += VF * (InsCost + ExtCost * I->getNumOperands());
+    if (RetTy->isVoidTy() || VF != 1) {
+      unsigned InsCost = VTTI->getVectorInstrCost(Instruction::InsertElement,
+                                                  VectorTy);
+      unsigned ExtCost = VTTI->getVectorInstrCost(Instruction::ExtractElement,
+                                                  VectorTy);
+
+      // The cost of inserting the results plus extracting each one of the
+      // operands.
+      Cost += VF * (InsCost + ExtCost * I->getNumOperands());
+    }
 
     // The cost of executing VF copies of the scalar instruction. This opcode
     // is unknown. Assume that it is the same as 'mul'.