69 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 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 i17; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 1, i8 [[Y:%.*]]8; CHECK-NEXT: ret i8 [[RET]]9;10 %trunc = trunc nuw i8 %x to i111 %ret = select i1 %trunc, i8 %x, i8 %y12 ret i8 %ret13}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 i118; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 019; CHECK-NEXT: ret i8 [[RET]]20;21 %trunc = trunc nuw i8 %x to i122 %ret = select i1 %trunc, i8 %y, i8 %x23 ret i8 %ret24}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 i129; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i128 -1, i128 [[Y:%.*]]30; CHECK-NEXT: ret i128 [[RET]]31;32 %trunc = trunc nsw i128 %x to i133 %ret = select i1 %trunc, i128 %x, i128 %y34 ret i128 %ret35}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 i140; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 [[Y:%.*]], i8 041; CHECK-NEXT: ret i8 [[RET]]42;43 %trunc = trunc nsw i8 %x to i144 %ret = select i1 %trunc, i8 %y, i8 %x45 ret i8 %ret46}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 i151; CHECK-NEXT: [[RET:%.*]] = select i1 [[TRUNC]], i8 [[X]], i8 [[Y:%.*]]52; CHECK-NEXT: ret i8 [[RET]]53;54 %trunc = trunc i8 %x to i155 %ret = select i1 %trunc, i8 %x, i8 %y56 ret i8 %ret57}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> %y67 ret <2 x i8> %ret68}69