[polly] r255714 - VectorBlockGenerator: Generate scalar loads for vector statements
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 15 15:49:58 PST 2015
Author: grosser
Date: Tue Dec 15 17:49:58 2015
New Revision: 255714
URL: http://llvm.org/viewvc/llvm-project?rev=255714&view=rev
Log:
VectorBlockGenerator: Generate scalar loads for vector statements
When generating scalar loads/stores separately the vector code has not been
updated. This commit adds code to generate scalar loads for vector code as well
as code to assert in case scalar stores are encountered within a vector loop.
Added:
polly/trunk/test/Isl/CodeGen/simple_vec_stride_one.ll
Modified:
polly/trunk/include/polly/CodeGen/BlockGenerators.h
polly/trunk/lib/CodeGen/BlockGenerators.cpp
Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=255714&r1=255713&r2=255714&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Tue Dec 15 17:49:58 2015
@@ -709,6 +709,18 @@ private:
bool hasVectorOperands(const Instruction *Inst, ValueMapT &VectorMap);
+ /// @brief Generate vector loads for scalars.
+ ///
+ /// @param Stmt The scop statement for which to generate the loads.
+ /// @param VectorBlockMap A map that will be updated to relate the original
+ /// values with the newly generated vector loads.
+ void generateScalarVectorLoads(ScopStmt &Stmt, ValueMapT &VectorBlockMap);
+
+ /// @brief Verify absence of scalar stores.
+ ///
+ /// @param Stmt The scop statement to check for scalar stores.
+ void verifyNoScalarStores(ScopStmt &Stmt);
+
/// @param NewAccesses A map from memory access ids to new ast expressions,
/// which may contain new access expressions for certain
/// memory accesses.
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=255714&r1=255713&r2=255714&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Tue Dec 15 17:49:58 2015
@@ -966,6 +966,36 @@ void VectorBlockGenerator::copyInstructi
copyInstScalarized(Stmt, Inst, VectorMap, ScalarMaps, NewAccesses);
}
+void VectorBlockGenerator::generateScalarVectorLoads(
+ ScopStmt &Stmt, ValueMapT &VectorBlockMap) {
+ for (MemoryAccess *MA : Stmt) {
+ if (MA->isArrayKind() || MA->isWrite())
+ continue;
+
+ auto *Address = getOrCreateAlloca(*MA);
+ Type *VectorPtrType = getVectorPtrTy(Address, 1);
+ Value *VectorPtr = Builder.CreateBitCast(Address, VectorPtrType,
+ Address->getName() + "_p_vec_p");
+ auto *Val = Builder.CreateLoad(VectorPtr, Address->getName() + ".reload");
+ Constant *SplatVector = Constant::getNullValue(
+ VectorType::get(Builder.getInt32Ty(), getVectorWidth()));
+
+ Value *VectorVal = Builder.CreateShuffleVector(
+ Val, Val, SplatVector, Address->getName() + "_p_splat");
+ VectorBlockMap[MA->getBaseAddr()] = VectorVal;
+ VectorVal->dump();
+ }
+}
+
+void VectorBlockGenerator::verifyNoScalarStores(ScopStmt &Stmt) {
+ for (MemoryAccess *MA : Stmt) {
+ if (MA->isArrayKind() || MA->isRead())
+ continue;
+
+ llvm_unreachable("Scalar stores not expected in vector loop");
+ }
+}
+
void VectorBlockGenerator::copyStmt(
ScopStmt &Stmt, __isl_keep isl_id_to_ast_expr *NewAccesses) {
assert(Stmt.isBlockStmt() && "TODO: Only block statements can be copied by "
@@ -994,8 +1024,12 @@ void VectorBlockGenerator::copyStmt(
VectorValueMapT ScalarBlockMap(getVectorWidth());
ValueMapT VectorBlockMap;
+ generateScalarVectorLoads(Stmt, VectorBlockMap);
+
for (Instruction &Inst : *BB)
copyInstruction(Stmt, &Inst, VectorBlockMap, ScalarBlockMap, NewAccesses);
+
+ verifyNoScalarStores(Stmt);
}
BasicBlock *RegionGenerator::repairDominance(BasicBlock *BB,
Added: polly/trunk/test/Isl/CodeGen/simple_vec_stride_one.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/simple_vec_stride_one.ll?rev=255714&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/simple_vec_stride_one.ll (added)
+++ polly/trunk/test/Isl/CodeGen/simple_vec_stride_one.ll Tue Dec 15 17:49:58 2015
@@ -0,0 +1,37 @@
+; RUN: opt %loadPolly -polly-codegen -polly-vectorizer=polly \
+; RUN: < %s -S | FileCheck %s
+
+; CHECK: store <4 x double> %val.s2a_p_splat, <4 x double>* %vector_ptr
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @update_access_functions(i64 %arg, double* %A, double* %B) {
+bb3:
+ br label %loop1
+
+loop1:
+ %indvar = phi i64 [ %indvar.next, %loop1 ], [ 0, %bb3 ]
+ %ptr1 = getelementptr inbounds double, double* %A, i64 %indvar
+ store double 42.0, double* %ptr1, align 8
+ %indvar.next = add nuw nsw i64 %indvar, 1
+ %cmp = icmp ne i64 %indvar.next, 4
+ br i1 %cmp, label %loop1, label %loop2
+
+loop2:
+ %indvar.2 = phi i64 [ %indvar.2.next, %loop2 ], [ 0, %loop1 ]
+ %ptr2 = getelementptr inbounds double, double* %A, i64 %indvar.2
+ %val = load double, double* %ptr2, align 8
+ %indvar.2.next = add nuw nsw i64 %indvar.2, 1
+ %cmp.2 = icmp ne i64 %indvar.2.next, 4
+ br i1 %cmp.2, label %loop2, label %loop3
+
+loop3:
+ %indvar.3 = phi i64 [ %indvar.3.next, %loop3 ], [ 0, %loop2 ]
+ %ptr3 = getelementptr inbounds double, double* %A, i64 %indvar.3
+ store double %val, double* %ptr3, align 8
+ %indvar.3.next = add nuw nsw i64 %indvar.3, 1
+ %cmp.3 = icmp ne i64 %indvar.3.next, 4
+ br i1 %cmp.3, label %loop3, label %exit
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list