xref: /llvm-project/llvm/test/Transforms/InstCombine/fold-select-trunc.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4define i8 @fold_select_trunc_nuw_true(i8 %x, i8 %y) {
5; CHECK-LABEL: @fold_select_trunc_nuw_true(
6; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
7; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 1, i8 [[Y:%.*]]
8; CHECK-NEXT:    ret i8 [[RET]]
9;
10  %trunc = trunc nuw i8 %x to i1
11  %ret = select i1 %trunc, i8 %x, i8 %y
12  ret i8 %ret
13}
14
15define i8 @fold_select_trunc_nuw_false(i8 %x, i8 %y) {
16; CHECK-LABEL: @fold_select_trunc_nuw_false(
17; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
18; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
19; CHECK-NEXT:    ret i8 [[RET]]
20;
21  %trunc = trunc nuw i8 %x to i1
22  %ret = select i1 %trunc, i8 %y, i8 %x
23  ret i8 %ret
24}
25
26define i128 @fold_select_trunc_nsw_true(i128 %x, i128 %y) {
27; CHECK-LABEL: @fold_select_trunc_nsw_true(
28; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nsw i128 [[X:%.*]] to i1
29; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i128 -1, i128 [[Y:%.*]]
30; CHECK-NEXT:    ret i128 [[RET]]
31;
32  %trunc = trunc nsw i128 %x to i1
33  %ret = select i1 %trunc, i128 %x, i128 %y
34  ret i128 %ret
35}
36
37define i8 @fold_select_trunc_nsw_false(i8 %x, i8 %y) {
38; CHECK-LABEL: @fold_select_trunc_nsw_false(
39; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nsw i8 [[X:%.*]] to i1
40; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
41; CHECK-NEXT:    ret i8 [[RET]]
42;
43  %trunc = trunc nsw i8 %x to i1
44  %ret = select i1 %trunc, i8 %y, i8 %x
45  ret i8 %ret
46}
47
48define i8 @fold_select_trunc_negative(i8 %x, i8 %y) {
49; CHECK-LABEL: @fold_select_trunc_negative(
50; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
51; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[X]], i8 [[Y:%.*]]
52; CHECK-NEXT:    ret i8 [[RET]]
53;
54  %trunc = trunc i8 %x to i1
55  %ret = select i1 %trunc, i8 %x, i8 %y
56  ret i8 %ret
57}
58
59define <2 x i8> @fold_select_trunc_vector(<2 x i8> %x, <2 x i8> %y) {
60; CHECK-LABEL: @fold_select_trunc_vector(
61; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw <2 x i8> [[X:%.*]] to <2 x i1>
62; CHECK-NEXT:    [[RET:%.*]] = select <2 x i1> [[TRUNC]], <2 x i8> splat (i8 1), <2 x i8> [[Y:%.*]]
63; CHECK-NEXT:    ret <2 x i8> [[RET]]
64;
65  %trunc = trunc nuw <2 x i8> %x to <2 x i1>
66  %ret = select <2 x i1> %trunc, <2 x i8> %x, <2 x i8> %y
67  ret <2 x i8> %ret
68}
69