1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
4 ; We could hoist the div/rem in these tests because it's safe to do so.
5 ; PR31028 - https://bugs.llvm.org/show_bug.cgi?id=31028
6 ; ...but since there's a separate pass for that, don't bother.
8 define i32 @hoist_sdiv(i32 %a, i32 %b) {
9 ; CHECK-LABEL: @hoist_sdiv(
11 ; CHECK-NEXT: [[REM:%.*]] = srem i32 [[A:%.*]], [[B:%.*]]
12 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[REM]], 42
13 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
15 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[A]], [[B]]
16 ; CHECK-NEXT: br label [[END]]
18 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[DIV]], [[IF]] ], [ 3, [[ENTRY:%.*]] ]
19 ; CHECK-NEXT: ret i32 [[RET]]
22 %rem = srem i32 %a, %b
23 %cmp = icmp eq i32 %rem, 42
24 br i1 %cmp, label %if, label %end
27 %div = sdiv i32 %a, %b
31 %ret = phi i32 [ %div, %if ], [ 3, %entry ]
35 define i64 @hoist_udiv(i64 %a, i64 %b) {
36 ; CHECK-LABEL: @hoist_udiv(
38 ; CHECK-NEXT: [[REM:%.*]] = urem i64 [[A:%.*]], [[B:%.*]]
39 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[REM]], 42
40 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
42 ; CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[A]], [[B]]
43 ; CHECK-NEXT: br label [[END]]
45 ; CHECK-NEXT: [[RET:%.*]] = phi i64 [ [[DIV]], [[IF]] ], [ 3, [[ENTRY:%.*]] ]
46 ; CHECK-NEXT: ret i64 [[RET]]
49 %rem = urem i64 %a, %b
50 %cmp = icmp eq i64 %rem, 42
51 br i1 %cmp, label %if, label %end
54 %div = udiv i64 %a, %b
58 %ret = phi i64 [ %div, %if ], [ 3, %entry ]
62 define i16 @hoist_srem(i16 %a, i16 %b) {
63 ; CHECK-LABEL: @hoist_srem(
65 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i16 [[A:%.*]], [[B:%.*]]
66 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[DIV]], 42
67 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
69 ; CHECK-NEXT: [[REM:%.*]] = srem i16 [[A]], [[B]]
70 ; CHECK-NEXT: br label [[END]]
72 ; CHECK-NEXT: [[RET:%.*]] = phi i16 [ [[REM]], [[IF]] ], [ 3, [[ENTRY:%.*]] ]
73 ; CHECK-NEXT: ret i16 [[RET]]
76 %div = sdiv i16 %a, %b
77 %cmp = icmp eq i16 %div, 42
78 br i1 %cmp, label %if, label %end
81 %rem = srem i16 %a, %b
85 %ret = phi i16 [ %rem, %if ], [ 3, %entry ]
89 define i8 @hoist_urem(i8 %a, i8 %b) {
90 ; CHECK-LABEL: @hoist_urem(
92 ; CHECK-NEXT: [[DIV:%.*]] = udiv i8 [[A:%.*]], [[B:%.*]]
93 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[DIV]], 42
94 ; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[END:%.*]]
96 ; CHECK-NEXT: [[REM:%.*]] = urem i8 [[A]], [[B]]
97 ; CHECK-NEXT: br label [[END]]
99 ; CHECK-NEXT: [[RET:%.*]] = phi i8 [ [[REM]], [[IF]] ], [ 3, [[ENTRY:%.*]] ]
100 ; CHECK-NEXT: ret i8 [[RET]]
103 %div = udiv i8 %a, %b
104 %cmp = icmp eq i8 %div, 42
105 br i1 %cmp, label %if, label %end
108 %rem = urem i8 %a, %b
112 %ret = phi i8 [ %rem, %if ], [ 3, %entry ]