summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-01-17 19:04:18 +0000
committerSanjay Patel <spatel@rotateright.com>2018-01-17 19:04:18 +0000
commit218a0b51ddc9f4e40ba3ad68818d3aa6d8e121df (patch)
treefc766ea7494f930e4d7b407be79c615814479cbb
parentbd2bd5a92e00aef5a0ea7c2909818ecd3af490d9 (diff)
downloadbcm5719-llvm-218a0b51ddc9f4e40ba3ad68818d3aa6d8e121df.tar.gz
bcm5719-llvm-218a0b51ddc9f4e40ba3ad68818d3aa6d8e121df.zip
[InstCombine] add baseline tests for D39958; NFC
llvm-svn: 322733
-rw-r--r--llvm/test/Transforms/InstCombine/select-gep.ll143
1 files changed, 143 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/select-gep.ll b/llvm/test/Transforms/InstCombine/select-gep.ll
new file mode 100644
index 00000000000..41304a8de0b
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/select-gep.ll
@@ -0,0 +1,143 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32* @test1a(i32* %p, i32* %q) {
+; CHECK-LABEL: @test1a(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, i32* [[P:%.*]], i64 4
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, i32* [[Q:%.*]], i64 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32* [[P]], [[Q]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr i32, i32* %p, i64 4
+ %gep2 = getelementptr i32, i32* %q, i64 4
+ %cmp = icmp ugt i32* %p, %q
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test1b(i32* %p, i32* %q) {
+; CHECK-LABEL: @test1b(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 4
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, i32* [[Q:%.*]], i64 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32* [[P]], [[Q]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 4
+ %gep2 = getelementptr i32, i32* %q, i64 4
+ %cmp = icmp ugt i32* %p, %q
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test1c(i32* %p, i32* %q) {
+; CHECK-LABEL: @test1c(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, i32* [[P:%.*]], i64 4
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, i32* [[Q:%.*]], i64 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32* [[P]], [[Q]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr i32, i32* %p, i64 4
+ %gep2 = getelementptr inbounds i32, i32* %q, i64 4
+ %cmp = icmp ugt i32* %p, %q
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test1d(i32* %p, i32* %q) {
+; CHECK-LABEL: @test1d(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 4
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, i32* [[Q:%.*]], i64 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32* [[P]], [[Q]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 4
+ %gep2 = getelementptr inbounds i32, i32* %q, i64 4
+ %cmp = icmp ugt i32* %p, %q
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test2(i32* %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 [[X:%.*]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, i32* [[P]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X]], [[Y]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 %x
+ %gep2 = getelementptr inbounds i32, i32* %p, i64 %y
+ %cmp = icmp ugt i64 %x, %y
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+; Three (or more) operand GEPs are currently expected to not be optimised,
+; though they could be in principle.
+
+define i32* @test3a([4 x i32]* %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test3a(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[P:%.*]], i64 2, i64 [[X:%.*]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[P]], i64 2, i64 [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X]], [[Y]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds [4 x i32], [4 x i32]* %p, i64 2, i64 %x
+ %gep2 = getelementptr inbounds [4 x i32], [4 x i32]* %p, i64 2, i64 %y
+ %cmp = icmp ugt i64 %x, %y
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test3b([4 x i32]* %p, i32* %q, i64 %x, i64 %y) {
+; CHECK-LABEL: @test3b(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[P:%.*]], i64 [[X:%.*]], i64 2
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, i32* [[Q:%.*]], i64 [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds [4 x i32], [4 x i32]* %p, i64 %x, i64 2
+ %gep2 = getelementptr inbounds i32, i32* %q, i64 %x
+ %cmp = icmp ugt i64 %x, %y
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+define i32* @test3c(i32* %p, [4 x i32]* %q, i64 %x, i64 %y) {
+; CHECK-LABEL: @test3c(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 [[X:%.*]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* [[Q:%.*]], i64 [[X]], i64 2
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 %x
+ %gep2 = getelementptr inbounds [4 x i32], [4 x i32]* %q, i64 %x, i64 2
+ %cmp = icmp ugt i64 %x, %y
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
+; Shouldn't be optimised as it would mean introducing an extra select
+
+define i32* @test4(i32* %p, i32* %q, i64 %x, i64 %y) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 [[X:%.*]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i32, i32* [[Q:%.*]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[X]], [[Y]]
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32* [[GEP1]], i32* [[GEP2]]
+; CHECK-NEXT: ret i32* [[SELECT]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 %x
+ %gep2 = getelementptr inbounds i32, i32* %q, i64 %y
+ %cmp = icmp ugt i64 %x, %y
+ %select = select i1 %cmp, i32* %gep1, i32* %gep2
+ ret i32* %select
+}
+
OpenPOWER on IntegriCloud