Index: polly/trunk/lib/CodeGen/BlockGenerators.cpp =================================================================== --- polly/trunk/lib/CodeGen/BlockGenerators.cpp +++ polly/trunk/lib/CodeGen/BlockGenerators.cpp @@ -222,8 +222,8 @@ const Instruction *Inst = dyn_cast(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 *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, Index: polly/trunk/lib/Exchange/JSONExporter.cpp =================================================================== --- polly/trunk/lib/Exchange/JSONExporter.cpp +++ polly/trunk/lib/Exchange/JSONExporter.cpp @@ -277,6 +277,21 @@ 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. Index: polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll =================================================================== --- polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll +++ polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment.ll @@ -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 +} Index: polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop =================================================================== --- polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop +++ polly/trunk/test/Isl/CodeGen/MemAccess/bad_alignment___%for.cond---%for.end.jscop @@ -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] }" + } + ] +} Index: polly/trunk/test/Isl/CodeGen/alignment.ll =================================================================== --- polly/trunk/test/Isl/CodeGen/alignment.ll +++ polly/trunk/test/Isl/CodeGen/alignment.ll @@ -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 +} Index: polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll =================================================================== --- polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll +++ polly/trunk/test/Isl/CodeGen/annotated_alias_scopes.ll @@ -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 !{