diff options
| -rw-r--r-- | polly/lib/CodeGeneration.cpp | 86 | ||||
| -rw-r--r-- | polly/test/CodeGen/simple_vec_stride_x.ll | 26 |
2 files changed, 54 insertions, 58 deletions
diff --git a/polly/lib/CodeGeneration.cpp b/polly/lib/CodeGeneration.cpp index 01bbaae665c..5f4990efde7 100644 --- a/polly/lib/CodeGeneration.cpp +++ b/polly/lib/CodeGeneration.cpp @@ -419,29 +419,17 @@ public: if (!opZero && !opOne) return; - bool isVectorOp = vectorMap.count(opZero) || vectorMap.count(opOne); - - if (isVectorOp && vectorDimension > 0) - return; - Value *newOpZero, *newOpOne; newOpZero = getOperand(opZero, BBMap, &vectorMap); newOpOne = getOperand(opOne, BBMap, &vectorMap); - std::string name; - if (isVectorOp) { - newOpZero = makeVectorOperand(newOpZero, vectorWidth); - newOpOne = makeVectorOperand(newOpOne, vectorWidth); - name = Inst->getNameStr() + "p_vec"; - } else - name = Inst->getNameStr() + "p_sca"; + newOpZero = makeVectorOperand(newOpZero, vectorWidth); + newOpOne = makeVectorOperand(newOpOne, vectorWidth); Value *newInst = Builder.CreateBinOp(Inst->getOpcode(), newOpZero, - newOpOne, name); - if (isVectorOp) - vectorMap[Inst] = newInst; - else - BBMap[Inst] = newInst; + newOpOne, + Inst->getNameStr() + "p_vec"); + vectorMap[Inst] = newInst; return; } @@ -482,8 +470,7 @@ public: return; } - void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap, - ValueMapT &VectorMap) { + void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap) { Instruction *NewInst = Inst->clone(); // Replace old operands with the new ones. @@ -509,49 +496,58 @@ public: NewInst->setName("p_" + Inst->getName()); } + bool hasVectorOperands(const Instruction *Inst, ValueMapT &VectorMap) { + for (Instruction::const_op_iterator OI = Inst->op_begin(), + OE = Inst->op_end(); OI != OE; ++OI) + if (VectorMap.count(*OI)) + return true; + return false; + } + + int getVectorSize() { + return ValueMaps.size(); + } + + bool isVectorBlock() { + return getVectorSize() > 1; + } + void copyInstruction(const Instruction *Inst, ValueMapT &BBMap, ValueMapT &vectorMap, VectorValueMapT &scalarMaps, int vectorDimension, int vectorWidth) { - // If this instruction is already in the vectorMap, a vector instruction - // was already issued, that calculates the values of all dimensions. No - // need to create any more instructions. - if (vectorMap.count(Inst)) - return; - // Terminator instructions control the control flow. They are explicitally // expressed in the clast and do not need to be copied. if (Inst->isTerminator()) return; - if (const LoadInst *load = dyn_cast<LoadInst>(Inst)) { - generateLoad(load, vectorMap, scalarMaps, vectorWidth); - return; + if (isVectorBlock()) { + // If this instruction is already in the vectorMap, a vector instruction + // was already issued, that calculates the values of all dimensions. No + // need to create any more instructions. + if (vectorMap.count(Inst)) + return; } - if (const BinaryOperator *binaryInst = dyn_cast<BinaryOperator>(Inst)) { - copyBinInst(binaryInst, BBMap, vectorMap, scalarMaps, vectorDimension, - vectorWidth); + if (const LoadInst *load = dyn_cast<LoadInst>(Inst)) { + generateLoad(load, vectorMap, scalarMaps, vectorWidth); return; } - if (const StoreInst *store = dyn_cast<StoreInst>(Inst)) - if (vectorMap.count(store->getValueOperand()) > 0) { + if (isVectorBlock() && hasVectorOperands(Inst, vectorMap)) { + if (const BinaryOperator *binaryInst = dyn_cast<BinaryOperator>(Inst)) + copyBinInst(binaryInst, BBMap, vectorMap, scalarMaps, vectorDimension, + vectorWidth); + else if (const StoreInst *store = dyn_cast<StoreInst>(Inst)) copyVectorStore(store, BBMap, vectorMap, scalarMaps, vectorDimension, - vectorWidth); - return; - } - - copyInstScalar(Inst, BBMap, vectorMap); - } + vectorWidth); + else + llvm_unreachable("Cannot issue vector code for this instruction"); - int getVectorSize() { - return ValueMaps.size(); - } + return; + } - bool isVectorBlock() { - return getVectorSize() > 1; + copyInstScalar(Inst, BBMap); } - // Insert a copy of a basic block in the newly generated code. // // @param Builder The builder used to insert the code. It also specifies diff --git a/polly/test/CodeGen/simple_vec_stride_x.ll b/polly/test/CodeGen/simple_vec_stride_x.ll index 1a927251875..6206125a628 100644 --- a/polly/test/CodeGen/simple_vec_stride_x.ll +++ b/polly/test/CodeGen/simple_vec_stride_x.ll @@ -41,19 +41,19 @@ bb: ; CHECK: load float* %p_scevgep1.moved.to.bb3 ; CHECK: insertelement <4 x float> undef, float %tmp4_p_scalar_, i32 0 -; CHECK: load float* %p_scevgep1.moved.to.bb31 -; CHECK: insertelement <4 x float> %tmp4_p_vec_, float %tmp4_p_scalar_7, i32 1 -; CHECK: load float* %p_scevgep1.moved.to.bb32 -; CHECK: insertelement <4 x float> %tmp4_p_vec_8, float %tmp4_p_scalar_9, i32 2 -; CHECK: load float* %p_scevgep1.moved.to.bb33 -; CHECK: insertelement <4 x float> %tmp4_p_vec_10, float %tmp4_p_scalar_11, i32 3 -; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 0 +; CHECK: load float* %p_scevgep1.moved.to.bb34 +; CHECK: insertelement <4 x float> %tmp4_p_vec_, float %tmp4_p_scalar_10, i32 1 +; CHECK: load float* %p_scevgep1.moved.to.bb35 +; CHECK: insertelement <4 x float> %tmp4_p_vec_11, float %tmp4_p_scalar_12, i32 2 +; CHECK: load float* %p_scevgep1.moved.to.bb36 +; CHECK: insertelement <4 x float> %tmp4_p_vec_13, float %tmp4_p_scalar_14, i32 3 +; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 0 ; CHECK: store float %0, float* %p_scevgep.moved.to.bb3 -; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 1 -; CHECK: store float %1, float* %p_scevgep.moved.to.bb34 -; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 2 -; CHECK: store float %2, float* %p_scevgep.moved.to.bb35 -; CHECK: extractelement <4 x float> %tmp4_p_vec_12, i32 3 -; CHECK: store float %3, float* %p_scevgep.moved.to.bb36 +; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 1 +; CHECK: store float %1, float* %p_scevgep.moved.to.bb37 +; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 2 +; CHECK: store float %2, float* %p_scevgep.moved.to.bb38 +; CHECK: extractelement <4 x float> %tmp4_p_vec_15, i32 3 +; CHECK: store float %3, float* %p_scevgep.moved.to.bb39 |

