1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; PR30281 - https://llvm.org/bugs/show_bug.cgi?id=30281
6 ; All of these tests contain foldable division-by-constant instructions, but we
7 ; can't assert that those folds have occurred before we process the later icmp.
9 define i32 @icmp_div(i16 %a, i16 %c) {
10 ; CHECK-LABEL: @icmp_div(
12 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 %a, 0
13 ; CHECK-NEXT: br i1 [[TOBOOL]], label %then, label %exit
15 ; CHECK-NEXT: [[NOT_CMP:%.*]] = icmp eq i16 %c, 0
16 ; CHECK-NEXT: [[PHITMP1:%.*]] = sext i1 [[NOT_CMP]] to i32
17 ; CHECK-NEXT: br label %exit
19 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, %entry ], [ [[PHITMP1]], %then ]
20 ; CHECK-NEXT: ret i32 [[PHI]]
23 %tobool = icmp eq i16 %a, 0
24 br i1 %tobool, label %then, label %exit
27 %div = sdiv i16 %c, -1
28 %cmp = icmp ne i16 %div, 0
32 %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
33 %zext = zext i1 %phi to i32
34 %add = add nsw i32 %zext, -1
38 define i32 @icmp_div2(i16 %a, i16 %c) {
39 ; CHECK-LABEL: @icmp_div2(
41 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 %a, 0
42 ; CHECK-NEXT: br i1 [[TOBOOL]], label %then, label %exit
44 ; CHECK-NEXT: br label %exit
46 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, %entry ], [ 0, %then ]
47 ; CHECK-NEXT: ret i32 [[PHI]]
50 %tobool = icmp eq i16 %a, 0
51 br i1 %tobool, label %then, label %exit
55 %cmp = icmp ne i16 %div, 0
59 %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
60 %zext = zext i1 %phi to i32
61 %add = add nsw i32 %zext, -1
65 define i32 @icmp_div3(i16 %a, i16 %c) {
66 ; CHECK-LABEL: @icmp_div3(
68 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 %a, 0
69 ; CHECK-NEXT: br i1 [[TOBOOL]], label %then, label %exit
71 ; CHECK-NEXT: [[NOT_CMP:%.*]] = icmp eq i16 %c, 0
72 ; CHECK-NEXT: [[PHITMP1:%.*]] = sext i1 [[NOT_CMP]] to i32
73 ; CHECK-NEXT: br label %exit
75 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, %entry ], [ [[PHITMP1]], %then ]
76 ; CHECK-NEXT: ret i32 [[PHI]]
79 %tobool = icmp eq i16 %a, 0
80 br i1 %tobool, label %then, label %exit
84 %cmp = icmp ne i16 %div, 0
88 %phi = phi i1 [ false, %entry ], [ %cmp, %then ]
89 %zext = zext i1 %phi to i32
90 %add = add nsw i32 %zext, -1