1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -instcombine-infinite-loop-threshold=2 -S | FileCheck %s
3
4define i8 @single(i32 %A) {
5; CHECK-LABEL: @single(
6; CHECK-NEXT:  entry:
7; CHECK-NEXT:    [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
8; CHECK-NEXT:    [[L2:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
9; CHECK-NEXT:    [[CONV7:%.*]] = trunc i32 [[L2]] to i8
10; CHECK-NEXT:    ret i8 [[CONV7]]
11;
12entry:
13  %l1 = icmp slt i32 %A, -128
14  %l2 = select i1 %l1, i32 128, i32 %A
15  %conv7 = trunc i32 %l2 to i8
16  ret i8 %conv7
17}
18
19define i8 @double(i32 %A) {
20; CHECK-LABEL: @double(
21; CHECK-NEXT:  entry:
22; CHECK-NEXT:    [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
23; CHECK-NEXT:    [[L2:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
24; CHECK-NEXT:    [[TMP1:%.*]] = icmp slt i32 [[L2]], 127
25; CHECK-NEXT:    [[SPEC_SELECT_I:%.*]] = select i1 [[TMP1]], i32 [[L2]], i32 127
26; CHECK-NEXT:    [[CONV7:%.*]] = trunc i32 [[SPEC_SELECT_I]] to i8
27; CHECK-NEXT:    ret i8 [[CONV7]]
28;
29entry:
30  %l1 = icmp slt i32 %A, -128
31  %l2 = select i1 %l1, i32 128, i32 %A
32  %.inv = icmp sgt i32 %A, 127
33  %spec.select.i = select i1 %.inv, i32 127, i32 %l2
34  %conv7 = trunc i32 %spec.select.i to i8
35  ret i8 %conv7
36}
37
38define i8 @thisdoesnotloop(i32 %A, i32 %B) {
39; CHECK-LABEL: @thisdoesnotloop(
40; CHECK-NEXT:  entry:
41; CHECK-NEXT:    [[L1:%.*]] = icmp slt i32 [[A:%.*]], -128
42; CHECK-NEXT:    [[TMP0:%.*]] = trunc i32 [[B:%.*]] to i8
43; CHECK-NEXT:    [[CONV7:%.*]] = select i1 [[L1]], i8 -128, i8 [[TMP0]]
44; CHECK-NEXT:    ret i8 [[CONV7]]
45;
46entry:
47  %l1 = icmp slt i32 %A, -128
48  %l2 = select i1 %l1, i32 128, i32 %B
49  %conv7 = trunc i32 %l2 to i8
50  ret i8 %conv7
51}
52
53define i8 @original(i32 %A, i32 %B) {
54; CHECK-LABEL: @original(
55; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -128
56; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 -128
57; CHECK-NEXT:    [[TMP3:%.*]] = icmp slt i32 [[TMP2]], 127
58; CHECK-NEXT:    [[SPEC_SELECT_I:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 127
59; CHECK-NEXT:    [[CONV7:%.*]] = trunc i32 [[SPEC_SELECT_I]] to i8
60; CHECK-NEXT:    ret i8 [[CONV7]]
61;
62  %cmp4.i = icmp slt i32 127, %A
63  %cmp6.i = icmp sle i32 -128, %A
64  %retval.0.i = select i1 %cmp4.i, i32 127, i32 -128
65  %not.cmp4.i = xor i1 %cmp4.i, true
66  %cleanup.dest.slot.0.i = and i1 %cmp6.i, %not.cmp4.i
67  %spec.select.i = select i1 %cleanup.dest.slot.0.i, i32 %A, i32 %retval.0.i
68  %conv7 = trunc i32 %spec.select.i to i8
69  ret i8 %conv7
70}
71