1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3 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, %y 13 %and = and i8 %x, %y 14 %sel = select i1 %cmp, i8 %and, i8 %z 15 ret i8 %sel 16} 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, %y 26 call void @use.i1(i1 %cmp) 27 %and = or i8 %x, %y 28 %sel = select i1 %cmp, i8 %z, i8 %and 29 ret i8 %sel 30} 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, %y 41 call void @use.i1(i1 %cmp) 42 %and = or i8 %x, %y 43 %sel = select i1 %cmp, i8 %z, i8 %and 44 ret i8 %sel 45} 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:%.*]], 13 50; 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, 13 56 %cmp = icmp eq i8 %x, %y 57 %add = add nuw i8 %x, %y 58 %sel = select i1 %cmp, i8 %add, i8 %z 59 ret i8 %sel 60} 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:%.*]], 13 65; 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, 13 71 %cmp = icmp eq i8 %x, %y 72 %add = add nuw i8 %x, %q 73 %sel = select i1 %cmp, i8 %add, i8 %z 74 ret i8 %sel 75} 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:%.*]], 13 80; 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, 13 87 %y = add i8 %yy, %w 88 %cmp = icmp eq i8 %x, %y 89 %mul = mul i8 %x, %y 90 %sel = select i1 %cmp, i8 %mul, i8 %z 91 ret i8 %sel 92} 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:%.*]], 13 97; 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, 13 104 %y = add i8 %yy, %w 105 %cmp = icmp eq i8 %x, %y 106 %mul = mul i8 %q, %y 107 %sel = select i1 %cmp, i8 %mul, i8 %z 108 ret i8 %sel 109} 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:%.*]], 13 114; 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, 13 122 %y = add i8 %yy, %w 123 %cmp = icmp eq i8 %x, %y 124 %mul = mul i8 %x, %y 125 call void @use.i8(i8 %y) 126 %sel = select i1 %cmp, i8 %mul, i8 %z 127 ret i8 %sel 128} 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:%.*]], 13 133; 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, 13 139 %cmp = icmp eq i8 %x, %y 140 %mul = mul i8 %x, %y 141 %sel = select i1 %cmp, i8 %mul, i8 %z 142 ret i8 %sel 143} 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, %y 153 %mul = mul nsw i8 %x, %y 154 %sel = select i1 %cmp, i8 %mul, i8 %z 155 ret i8 %sel 156} 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, %y 167 %mul = mul nsw i8 %x, %y 168 %sel = select i1 %cmp, i8 %mul, i8 %z 169 call void @use.i8(i8 %mul) 170 ret i8 %sel 171} 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, %y 181 %mul = mul nsw i8 %x, %q 182 %sel = select i1 %cmp, i8 %mul, i8 %z 183 ret i8 %sel 184} 185