1 ; RUN: opt -simplifycfg -S < %s | FileCheck %s
3 ; We could hoist the div/rem in these tests because it's safe to do so.
4 ; PR31028 - https://bugs.llvm.org/show_bug.cgi?id=31028
5 ; ...but since there's a separate pass for that, don't bother.
7 define i32 @hoist_sdiv(i32 %a, i32 %b) {
8 ; CHECK-LABEL: @hoist_sdiv(
10 ; CHECK-NEXT: [[REM:%.*]] = srem i32 %a, %b
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[REM]], 42
12 ; CHECK-NEXT: br i1 [[CMP]], label %if, label %end
14 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 %a, %b
15 ; CHECK-NEXT: br label %end
17 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[DIV]], %if ], [ 3, %entry ]
18 ; CHECK-NEXT: ret i32 [[RET]]
21 %rem = srem i32 %a, %b
22 %cmp = icmp eq i32 %rem, 42
23 br i1 %cmp, label %if, label %end
26 %div = sdiv i32 %a, %b
30 %ret = phi i32 [ %div, %if ], [ 3, %entry ]
34 define i64 @hoist_udiv(i64 %a, i64 %b) {
35 ; CHECK-LABEL: @hoist_udiv(
37 ; CHECK-NEXT: [[REM:%.*]] = urem i64 %a, %b
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[REM]], 42
39 ; CHECK-NEXT: br i1 [[CMP]], label %if, label %end
41 ; CHECK-NEXT: [[DIV:%.*]] = udiv i64 %a, %b
42 ; CHECK-NEXT: br label %end
44 ; CHECK-NEXT: [[RET:%.*]] = phi i64 [ [[DIV]], %if ], [ 3, %entry ]
45 ; CHECK-NEXT: ret i64 [[RET]]
48 %rem = urem i64 %a, %b
49 %cmp = icmp eq i64 %rem, 42
50 br i1 %cmp, label %if, label %end
53 %div = udiv i64 %a, %b
57 %ret = phi i64 [ %div, %if ], [ 3, %entry ]
61 define i16 @hoist_srem(i16 %a, i16 %b) {
62 ; CHECK-LABEL: @hoist_srem(
64 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i16 %a, %b
65 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[DIV]], 42
66 ; CHECK-NEXT: br i1 [[CMP]], label %if, label %end
68 ; CHECK-NEXT: [[REM:%.*]] = srem i16 %a, %b
69 ; CHECK-NEXT: br label %end
71 ; CHECK-NEXT: [[RET:%.*]] = phi i16 [ [[REM]], %if ], [ 3, %entry ]
72 ; CHECK-NEXT: ret i16 [[RET]]
75 %div = sdiv i16 %a, %b
76 %cmp = icmp eq i16 %div, 42
77 br i1 %cmp, label %if, label %end
80 %rem = srem i16 %a, %b
84 %ret = phi i16 [ %rem, %if ], [ 3, %entry ]
88 define i8 @hoist_urem(i8 %a, i8 %b) {
89 ; CHECK-LABEL: @hoist_urem(
91 ; CHECK-NEXT: [[DIV:%.*]] = udiv i8 %a, %b
92 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[DIV]], 42
93 ; CHECK-NEXT: br i1 [[CMP]], label %if, label %end
95 ; CHECK-NEXT: [[REM:%.*]] = urem i8 %a, %b
96 ; CHECK-NEXT: br label %end
98 ; CHECK-NEXT: [[RET:%.*]] = phi i8 [ [[REM]], %if ], [ 3, %entry ]
99 ; CHECK-NEXT: ret i8 [[RET]]
102 %div = udiv i8 %a, %b
103 %cmp = icmp eq i8 %div, 42
104 br i1 %cmp, label %if, label %end
107 %rem = urem i8 %a, %b
111 %ret = phi i8 [ %rem, %if ], [ 3, %entry ]