summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2018-08-24 16:24:48 +0000
committerPhilip Reames <listmail@philipreames.com>2018-08-24 16:24:48 +0000
commit9ec15faf20a405dffbc83162183822789a534423 (patch)
treec8717424dbf6c01efd8815540e184d3bcb76500f
parent0f6e12bcdffcec5fcea2133f011b64b52cf8129e (diff)
downloadbcm5719-llvm-9ec15faf20a405dffbc83162183822789a534423.tar.gz
bcm5719-llvm-9ec15faf20a405dffbc83162183822789a534423.zip
[LICM] Hoist an invariant_start out of loops if there are no stores executed before it
Once the invariant_start is reached, we know that no instruction *after* it can modify the memory. So, if we can prove the location isn't read *between entry into the loop and the execution of the invariant_start*, we can execute the invariant_start before entering the loop. Differential Revision: https://reviews.llvm.org/D51181 llvm-svn: 340617
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp4
-rw-r--r--llvm/test/Transforms/LICM/invariant.start.ll13
2 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index da750d00341..a642d2ef9ff 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -525,7 +525,9 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
}
using namespace PatternMatch;
- if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>()) &&
+ if (((I.use_empty() &&
+ match(&I, m_Intrinsic<Intrinsic::invariant_start>())) ||
+ match(&I, m_Intrinsic<Intrinsic::experimental_guard>())) &&
IsMustExecute && IsMemoryNotModified &&
CurLoop->hasLoopInvariantOperands(&I)) {
hoist(I, DT, CurLoop, SafetyInfo, ORE);
diff --git a/llvm/test/Transforms/LICM/invariant.start.ll b/llvm/test/Transforms/LICM/invariant.start.ll
index 9049e54ab85..d5d44757c40 100644
--- a/llvm/test/Transforms/LICM/invariant.start.ll
+++ b/llvm/test/Transforms/LICM/invariant.start.ll
@@ -3,19 +3,18 @@
; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=0 -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s
; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=200 -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s --check-prefix=ALIAS-N2
-; TODO: By default (without the -licm-n2-threshold value), we should be able to hoist both load and invariant.start
define void @test1(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test1(
; CHECK-LABEL: entry:
+; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
-; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2-LABEL: @test1(
; ALIAS-N2-LABEL: entry:
-; ALIAS-N2: %val = load i32, i32* %ptr
-; ALIAS-N2-LABEL: loop:
; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
+; ALIAS-N2: %val = load i32, i32* %ptr
+; ALIAS-N2-LABEL: loop:
entry:
br label %loop
@@ -57,15 +56,15 @@ loop:
define void @test3(i1 %cond, i32* %ptr) {
; CHECK-LABEL: @test3(
; CHECK-LABEL: entry:
+; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; CHECK: %val = load i32, i32* %ptr
; CHECK-LABEL: loop:
-; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
; ALIAS-N2-LABEL: @test3(
; ALIAS-N2-LABEL: entry:
-; ALIAS-N2: %val = load i32, i32* %ptr
+; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
+; ALIAS-N2: %val = load i32, i32* %ptr
; ALIAS-N2-LABEL: loop:
-; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
entry:
br label %loop
OpenPOWER on IntegriCloud