Index: lib/CodeGen/PPCGCodeGeneration.cpp =================================================================== --- lib/CodeGen/PPCGCodeGeneration.cpp +++ lib/CodeGen/PPCGCodeGeneration.cpp @@ -1098,6 +1098,7 @@ HostPtr = BlockGen.getOrCreateAlloca(ArrayInfo); else HostPtr = ArrayInfo->getBasePtr(); + HostPtr = getLatestValue(HostPtr); Value *Offset = getArrayOffset(Array); if (Offset) { @@ -1131,6 +1132,7 @@ HostPtr = BlockGen.getOrCreateAlloca(ScopArray); else HostPtr = ScopArray->getBasePtr(); + HostPtr = getLatestValue(HostPtr); if (Offset) { HostPtr = Builder.CreatePointerCast( Index: test/GPGPU/invariant-load-hoisting-of-array.ll =================================================================== --- /dev/null +++ test/GPGPU/invariant-load-hoisting-of-array.ll @@ -0,0 +1,69 @@ +; RUN: opt %loadPolly -S -polly-codegen-ppcg \ +; RUN: -polly-invariant-load-hoisting < %s | FileCheck %s -check-prefix=HOST-IR + +; Make sure that we generate correct code even when an array is invariant load hoisted. + +; This is the value in the "original" code path. Make sure this still exists. +; This is the GEP into the invariant hoisted array +; HOST-IR: [[REGA:%.+]] = getelementptr double, double* %polly.access.v2.load, i64 1 + +; ModuleID = 'bugpoint-reduced-simplified.ll' +source_filename = "bugpoint-output-1116935.bc" +target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" + +%arrty = type { i8*, i64, i64, [1 x %threeints] } +%threeints = type { i64, i64, i64 } + +; Function Attrs: nounwind uwtable +define void @__mo_random_MOD_knuth_gauss_serial() #0 { +entry: + %v2 = alloca %arrty, align 8 + br label %entry.split + +entry.split: ; preds = %entry + br i1 undef, label %"63", label %"7" + +"7": ; preds = %entry.split + %.. = select i1 undef, i32 undef, i32 undef + br label %"51" + +"51": ; preds = %"7" + %tmp = bitcast %arrty* %v2 to double** + %tmp1 = load double*, double** %tmp, align 8 + %tmp2 = getelementptr inbounds %arrty, %arrty* %v2, i64 0, i32 1 + %tmp3 = sext i32 %.. to i64 + br i1 false, label %"54", label %"53.lr.ph" + +"53.lr.ph": ; preds = %"51" + br label %"53" + +"53": ; preds = %"53", %"53.lr.ph" + %tmp4 = phi i64 [ 1, %"53.lr.ph" ], [ %tmp7, %"53" ] + %tmp5 = add i64 %tmp4, 0 + %tmp6 = getelementptr double, double* %tmp1, i64 %tmp5 + store double undef, double* %tmp6, align 8 + %tmp7 = add nuw nsw i64 %tmp4, 1 + %tmp8 = icmp sgt i64 %tmp7, %tmp3 + br i1 %tmp8, label %"52.54_crit_edge", label %"53" + +"52.54_crit_edge": ; preds = %"53" + br label %"54" + +"54": ; preds = %"52.54_crit_edge", %"51" + br label %"55" + +"55": ; preds = %"54" + br i1 undef, label %"56", label %"58" + +"56": ; preds = %"55" + unreachable + +"58": ; preds = %"55" + unreachable + +"63": ; preds = %entry.split + ret void +} + +attributes #0 = { nounwind uwtable }