summaryrefslogtreecommitdiff
path: root/test/Transforms
diff options
context:
space:
mode:
authorJun Bum Lim <junbuml@codeaurora.org>2017-12-15 16:09:54 +0000
committerJun Bum Lim <junbuml@codeaurora.org>2017-12-15 16:09:54 +0000
commit20ea5a516182ba80d098f722ff822fda9702d583 (patch)
tree93172453fb744a870cfd52ab0c7fe05d01431ec5 /test/Transforms
parent213645abbdf5e9f079496abf8798b94221026db9 (diff)
[LICM] Allow sinking when foldable in loop
Summary: Continue trying to sink an instruction if its users in the loop is foldable. This will allow the instruction to be folded in the loop by decoupling it from the user outside of the loop. Reviewers: hfinkel, majnemer, davidxl, efriedma, danielcdh, bmakam, mcrosier Reviewed By: hfinkel Subscribers: javed.absar, bmakam, mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D37076 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320823 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/LICM/sink-foldable.ll147
1 files changed, 147 insertions, 0 deletions
diff --git a/test/Transforms/LICM/sink-foldable.ll b/test/Transforms/LICM/sink-foldable.ll
new file mode 100644
index 00000000000..cf67e35efed
--- /dev/null
+++ b/test/Transforms/LICM/sink-foldable.ll
@@ -0,0 +1,147 @@
+; RUN: opt < %s -licm -S | FileCheck %s
+target triple = "aarch64--linux-gnueabi"
+
+; CHECK-LABEL:@test1
+; CHECK-LABEL:loopexit1:
+; CHECK: %[[PHI:.+]] = phi i8** [ %arrayidx0, %if.end ]
+; CHECK: getelementptr inbounds i8*, i8** %[[PHI]], i64 1
+define i8** @test1(i32 %j, i8** readonly %P, i8* readnone %Q) {
+entry:
+ %cmp0 = icmp slt i32 0, %j
+ br i1 %cmp0, label %for.body.lr.ph, label %return
+
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %P.addr = phi i8** [ %P, %for.body.lr.ph ], [ %arrayidx0, %if.end ]
+ %i0 = phi i32 [ 0, %for.body.lr.ph ], [ %i.add, %if.end]
+
+ %i0.ext = sext i32 %i0 to i64
+ %arrayidx0 = getelementptr inbounds i8*, i8** %P.addr, i64 %i0.ext
+ %l0 = load i8*, i8** %arrayidx0, align 8
+ %cmp1 = icmp ugt i8* %l0, %Q
+ br i1 %cmp1, label %loopexit0, label %if.end
+
+if.end: ; preds = %for.body
+ %arrayidx1 = getelementptr inbounds i8*, i8** %arrayidx0, i64 1
+ %l1 = load i8*, i8** %arrayidx1, align 8
+ %cmp4 = icmp ugt i8* %l1, %Q
+ %i.add = add nsw i32 %i0, 2
+ br i1 %cmp4, label %loopexit1, label %for.body
+
+loopexit0:
+ %p1 = phi i8** [%arrayidx0, %for.body]
+ br label %return
+
+loopexit1:
+ %p2 = phi i8** [%arrayidx1, %if.end]
+ br label %return
+
+return:
+ %retval.0 = phi i8** [ %p1, %loopexit0 ], [%p2, %loopexit1], [ null, %entry ]
+ ret i8** %retval.0
+}
+
+; CHECK-LABEL: @test2
+; CHECK-LABEL: loopexit2:
+; CHECK: %[[PHI:.*]] = phi i8** [ %add.ptr, %if.end ]
+; CHECK: getelementptr inbounds i8*, i8** %[[PHI]]
+define i8** @test2(i32 %j, i8** readonly %P, i8* readnone %Q) {
+
+entry:
+ br label %for.body
+
+for.cond:
+ %i.addr.0 = phi i32 [ %add, %if.end ]
+ %P.addr.0 = phi i8** [ %add.ptr, %if.end ]
+ %cmp = icmp slt i32 %i.addr.0, %j
+ br i1 %cmp, label %for.body, label %loopexit0
+
+for.body:
+ %P.addr = phi i8** [ %P, %entry ], [ %P.addr.0, %for.cond ]
+ %i.addr = phi i32 [ 0, %entry ], [ %i.addr.0, %for.cond ]
+
+ %idx.ext = sext i32 %i.addr to i64
+ %add.ptr = getelementptr inbounds i8*, i8** %P.addr, i64 %idx.ext
+ %l0 = load i8*, i8** %add.ptr, align 8
+
+ %cmp1 = icmp ugt i8* %l0, %Q
+ br i1 %cmp1, label %loopexit1, label %if.end
+
+if.end:
+ %add.i = add i32 %i.addr, 1
+ %idx2.ext = sext i32 %add.i to i64
+ %arrayidx2 = getelementptr inbounds i8*, i8** %add.ptr, i64 %idx2.ext
+ %l1 = load i8*, i8** %arrayidx2, align 8
+ %cmp2 = icmp ugt i8* %l1, %Q
+ %add = add nsw i32 %add.i, 1
+ br i1 %cmp2, label %loopexit2, label %for.cond
+
+loopexit0:
+ %p0 = phi i8** [ null, %for.cond ]
+ br label %return
+
+loopexit1:
+ %p1 = phi i8** [ %add.ptr, %for.body ]
+ br label %return
+
+loopexit2:
+ %p2 = phi i8** [ %arrayidx2, %if.end ]
+ br label %return
+
+return:
+ %retval.0 = phi i8** [ %p1, %loopexit1 ], [ %p2, %loopexit2 ], [ %p0, %loopexit0 ]
+ ret i8** %retval.0
+}
+
+
+; CHECK-LABEL: @test3
+; CHECK-LABEL: loopexit1:
+; CHECK: %[[ADD:.*]] = phi i64 [ %add, %if.end ]
+; CHECK: %[[ADDR:.*]] = phi i8** [ %P.addr, %if.end ]
+; CHECK: %[[TRUNC:.*]] = trunc i64 %[[ADD]] to i32
+; CHECK: getelementptr inbounds i8*, i8** %[[ADDR]], i32 %[[TRUNC]]
+; CHECK: call void @dummy(i32 %[[TRUNC]])
+define i8** @test3(i64 %j, i8** readonly %P, i8* readnone %Q) {
+entry:
+ %cmp0 = icmp slt i64 0, %j
+ br i1 %cmp0, label %for.body.lr.ph, label %return
+
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %P.addr = phi i8** [ %P, %for.body.lr.ph ], [ %arrayidx0, %if.end ]
+ %i0 = phi i32 [ 0, %for.body.lr.ph ], [ %i.add, %if.end]
+
+ %i0.ext = sext i32 %i0 to i64
+ %arrayidx0 = getelementptr inbounds i8*, i8** %P.addr, i64 %i0.ext
+ %l0 = load i8*, i8** %arrayidx0, align 8
+ %cmp1 = icmp ugt i8* %l0, %Q
+ br i1 %cmp1, label %loopexit0, label %if.end
+
+if.end: ; preds = %for.body
+ %add = add i64 %i0.ext, 1
+ %trunc = trunc i64 %add to i32
+ %arrayidx1 = getelementptr inbounds i8*, i8** %P.addr, i32 %trunc
+ %l1 = load i8*, i8** %arrayidx1, align 8
+ %cmp4 = icmp ugt i8* %l1, %Q
+ %i.add = add nsw i32 %i0, 2
+ br i1 %cmp4, label %loopexit1, label %for.body
+
+loopexit0:
+ %p1 = phi i8** [%arrayidx0, %for.body]
+ br label %return
+
+loopexit1:
+ %p2 = phi i8** [%arrayidx1, %if.end]
+ call void @dummy(i32 %trunc)
+ br label %return
+
+return:
+ %retval.0 = phi i8** [ %p1, %loopexit0 ], [%p2, %loopexit1], [ null, %entry ]
+ ret i8** %retval.0
+}
+
+declare void @dummy(i32)