205 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare void @use.i1(i1)5declare void @use.i8(i8)6define i8 @replace_with_y_noundef(i8 %x, i8 noundef %y, i8 %z) {7; CHECK-LABEL: @replace_with_y_noundef(8; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]9; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Y]], i8 [[Z:%.*]]10; CHECK-NEXT: ret i8 [[SEL]]11;12 %cmp = icmp eq i8 %x, %y13 %and = and i8 %x, %y14 %sel = select i1 %cmp, i8 %and, i8 %z15 ret i8 %sel16}17 18define i8 @replace_with_x_noundef(i8 noundef %x, i8 %y, i8 %z) {19; CHECK-LABEL: @replace_with_x_noundef(20; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]21; CHECK-NEXT: call void @use.i1(i1 [[CMP]])22; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[X]]23; CHECK-NEXT: ret i8 [[SEL]]24;25 %cmp = icmp ne i8 %x, %y26 call void @use.i1(i1 %cmp)27 %and = or i8 %x, %y28 %sel = select i1 %cmp, i8 %z, i8 %and29 ret i8 %sel30}31 32define i8 @replace_with_x_maybe_undef_fail(i8 %x, i8 %y, i8 %z) {33; CHECK-LABEL: @replace_with_x_maybe_undef_fail(34; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], [[Y:%.*]]35; CHECK-NEXT: call void @use.i1(i1 [[CMP]])36; CHECK-NEXT: [[AND:%.*]] = or i8 [[X]], [[Y]]37; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[Z:%.*]], i8 [[AND]]38; CHECK-NEXT: ret i8 [[SEL]]39;40 %cmp = icmp ne i8 %x, %y41 call void @use.i1(i1 %cmp)42 %and = or i8 %x, %y43 %sel = select i1 %cmp, i8 %z, i8 %and44 ret i8 %sel45}46 47define i8 @replace_with_y_for_new_oneuse(i8 noundef %xx, i8 noundef %y, i8 %z) {48; CHECK-LABEL: @replace_with_y_for_new_oneuse(49; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 1350; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]51; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Y]]52; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]53; CHECK-NEXT: ret i8 [[SEL]]54;55 %x = mul i8 %xx, 1356 %cmp = icmp eq i8 %x, %y57 %add = add nuw i8 %x, %y58 %sel = select i1 %cmp, i8 %add, i8 %z59 ret i8 %sel60}61 62define i8 @replace_with_y_for_new_oneuse2(i8 %xx, i8 noundef %y, i8 %z, i8 %q) {63; CHECK-LABEL: @replace_with_y_for_new_oneuse2(64; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 1365; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]66; CHECK-NEXT: [[ADD:%.*]] = add nuw i8 [[X]], [[Q:%.*]]67; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 [[Z:%.*]]68; CHECK-NEXT: ret i8 [[SEL]]69;70 %x = mul i8 %xx, 1371 %cmp = icmp eq i8 %x, %y72 %add = add nuw i8 %x, %q73 %sel = select i1 %cmp, i8 %add, i8 %z74 ret i8 %sel75}76 77define i8 @replace_with_x_for_new_oneuse(i8 noundef %xx, i8 noundef %yy, i8 %z, i8 %w) {78; CHECK-LABEL: @replace_with_x_for_new_oneuse(79; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 1380; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]81; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]82; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]83; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]84; CHECK-NEXT: ret i8 [[SEL]]85;86 %x = mul i8 %xx, 1387 %y = add i8 %yy, %w88 %cmp = icmp eq i8 %x, %y89 %mul = mul i8 %x, %y90 %sel = select i1 %cmp, i8 %mul, i8 %z91 ret i8 %sel92}93 94define i8 @replace_with_x_for_new_oneuse2(i8 noundef %xx, i8 %yy, i8 %z, i8 %w, i8 %q) {95; CHECK-LABEL: @replace_with_x_for_new_oneuse2(96; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 1397; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]98; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]99; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[Q:%.*]], [[Y]]100; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]101; CHECK-NEXT: ret i8 [[SEL]]102;103 %x = mul i8 %xx, 13104 %y = add i8 %yy, %w105 %cmp = icmp eq i8 %x, %y106 %mul = mul i8 %q, %y107 %sel = select i1 %cmp, i8 %mul, i8 %z108 ret i8 %sel109}110 111define i8 @replace_with_x_for_simple_binop(i8 noundef %xx, i8 %yy, i8 %z, i8 %w) {112; CHECK-LABEL: @replace_with_x_for_simple_binop(113; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13114; CHECK-NEXT: [[Y:%.*]] = add i8 [[YY:%.*]], [[W:%.*]]115; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y]]116; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]117; CHECK-NEXT: call void @use.i8(i8 [[Y]])118; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]119; CHECK-NEXT: ret i8 [[SEL]]120;121 %x = mul i8 %xx, 13122 %y = add i8 %yy, %w123 %cmp = icmp eq i8 %x, %y124 %mul = mul i8 %x, %y125 call void @use.i8(i8 %y)126 %sel = select i1 %cmp, i8 %mul, i8 %z127 ret i8 %sel128}129 130define i8 @replace_with_none_for_new_oneuse_fail_maybe_undef(i8 %xx, i8 %y, i8 %z) {131; CHECK-LABEL: @replace_with_none_for_new_oneuse_fail_maybe_undef(132; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], 13133; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]134; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[X]], [[Y]]135; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]136; CHECK-NEXT: ret i8 [[SEL]]137;138 %x = mul i8 %xx, 13139 %cmp = icmp eq i8 %x, %y140 %mul = mul i8 %x, %y141 %sel = select i1 %cmp, i8 %mul, i8 %z142 ret i8 %sel143}144 145define i8 @replace_with_y_for_simple_binop(i8 %x, i8 noundef %y, i8 %z) {146; CHECK-LABEL: @replace_with_y_for_simple_binop(147; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]148; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]149; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]150; CHECK-NEXT: ret i8 [[SEL]]151;152 %cmp = icmp eq i8 %x, %y153 %mul = mul nsw i8 %x, %y154 %sel = select i1 %cmp, i8 %mul, i8 %z155 ret i8 %sel156}157 158define i8 @replace_with_y_for_simple_binop_fail_multiuse(i8 %x, i8 noundef %y, i8 %z) {159; CHECK-LABEL: @replace_with_y_for_simple_binop_fail_multiuse(160; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]161; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Y]]162; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]163; CHECK-NEXT: call void @use.i8(i8 [[MUL]])164; CHECK-NEXT: ret i8 [[SEL]]165;166 %cmp = icmp eq i8 %x, %y167 %mul = mul nsw i8 %x, %y168 %sel = select i1 %cmp, i8 %mul, i8 %z169 call void @use.i8(i8 %mul)170 ret i8 %sel171}172 173define i8 @replace_with_y_for_simple_binop_fail(i8 %x, i8 noundef %y, i8 %z, i8 %q) {174; CHECK-LABEL: @replace_with_y_for_simple_binop_fail(175; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]176; CHECK-NEXT: [[MUL:%.*]] = mul nsw i8 [[X]], [[Q:%.*]]177; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[MUL]], i8 [[Z:%.*]]178; CHECK-NEXT: ret i8 [[SEL]]179;180 %cmp = icmp eq i8 %x, %y181 %mul = mul nsw i8 %x, %q182 %sel = select i1 %cmp, i8 %mul, i8 %z183 ret i8 %sel184}185 186; Make sure we don't run into an infinite loop.187define i32 @pr142405(i32 noundef %x) {188; CHECK-LABEL: @pr142405(189; CHECK-NEXT: entry:190; CHECK-NEXT: [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[X:%.*]], i32 0)191; CHECK-NEXT: [[MASKED:%.*]] = and i32 [[SMAX]], 65535192; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], [[MASKED]]193; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[SMAX]], 1194; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP]], i32 [[TMP0]], i32 0195; CHECK-NEXT: ret i32 [[AND]]196;197entry:198 %smax = call i32 @llvm.smax.i32(i32 %x, i32 0)199 %masked = and i32 %smax, 65535200 %cmp = icmp eq i32 %x, %masked201 %sel = select i1 %cmp, i32 %smax, i32 0202 %and = and i32 %sel, 1203 ret i32 %and204}205