105 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(i32)5 6define i32 @sub_to_xor(i32 %x, i32 %y) {7; CHECK-LABEL: @sub_to_xor(8; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]9; CHECK-NEXT: ret i32 [[SUB]]10;11 %or = or i32 %x, %y12 %and = and i32 %x, %y13 %sub = sub i32 %or, %and14 ret i32 %sub15}16 17define i32 @sub_to_xor_extra_use_sub(i32 %x, i32 %y) {18; CHECK-LABEL: @sub_to_xor_extra_use_sub(19; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]20; CHECK-NEXT: call void @use(i32 [[SUB]])21; CHECK-NEXT: ret i32 [[SUB]]22;23 %or = or i32 %x, %y24 %and = and i32 %x, %y25 %sub = sub i32 %or, %and26 call void @use(i32 %sub)27 ret i32 %sub28}29 30define i32 @sub_to_xor_extra_use_and(i32 %x, i32 %y) {31; CHECK-LABEL: @sub_to_xor_extra_use_and(32; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]33; CHECK-NEXT: call void @use(i32 [[AND]])34; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X]], [[Y]]35; CHECK-NEXT: ret i32 [[SUB]]36;37 %or = or i32 %x, %y38 %and = and i32 %x, %y39 call void @use(i32 %and)40 %sub = sub i32 %or, %and41 ret i32 %sub42}43 44define i32 @sub_to_xor_extra_use_or(i32 %x, i32 %y) {45; CHECK-LABEL: @sub_to_xor_extra_use_or(46; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]47; CHECK-NEXT: call void @use(i32 [[OR]])48; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X]], [[Y]]49; CHECK-NEXT: ret i32 [[SUB]]50;51 %or = or i32 %x, %y52 call void @use(i32 %or)53 %and = and i32 %x, %y54 %sub = sub i32 %or, %and55 ret i32 %sub56}57 58define i32 @sub_to_xor_or_commuted(i32 %x, i32 %y) {59; CHECK-LABEL: @sub_to_xor_or_commuted(60; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]61; CHECK-NEXT: ret i32 [[SUB]]62;63 %or = or i32 %y, %x64 %and = and i32 %x, %y65 %sub = sub i32 %or, %and66 ret i32 %sub67}68 69define i32 @sub_to_xor_and_commuted(i32 %x, i32 %y) {70; CHECK-LABEL: @sub_to_xor_and_commuted(71; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]72; CHECK-NEXT: ret i32 [[SUB]]73;74 %or = or i32 %x, %y75 %and = and i32 %y, %x76 %sub = sub i32 %or, %and77 ret i32 %sub78}79 80define <2 x i32> @sub_to_xor_vec(<2 x i32> %x, <2 x i32> %y) {81; CHECK-LABEL: @sub_to_xor_vec(82; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[Y:%.*]], [[X:%.*]]83; CHECK-NEXT: ret <2 x i32> [[SUB]]84;85 %or = or <2 x i32> %x, %y86 %and = and <2 x i32> %y, %x87 %sub = sub <2 x i32> %or, %and88 ret <2 x i32> %sub89}90 91; Negative tests92 93define i32 @sub_to_xor_wrong_arg(i32 %x, i32 %y, i32 %z) {94; CHECK-LABEL: @sub_to_xor_wrong_arg(95; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]96; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[Z:%.*]]97; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[AND]], [[OR]]98; CHECK-NEXT: ret i32 [[SUB]]99;100 %or = or i32 %x, %y101 %and = and i32 %x, %z102 %sub = sub i32 %and, %or103 ret i32 %sub104}105