xref: /llvm-project/llvm/test/Transforms/InstCombine/fold-select-trunc.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
143c6fb29Sc8ef; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
243c6fb29Sc8ef; RUN: opt < %s -passes=instcombine -S | FileCheck %s
343c6fb29Sc8ef
443c6fb29Sc8efdefine i8 @fold_select_trunc_nuw_true(i8 %x, i8 %y) {
543c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_nuw_true(
643c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
743c6fb29Sc8ef; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 1, i8 [[Y:%.*]]
843c6fb29Sc8ef; CHECK-NEXT:    ret i8 [[RET]]
943c6fb29Sc8ef;
1043c6fb29Sc8ef  %trunc = trunc nuw i8 %x to i1
1143c6fb29Sc8ef  %ret = select i1 %trunc, i8 %x, i8 %y
1243c6fb29Sc8ef  ret i8 %ret
1343c6fb29Sc8ef}
1443c6fb29Sc8ef
1543c6fb29Sc8efdefine i8 @fold_select_trunc_nuw_false(i8 %x, i8 %y) {
1643c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_nuw_false(
1743c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
1843c6fb29Sc8ef; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
1943c6fb29Sc8ef; CHECK-NEXT:    ret i8 [[RET]]
2043c6fb29Sc8ef;
2143c6fb29Sc8ef  %trunc = trunc nuw i8 %x to i1
2243c6fb29Sc8ef  %ret = select i1 %trunc, i8 %y, i8 %x
2343c6fb29Sc8ef  ret i8 %ret
2443c6fb29Sc8ef}
2543c6fb29Sc8ef
2643c6fb29Sc8efdefine i128 @fold_select_trunc_nsw_true(i128 %x, i128 %y) {
2743c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_nsw_true(
2843c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nsw i128 [[X:%.*]] to i1
2943c6fb29Sc8ef; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i128 -1, i128 [[Y:%.*]]
3043c6fb29Sc8ef; CHECK-NEXT:    ret i128 [[RET]]
3143c6fb29Sc8ef;
3243c6fb29Sc8ef  %trunc = trunc nsw i128 %x to i1
3343c6fb29Sc8ef  %ret = select i1 %trunc, i128 %x, i128 %y
3443c6fb29Sc8ef  ret i128 %ret
3543c6fb29Sc8ef}
3643c6fb29Sc8ef
3743c6fb29Sc8efdefine i8 @fold_select_trunc_nsw_false(i8 %x, i8 %y) {
3843c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_nsw_false(
3943c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nsw i8 [[X:%.*]] to i1
4043c6fb29Sc8ef; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 0
4143c6fb29Sc8ef; CHECK-NEXT:    ret i8 [[RET]]
4243c6fb29Sc8ef;
4343c6fb29Sc8ef  %trunc = trunc nsw i8 %x to i1
4443c6fb29Sc8ef  %ret = select i1 %trunc, i8 %y, i8 %x
4543c6fb29Sc8ef  ret i8 %ret
4643c6fb29Sc8ef}
4743c6fb29Sc8ef
4843c6fb29Sc8efdefine i8 @fold_select_trunc_negative(i8 %x, i8 %y) {
4943c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_negative(
5043c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
5143c6fb29Sc8ef; CHECK-NEXT:    [[RET:%.*]] = select i1 [[TRUNC]], i8 [[X]], i8 [[Y:%.*]]
5243c6fb29Sc8ef; CHECK-NEXT:    ret i8 [[RET]]
5343c6fb29Sc8ef;
5443c6fb29Sc8ef  %trunc = trunc i8 %x to i1
5543c6fb29Sc8ef  %ret = select i1 %trunc, i8 %x, i8 %y
5643c6fb29Sc8ef  ret i8 %ret
5743c6fb29Sc8ef}
5843c6fb29Sc8ef
5943c6fb29Sc8efdefine <2 x i8> @fold_select_trunc_vector(<2 x i8> %x, <2 x i8> %y) {
6043c6fb29Sc8ef; CHECK-LABEL: @fold_select_trunc_vector(
6143c6fb29Sc8ef; CHECK-NEXT:    [[TRUNC:%.*]] = trunc nuw <2 x i8> [[X:%.*]] to <2 x i1>
62*38fffa63SPaul Walker; CHECK-NEXT:    [[RET:%.*]] = select <2 x i1> [[TRUNC]], <2 x i8> splat (i8 1), <2 x i8> [[Y:%.*]]
6343c6fb29Sc8ef; CHECK-NEXT:    ret <2 x i8> [[RET]]
6443c6fb29Sc8ef;
6543c6fb29Sc8ef  %trunc = trunc nuw <2 x i8> %x to <2 x i1>
6643c6fb29Sc8ef  %ret = select <2 x i1> %trunc, <2 x i8> %x, <2 x i8> %y
6743c6fb29Sc8ef  ret <2 x i8> %ret
6843c6fb29Sc8ef}
69