[llvm] 1813451 - [Test] Add test showing missing opportunity of folding ICmp(Phi(Consts...))
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 04:32:16 PDT 2020
Author: Max Kazantsev
Date: 2020-06-04T18:26:24+07:00
New Revision: 18134511d93046b7cde5c3cb9d5e356bd8e06b00
URL: https://github.com/llvm/llvm-project/commit/18134511d93046b7cde5c3cb9d5e356bd8e06b00
DIFF: https://github.com/llvm/llvm-project/commit/18134511d93046b7cde5c3cb9d5e356bd8e06b00.diff
LOG: [Test] Add test showing missing opportunity of folding ICmp(Phi(Consts...))
Added:
llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
new file mode 100644
index 000000000000..9753149f8012
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
@@ -0,0 +1,135 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; TODO: Replace with boolean Phi.
+
+define i1 @test_eq(i1 %cond) {
+; CHECK-LABEL: @test_eq(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
+; CHECK: if.true:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: if.false:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 123, [[IF_TRUE]] ], [ 456, [[IF_FALSE]] ]
+; CHECK-NEXT: br label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[COMPARE:%.*]] = icmp eq i32 [[PHI]], 456
+; CHECK-NEXT: ret i1 [[COMPARE]]
+;
+entry:
+ br i1 %cond, label %if.true, label %if.false
+
+if.true:
+ br label %merge
+
+if.false:
+ br label %merge
+
+merge:
+ %phi = phi i32 [123, %if.true], [456, %if.false]
+ br label %exit
+
+exit:
+ %compare = icmp eq i32 %phi, 456
+ ret i1 %compare
+}
+
+define i1 @test_slt(i1 %cond) {
+; CHECK-LABEL: @test_slt(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
+; CHECK: if.true:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: if.false:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 123, [[IF_TRUE]] ], [ 456, [[IF_FALSE]] ]
+; CHECK-NEXT: br label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[COMPARE:%.*]] = icmp ult i32 [[PHI]], 456
+; CHECK-NEXT: ret i1 [[COMPARE]]
+;
+entry:
+ br i1 %cond, label %if.true, label %if.false
+
+if.true:
+ br label %merge
+
+if.false:
+ br label %merge
+
+merge:
+ %phi = phi i32 [123, %if.true], [456, %if.false]
+ br label %exit
+
+exit:
+ %compare = icmp slt i32 %phi, 456
+ ret i1 %compare
+}
+
+define i1 @test_sle(i1 %cond) {
+; CHECK-LABEL: @test_sle(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
+; CHECK: if.true:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: if.false:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: br label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: ret i1 true
+;
+entry:
+ br i1 %cond, label %if.true, label %if.false
+
+if.true:
+ br label %merge
+
+if.false:
+ br label %merge
+
+merge:
+ %phi = phi i32 [123, %if.true], [456, %if.false]
+ br label %exit
+
+exit:
+ %compare = icmp sle i32 %phi, 456
+ ret i1 %compare
+}
+
+define i1 @test_ne(i1 %cond) {
+; CHECK-LABEL: @test_ne(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
+; CHECK: if.true:
+; CHECK-NEXT: br label [[MERGE:%.*]]
+; CHECK: if.false:
+; CHECK-NEXT: br label [[MERGE]]
+; CHECK: merge:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 123, [[IF_TRUE]] ], [ 456, [[IF_FALSE]] ]
+; CHECK-NEXT: br label [[EXIT:%.*]]
+; CHECK: exit:
+; CHECK-NEXT: [[COMPARE:%.*]] = icmp ne i32 [[PHI]], 456
+; CHECK-NEXT: ret i1 [[COMPARE]]
+;
+entry:
+ br i1 %cond, label %if.true, label %if.false
+
+if.true:
+ br label %merge
+
+if.false:
+ br label %merge
+
+merge:
+ %phi = phi i32 [123, %if.true], [456, %if.false]
+ br label %exit
+
+exit:
+ %compare = icmp ne i32 %phi, 456
+ ret i1 %compare
+}
More information about the llvm-commits
mailing list