195 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=instcombine -S < %s | FileCheck %s3 4declare void @use(i8)5 6define i8 @basic(i8 %x, i8 %y) {7; CHECK-LABEL: @basic(8; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]9; CHECK-NEXT: ret i8 [[NOTA]]10;11 %notx = xor i8 %x, -112 %a = add i8 %notx, %y13 %nota = xor i8 %a, -114 ret i8 %nota15}16 17define i8 @basic_com_add(i8 %x, i8 %y) {18; CHECK-LABEL: @basic_com_add(19; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[Y:%.*]], [[X:%.*]]20; CHECK-NEXT: ret i8 [[NOTA]]21;22 %noty = xor i8 %y, -123 %a = add i8 %x, %noty24 %nota = xor i8 %a, -125 ret i8 %nota26}27 28define i8 @basic_use_xor(i8 %x, i8 %y) {29; CHECK-LABEL: @basic_use_xor(30; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -131; CHECK-NEXT: call void @use(i8 [[NOTX]])32; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y:%.*]]33; CHECK-NEXT: ret i8 [[NOTA]]34;35 %notx = xor i8 %x, -136 call void @use(i8 %notx)37 %a = add i8 %notx, %y38 %nota = xor i8 %a, -139 ret i8 %nota40}41 42define i8 @basic_use_add(i8 %x, i8 %y) {43; CHECK-LABEL: @basic_use_add(44; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -145; CHECK-NEXT: [[A:%.*]] = add i8 [[Y:%.*]], [[NOTX]]46; CHECK-NEXT: call void @use(i8 [[A]])47; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]48; CHECK-NEXT: ret i8 [[NOTA]]49;50 %notx = xor i8 %x, -151 %a = add i8 %notx, %y52 call void @use(i8 %a)53 %nota = xor i8 %a, -154 ret i8 %nota55}56 57define i8 @basic_use_both(i8 %x, i8 %y) {58; CHECK-LABEL: @basic_use_both(59; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -160; CHECK-NEXT: call void @use(i8 [[NOTX]])61; CHECK-NEXT: [[A:%.*]] = add i8 [[Y:%.*]], [[NOTX]]62; CHECK-NEXT: call void @use(i8 [[A]])63; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]64; CHECK-NEXT: ret i8 [[NOTA]]65;66 %notx = xor i8 %x, -167 call void @use(i8 %notx)68 %a = add i8 %notx, %y69 call void @use(i8 %a)70 %nota = xor i8 %a, -171 ret i8 %nota72}73 74define i8 @basic_preserve_nsw(i8 %x, i8 %y) {75; CHECK-LABEL: @basic_preserve_nsw(76; CHECK-NEXT: [[NOTA:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]77; CHECK-NEXT: ret i8 [[NOTA]]78;79 %notx = xor i8 %x, -180 %a = add nsw i8 %notx, %y81 %nota = xor i8 %a, -182 ret i8 %nota83}84 85define i8 @basic_preserve_nuw(i8 %x, i8 %y) {86; CHECK-LABEL: @basic_preserve_nuw(87; CHECK-NEXT: [[NOTA:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]88; CHECK-NEXT: ret i8 [[NOTA]]89;90 %notx = xor i8 %x, -191 %a = add nuw i8 %notx, %y92 %nota = xor i8 %a, -193 ret i8 %nota94}95 96define i8 @basic_preserve_nuw_nsw(i8 %x, i8 %y) {97; CHECK-LABEL: @basic_preserve_nuw_nsw(98; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw i8 [[X:%.*]], [[Y:%.*]]99; CHECK-NEXT: ret i8 [[NOTA]]100;101 %notx = xor i8 %x, -1102 %a = add nuw nsw i8 %notx, %y103 %nota = xor i8 %a, -1104 ret i8 %nota105}106 107define <4 x i32> @vector_test(<4 x i32> %x, <4 x i32> %y) {108; CHECK-LABEL: @vector_test(109; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]110; CHECK-NEXT: ret <4 x i32> [[NOTA]]111;112 %notx = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>113 %a = add <4 x i32> %notx, %y114 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>115 ret <4 x i32> %nota116}117 118define <4 x i32> @vector_test_poison(<4 x i32> %x, <4 x i32> %y) {119; CHECK-LABEL: @vector_test_poison(120; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]121; CHECK-NEXT: ret <4 x i32> [[NOTA]]122;123 %notx = xor <4 x i32> %x, <i32 -1, i32 poison, i32 poison, i32 -1>124 %a = add <4 x i32> %notx, %y125 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 poison, i32 poison>126 ret <4 x i32> %nota127}128 129 130define <4 x i32> @vector_test_poison_nsw_nuw(<4 x i32> %x, <4 x i32> %y) {131; CHECK-LABEL: @vector_test_poison_nsw_nuw(132; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw <4 x i32> [[X:%.*]], [[Y:%.*]]133; CHECK-NEXT: ret <4 x i32> [[NOTA]]134;135 %notx = xor <4 x i32> %x, <i32 -1, i32 poison, i32 poison, i32 -1>136 %a = add nsw nuw <4 x i32> %notx, %y137 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 poison, i32 poison>138 ret <4 x i32> %nota139}140 141define i32 @pr50308(i1 %c1, i32 %v1, i32 %v2, i32 %v3) {142; CHECK-LABEL: @pr50308(143; CHECK-NEXT: entry:144; CHECK-NEXT: br i1 [[C1:%.*]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]145; CHECK: cond.true:146; CHECK-NEXT: [[TMP0:%.*]] = sub i32 -2, [[V1:%.*]]147; CHECK-NEXT: [[ADD1_NEG:%.*]] = xor i32 [[TMP0]], [[V2:%.*]]148; CHECK-NEXT: br label [[COND_END]]149; CHECK: cond.end:150; CHECK-NEXT: [[COND_NEG:%.*]] = phi i32 [ [[ADD1_NEG]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]151; CHECK-NEXT: [[SUB:%.*]] = add i32 [[COND_NEG]], [[V3:%.*]]152; CHECK-NEXT: ret i32 [[SUB]]153;154entry:155 br i1 %c1, label %cond.true, label %cond.end156 157cond.true:158 %add = add nsw i32 1, %v1159 %xor = xor i32 %add, %v2160 %add1 = add nsw i32 1, %xor161 br label %cond.end162 163cond.end:164 %cond = phi i32 [ %add1, %cond.true ], [ 0, %entry ]165 %sub = sub nsw i32 %v3, %cond166 ret i32 %sub167}168 169@g = extern_weak global i32170define void @pr50370(i32 %x) {171; CHECK-LABEL: @pr50370(172; CHECK-NEXT: entry:173; CHECK-NEXT: store i32 poison, ptr undef, align 4174; CHECK-NEXT: ret void175;176entry:177 %xor = xor i32 %x, 1178 %cmp = icmp eq ptr @g, null179 %ext = zext i1 %cmp to i32180 %or = or i32 %ext, 1181 %or4 = or i32 %or, 65536182 %B6 = ashr i32 65536, %or4183 %B15 = srem i32 %B6, %xor184 %B20 = sdiv i32 %or4, 2147483647185 %B22 = add i32 %B15, %B20186 %B14 = srem i32 %B6, %B22187 %B12 = add i32 %B15, %B6188 %B8 = shl i32 %B20, %B14189 %B2 = xor i32 %B12, %B8190 %B3 = or i32 %B12, undef191 %B = xor i32 %B2, %B3192 store i32 %B, ptr undef, align 4193 ret void194}195