aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/phi.ll
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/InstCombine/phi.ll')
-rw-r--r--test/Transforms/InstCombine/phi.ll119
1 files changed, 119 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/phi.ll b/test/Transforms/InstCombine/phi.ll
index d0441d76d399..c417737fdf23 100644
--- a/test/Transforms/InstCombine/phi.ll
+++ b/test/Transforms/InstCombine/phi.ll
@@ -760,3 +760,122 @@ epilog:
; CHECK-NEXT: ret i1 %[[RES]]
}
+; CHECK-LABEL: phi_allnonzeroconstant
+; CHECK-NOT: phi i32
+; CHECK: ret i1 false
+define i1 @phi_allnonzeroconstant(i1 %c, i32 %a, i32 %b) {
+entry:
+ br i1 %c, label %if.then, label %if.else
+
+if.then: ; preds = %entry
+ br label %if.end
+
+if.else: ; preds = %entry
+ call void @dummy()
+
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ %x.0 = phi i32 [ 1, %if.then ], [ 2, %if.else ]
+ %or = or i32 %x.0, %a
+ %cmp1 = icmp eq i32 %or, 0
+ ret i1 %cmp1
+}
+
+declare void @dummy()
+
+; CHECK-LABEL: @phi_knownnonzero_eq
+; CHECK-LABEL: if.then:
+; CHECK-NOT: select
+; CHECK-LABEL: if.end:
+; CHECK: phi i32 [ 1, %if.then ]
+define i1 @phi_knownnonzero_eq(i32 %n, i32 %s, i32* nocapture readonly %P) {
+entry:
+ %tobool = icmp slt i32 %n, %s
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ %0 = load i32, i32* %P
+ %cmp = icmp eq i32 %n, %0
+ %1 = select i1 %cmp, i32 1, i32 2
+ br label %if.end
+
+if.end: ; preds = %entry, %if.then
+ %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
+ %cmp1 = icmp eq i32 %a.0, 0
+ ret i1 %cmp1
+}
+
+; CHECK-LABEL: @phi_knownnonzero_ne
+; CHECK-LABEL: if.then:
+; CHECK-NOT: select
+; CHECK-LABEL: if.end:
+; CHECK: phi i32 [ 1, %if.then ]
+define i1 @phi_knownnonzero_ne(i32 %n, i32 %s, i32* nocapture readonly %P) {
+entry:
+ %tobool = icmp slt i32 %n, %s
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ %0 = load i32, i32* %P
+ %cmp = icmp eq i32 %n, %0
+ %1 = select i1 %cmp, i32 1, i32 2
+ br label %if.end
+
+if.end: ; preds = %entry, %if.then
+ %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
+ %cmp1 = icmp ne i32 %a.0, 0
+ ret i1 %cmp1
+}
+
+; CHECK-LABEL: @phi_knownnonzero_eq_2
+; CHECK-LABEL: if.then:
+; CHECK-NOT: select
+; CHECK-LABEL: if.end:
+; CHECK: phi i32 [ 2, %if.else ]
+define i1 @phi_knownnonzero_eq_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
+entry:
+ %tobool = icmp slt i32 %n, %s
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then:
+ %tobool2 = icmp slt i32 %n, %s
+ br i1 %tobool2, label %if.else, label %if.end
+
+if.else: ; preds = %entry
+ %0 = load i32, i32* %P
+ %cmp = icmp eq i32 %n, %0
+ %1 = select i1 %cmp, i32 1, i32 2
+ br label %if.end
+
+if.end: ; preds = %entry, %if.then
+ %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
+ %cmp1 = icmp eq i32 %a.0, 0
+ ret i1 %cmp1
+}
+
+; CHECK-LABEL: @phi_knownnonzero_ne_2
+; CHECK-LABEL: if.then:
+; CHECK-NOT: select
+; CHECK-LABEL: if.end:
+; CHECK: phi i32 [ 2, %if.else ]
+define i1 @phi_knownnonzero_ne_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
+entry:
+ %tobool = icmp slt i32 %n, %s
+ br i1 %tobool, label %if.then, label %if.end
+
+if.then:
+ %tobool2 = icmp slt i32 %n, %s
+ br i1 %tobool2, label %if.else, label %if.end
+
+if.else: ; preds = %entry
+ %0 = load i32, i32* %P
+ %cmp = icmp eq i32 %n, %0
+ %1 = select i1 %cmp, i32 1, i32 2
+ br label %if.end
+
+if.end: ; preds = %entry, %if.then
+ %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
+ %cmp1 = icmp ne i32 %a.0, 0
+ ret i1 %cmp1
+}