[polly] r218883 - Align copied load/store instructions as the original.
Johannes Doerfert
doerfert at cs.uni-saarland.de
Thu Oct 2 09:22:20 PDT 2014
Author: jdoerfert
Date: Thu Oct 2 11:22:19 2014
New Revision: 218883
URL: http://llvm.org/viewvc/llvm-project?rev=218883&view=rev
Log:
Align copied load/store instructions as the original.
This also forbids the json importer to access other memory locations
than the original instruction as we to reuse the alignment of the
original load/store.
Differential Revision: http://reviews.llvm.org/D5560
Added:
polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll
polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop
polly/trunk/test/Isl/CodeGen/alignment.ll
Modified:
polly/trunk/lib/CodeGen/BlockGenerators.cpp
polly/trunk/lib/Exchange/JSONExporter.cpp
polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=218883&r1=218882&r2=218883&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Oct 2 11:22:19 2014
@@ -222,8 +222,8 @@ Value *BlockGenerator::generateScalarLoa
const Instruction *Inst = dyn_cast<Instruction>(Load);
Value *NewPointer =
generateLocationAccessed(Inst, Pointer, BBMap, GlobalMap, LTS);
- Value *ScalarLoad =
- Builder.CreateLoad(NewPointer, Load->getName() + "_p_scalar_");
+ Value *ScalarLoad = Builder.CreateAlignedLoad(
+ NewPointer, Load->getAlignment(), Load->getName() + "_p_scalar_");
return ScalarLoad;
}
@@ -237,7 +237,9 @@ Value *BlockGenerator::generateScalarSto
Value *ValueOperand = getNewValue(Store->getValueOperand(), BBMap, GlobalMap,
LTS, getLoopForInst(Store));
- return Builder.CreateStore(ValueOperand, NewPointer);
+ Value *NewStore = Builder.CreateAlignedStore(ValueOperand, NewPointer,
+ Store->getAlignment());
+ return NewStore;
}
void BlockGenerator::copyInstruction(const Instruction *Inst, ValueMapT &BBMap,
Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=218883&r1=218882&r2=218883&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Thu Oct 2 11:22:19 2014
@@ -277,6 +277,21 @@ bool JSONImporter::runOnScop(Scop &scop)
return false;
}
+ // We keep the old alignment, thus we cannot allow accesses to memory
+ // locations that were not accessed before.
+ isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
+ isl_set *currentAccessSet = isl_map_range(isl_map_copy(currentAccessMap));
+ bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
+ isl_set_free(newAccessSet);
+ isl_set_free(currentAccessSet);
+
+ if (!isSubset) {
+ errs() << "JScop file changes the accessed memory\n";
+ isl_map_free(currentAccessMap);
+ isl_map_free(newAccessMap);
+ return false;
+ }
+
// We need to copy the isl_ids for the parameter dimensions to the new
// map. Without doing this the current map would have different
// ids then the new one, even though both are named identically.
Added: polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll?rev=218883&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll Thu Oct 2 11:22:19 2014
@@ -0,0 +1,36 @@
+; RUN: opt %loadPolly -polly-codegen-scev -polly-import-jscop -polly-import-jscop-dir=%S -analyze 2>&1 < %s | FileCheck %s
+;
+; Check that we do not allow to access elements not accessed before because the
+; alignment information would become invalid.
+;
+; CHECK: JScop file changes the accessed memory
+;
+; void bad_alignment(int *A) {
+; for (int i = 0; i < 1024; i += 2)
+; A[i] = i;
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @bad_alignment(i32* %A) {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+ %cmp = icmp slt i64 %indvars.iv, 1024
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %arrayidx = getelementptr inbounds i32* %A, i64 %indvars.iv
+ %tmp = trunc i64 %indvars.iv to i32
+ store i32 %tmp, i32* %arrayidx, align 8
+ br label %for.inc
+
+for.inc: ; preds = %for.body
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
Added: polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%25for.cond---%25for.end.jscop?rev=218883&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop Thu Oct 2 11:22:19 2014
@@ -0,0 +1,17 @@
+{
+ "context" : "{ : }",
+ "name" : "for.cond => polly.merge_new_and_old",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body[i0] -> MemRef_A[1] }"
+ }
+ ],
+ "domain" : "{ Stmt_for_body[i0] : i0 >= 0 and i0 <= 511 }",
+ "name" : "Stmt_for_body",
+ "schedule" : "{ Stmt_for_body[i0] -> scattering[0, i0, 0] }"
+ }
+ ]
+}
Added: polly/trunk/test/Isl/CodeGen/alignment.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/alignment.ll?rev=218883&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/alignment.ll (added)
+++ polly/trunk/test/Isl/CodeGen/alignment.ll Thu Oct 2 11:22:19 2014
@@ -0,0 +1,36 @@
+; RUN: opt %loadPolly -polly-codegen-scev -polly-codegen-isl -S < %s | FileCheck %s
+;
+; Check that the special alignment information is kept
+;
+; CHECK: align 8
+; CHECK: align 8
+;
+; void jd(int *A) {
+; for (int i = 0; i < 1024; i += 2)
+; A[i] = i;
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A) {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+ %cmp = icmp slt i64 %indvars.iv, 1024
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %arrayidx = getelementptr inbounds i32* %A, i64 %indvars.iv
+ %tmp = trunc i64 %indvars.iv to i32
+ store i32 %tmp, i32* %arrayidx, align 8
+ br label %for.inc
+
+for.inc: ; preds = %for.body
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
Modified: polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll?rev=218883&r1=218882&r2=218883&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll (original)
+++ polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll Thu Oct 2 11:22:19 2014
@@ -4,11 +4,11 @@
; Check that we create alias scopes that indicate the accesses to A, B and C cannot alias in any way.
;
; SCOPES: %[[BIdx:[._a-zA-Z0-9]*]] = getelementptr inbounds i32* %B, i64 %polly.indvar
-; SCOPES: load i32* %[[BIdx]], !alias.scope ![[AliasScopeB:[0-9]*]], !noalias ![[NoAliasB:[0-9]*]]
+; SCOPES: load i32* %[[BIdx]], align 4, !alias.scope ![[AliasScopeB:[0-9]*]], !noalias ![[NoAliasB:[0-9]*]]
; SCOPES: %[[CIdx:[._a-zA-Z0-9]*]] = getelementptr inbounds float* %C, i64 %polly.indvar
-; SCOPES: load float* %[[CIdx]], !alias.scope ![[AliasScopeC:[0-9]*]], !noalias ![[NoAliasC:[0-9]*]]
+; SCOPES: load float* %[[CIdx]], align 4, !alias.scope ![[AliasScopeC:[0-9]*]], !noalias ![[NoAliasC:[0-9]*]]
; SCOPES: %[[AIdx:[._a-zA-Z0-9]*]] = getelementptr inbounds i32* %A, i64 %polly.indvar
-; SCOPES: store i32 %{{[._a-zA-Z0-9]*}}, i32* %[[AIdx]], !alias.scope ![[AliasScopeA:[0-9]*]], !noalias ![[NoAliasA:[0-9]*]]
+; SCOPES: store i32 %{{[._a-zA-Z0-9]*}}, i32* %[[AIdx]], align 4, !alias.scope ![[AliasScopeA:[0-9]*]], !noalias ![[NoAliasA:[0-9]*]]
;
; SCOPES: ![[AliasScopeB]] = metadata !{metadata ![[AliasScopeB]], metadata !{{[0-9]*}}, metadata !"polly.alias.scope.B"}
; SCOPES: ![[NoAliasB]] = metadata !{
More information about the llvm-commits
mailing list