From 654c3284f4232826d95ead6150277ea2dbef5df6 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 21 Oct 2015 22:14:57 +0000 Subject: [PATCH] [FIX] Do not hoist nested variant base pointers This fixes bug 25249. llvm-svn: 250958 --- polly/lib/Analysis/ScopInfo.cpp | 18 ++++++----- polly/test/ScopInfo/variant_base_pointer.ll | 34 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 polly/test/ScopInfo/variant_base_pointer.ll diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 63ba35ab5574..57caef9b0d14 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -2549,14 +2549,18 @@ void Scop::hoistInvariantLoads() { // not loaded inside the SCoP. This can happened e.g., if a readnone call // returns a pointer that is used as a base address. However, as we want // to hoist indirect pointers, we allow the base pointer to be defined in - // the region if it is also a memory access. Hence, if the ScopArrayInfo - // object has a base pointer origin we know the base pointer is loaded and - // that it is invariant, thus it will be hoisted too. + // the region if it is also a memory access. Each ScopArrayInfo object + // that has a base pointer origin has a base pointer that is loaded and + // that it is invariant, thus it will be hoisted too. However, if there is + // no bease pointer origin we check that the base pointer is defined + // outside the region. const ScopArrayInfo *SAI = MA->getScopArrayInfo(); - if (!SAI->getBasePtrOriginSAI()) - if (auto *BasePtrInst = dyn_cast(SAI->getBasePtr())) - if (R.contains(BasePtrInst)) - continue; + while (auto *BasePtrOriginSAI = SAI->getBasePtrOriginSAI()) + SAI = BasePtrOriginSAI; + + if (auto *BasePtrInst = dyn_cast(SAI->getBasePtr())) + if (R.contains(BasePtrInst)) + continue; // Skip accesses in non-affine subregions as they might not be executed // under the same condition as the entry of the non-affine subregion. diff --git a/polly/test/ScopInfo/variant_base_pointer.ll b/polly/test/ScopInfo/variant_base_pointer.ll new file mode 100644 index 000000000000..4afa667adbbd --- /dev/null +++ b/polly/test/ScopInfo/variant_base_pointer.ll @@ -0,0 +1,34 @@ +; RUN: opt %loadPolly -polly-ignore-aliasing -polly-scops -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -polly-ignore-aliasing -polly-codegen -analyze < %s +; +; CHECK: Invariant Accesses: { +; CHECK-NEXT: } +; +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +; Function Attrs: nounwind uwtable +define void @cli_hex2int() { +entry: + br label %if.end + +if.end: ; preds = %entry + %call = call i16** @__ctype_b_loc() #0 + %tmp = load i16*, i16** %call, align 8 + %arrayidx = getelementptr inbounds i16, i16* %tmp, i64 0 + %tmp1 = load i16, i16* %arrayidx, align 2 + br i1 false, label %if.then.2, label %if.end.3 + +if.then.2: ; preds = %if.end + br label %cleanup + +if.end.3: ; preds = %if.end + br label %cleanup + +cleanup: ; preds = %if.end.3, %if.then.2 + ret void +} + +; Function Attrs: nounwind readnone +declare i16** @__ctype_b_loc() #0 + +attributes #0 = { nounwind readnone }