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
4 define i8 @single(i32 %A) {
5 ; CHECK-LABEL: @single(
7 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
8 ; CHECK-NEXT: [[CONV71:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
9 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[CONV71]] to i8
10 ; CHECK-NEXT: ret i8 [[TMP1]]
13 %l1 = icmp slt i32 %A, -128
14 %l2 = select i1 %l1, i32 128, i32 %A
15 %conv7 = trunc i32 %l2 to i8
19 define i8 @double(i32 %A) {
20 ; CHECK-LABEL: @double(
22 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
23 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
24 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 127
25 ; CHECK-NEXT: [[CONV71:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 127
26 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[CONV71]] to i8
27 ; CHECK-NEXT: ret i8 [[TMP3]]
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
38 define i8 @thisdoesnotloop(i32 %A, i32 %B) {
39 ; CHECK-LABEL: @thisdoesnotloop(
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]]
47 %l1 = icmp slt i32 %A, -128
48 %l2 = select i1 %l1, i32 128, i32 %B
49 %conv7 = trunc i32 %l2 to i8
53 define 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]]
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
72 define i8 @original_logical(i32 %A, i32 %B) {
73 ; CHECK-LABEL: @original_logical(
74 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -128
75 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 -128
76 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], 127
77 ; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 127
78 ; CHECK-NEXT: [[CONV7:%.*]] = trunc i32 [[SPEC_SELECT_I]] to i8
79 ; CHECK-NEXT: ret i8 [[CONV7]]
81 %cmp4.i = icmp slt i32 127, %A
82 %cmp6.i = icmp sle i32 -128, %A
83 %retval.0.i = select i1 %cmp4.i, i32 127, i32 -128
84 %not.cmp4.i = xor i1 %cmp4.i, true
85 %cleanup.dest.slot.0.i = select i1 %cmp6.i, i1 %not.cmp4.i, i1 false
86 %spec.select.i = select i1 %cleanup.dest.slot.0.i, i32 %A, i32 %retval.0.i
87 %conv7 = trunc i32 %spec.select.i to i8
91 ; This would infinite loop because we have potentially opposing
92 ; constant transforms on degenerate (unsimplified) cmps.
94 define i32 @PR49205(i32 %t0, i1 %b) {
95 ; CHECK-LABEL: @PR49205(
97 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
99 ; CHECK-NEXT: br i1 [[B:%.*]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
101 ; CHECK-NEXT: br label [[FOR_COND]]
103 ; CHECK-NEXT: ret i32 1
109 %s = phi i32 [ 7, %entry ], [ %add, %for.body ]
110 br i1 %b, label %for.body, label %for.end
113 %div = add i32 %t0, undef
114 %add = add nsw i32 %div, 1
118 %cmp6 = icmp ne i32 %s, 4
119 %conv = zext i1 %cmp6 to i32
120 %and7 = and i32 %s, %conv
121 %sub = sub i32 %s, %and7
122 %cmp9 = icmp ne i32 %sub, 4
123 %conv10 = zext i1 %cmp9 to i32
124 %sub11 = sub i32 %conv10, %sub
125 %and = and i32 %sub11, 1