293 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=reassociate,gvn,bdce -S | FileCheck %s3 4; (~(a | b) & c) | ~(a | (b | c)) -> ~(a | b)5; (~(a | b) & c) | ~(b | (a | c)) -> ~(a | b)6 7define i32 @not_or_and_or_not_or_or(i32 %a, i32 %b, i32 %c) {8; CHECK-LABEL: @not_or_and_or_not_or_or(9; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]10; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -111; CHECK-NEXT: ret i32 [[NOT2]]12;13 %or1 = or i32 %b, %c14 %or2 = or i32 %or1, %a15 %not1 = xor i32 %or2, -116 %or3 = or i32 %b, %a17 %not2 = xor i32 %or3, -118 %and2 = and i32 %not2, %c19 %or4 = or i32 %and2, %not120 ret i32 %or421}22 23define i32 @not_or_and_or_not_or_or_commute1(i32 %a, i32 %b, i32 %c) {24; CHECK-LABEL: @not_or_and_or_not_or_or_commute1(25; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]26; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -127; CHECK-NEXT: ret i32 [[NOT2]]28;29 %or1 = or i32 %a, %c30 %or2 = or i32 %or1, %b31 %not1 = xor i32 %or2, -132 %or3 = or i32 %b, %a33 %not2 = xor i32 %or3, -134 %and2 = and i32 %not2, %c35 %or4 = or i32 %and2, %not136 ret i32 %or437}38 39define i32 @not_or_and_or_not_or_or_commute2(i32 %a, i32 %b, i32 %c) {40; CHECK-LABEL: @not_or_and_or_not_or_or_commute2(41; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]42; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -143; CHECK-NEXT: ret i32 [[NOT2]]44;45 %or1 = or i32 %c, %b46 %or2 = or i32 %or1, %a47 %not1 = xor i32 %or2, -148 %or3 = or i32 %b, %a49 %not2 = xor i32 %or3, -150 %and2 = and i32 %not2, %c51 %or4 = or i32 %and2, %not152 ret i32 %or453}54 55define i32 @not_or_and_or_not_or_or_commute3(i32 %a0, i32 %b, i32 %c) {56; CHECK-LABEL: @not_or_and_or_not_or_or_commute3(57; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]58; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A]], [[B:%.*]]59; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -160; CHECK-NEXT: ret i32 [[NOT2]]61;62 %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization63 %or1 = or i32 %b, %c64 %or2 = or i32 %a, %or165 %not1 = xor i32 %or2, -166 %or3 = or i32 %a, %b67 %not2 = xor i32 %or3, -168 %and2 = and i32 %not2, %c69 %or4 = or i32 %and2, %not170 ret i32 %or471}72 73define i32 @not_or_and_or_not_or_or_commute4(i32 %a, i32 %b0, i32 %c) {74; CHECK-LABEL: @not_or_and_or_not_or_or_commute4(75; CHECK-NEXT: [[B:%.*]] = sdiv i32 42, [[B0:%.*]]76; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B]], [[A:%.*]]77; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -178; CHECK-NEXT: ret i32 [[NOT2]]79;80 %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization81 %or1 = or i32 %a, %c82 %or2 = or i32 %b, %or183 %not1 = xor i32 %or2, -184 %or3 = or i32 %b, %a85 %not2 = xor i32 %or3, -186 %and2 = and i32 %not2, %c87 %or4 = or i32 %and2, %not188 ret i32 %or489}90 91define i32 @not_or_and_or_not_or_or_commute5(i32 %a, i32 %b, i32 %c0) {92; CHECK-LABEL: @not_or_and_or_not_or_or_commute5(93; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]94; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -195; CHECK-NEXT: ret i32 [[NOT2]]96;97 %c = sdiv i32 42, %c0 ; thwart complexity-based canonicalization98 %or1 = or i32 %c, %a99 %or2 = or i32 %or1, %b100 %not1 = xor i32 %or2, -1101 %or3 = or i32 %b, %a102 %not2 = xor i32 %or3, -1103 %and2 = and i32 %c, %not2104 %or4 = or i32 %and2, %not1105 ret i32 %or4106}107 108define i32 @not_or_and_or_not_or_or_use1(i32 %a, i32 %b, i32 %c) {109; CHECK-LABEL: @not_or_and_or_not_or_or_use1(110; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]111; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[C:%.*]]112; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1113; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1114; CHECK-NEXT: call void @use(i32 [[NOT1]])115; CHECK-NEXT: ret i32 [[NOT2]]116;117 %or1 = or i32 %b, %c118 %or2 = or i32 %or1, %a119 %not1 = xor i32 %or2, -1120 %or3 = or i32 %b, %a121 %not2 = xor i32 %or3, -1122 %and2 = and i32 %not2, %c123 %or4 = or i32 %and2, %not1124 call void @use(i32 %not1)125 ret i32 %or4126}127 128define i32 @not_or_and_or_not_or_or_use2(i32 %a, i32 %b, i32 %c) {129; CHECK-LABEL: @not_or_and_or_not_or_or_use2(130; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]131; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[C:%.*]]132; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1133; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1134; CHECK-NEXT: call void @use(i32 [[NOT1]])135; CHECK-NEXT: ret i32 [[NOT2]]136;137 %or1 = or i32 %a, %c138 %or2 = or i32 %or1, %b139 %not1 = xor i32 %or2, -1140 %or3 = or i32 %b, %a141 %not2 = xor i32 %or3, -1142 %and2 = and i32 %not2, %c143 %or4 = or i32 %and2, %not1144 call void @use(i32 %not1)145 ret i32 %or4146}147 148; (~(a & b) | c) & ~(a & (b & c)) -> ~(a & b)149; (~(a & b) | c) & ~(b & (a & c)) -> ~(a & b)150 151define i32 @not_and_or_and_not_and_and(i32 %a, i32 %b, i32 %c) {152; CHECK-LABEL: @not_and_or_and_not_and_and(153; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]154; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1155; CHECK-NEXT: ret i32 [[NOT2]]156;157 %and1 = and i32 %b, %c158 %and2 = and i32 %and1, %a159 %not1 = xor i32 %and2, -1160 %and3 = and i32 %b, %a161 %not2 = xor i32 %and3, -1162 %or2 = or i32 %not2, %c163 %and4 = and i32 %or2, %not1164 ret i32 %and4165}166 167define i32 @not_and_or_and_not_and_and_commute1(i32 %a, i32 %b, i32 %c) {168; CHECK-LABEL: @not_and_or_and_not_and_and_commute1(169; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]170; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1171; CHECK-NEXT: ret i32 [[NOT2]]172;173 %and1 = and i32 %a, %c174 %and2 = and i32 %and1, %b175 %not1 = xor i32 %and2, -1176 %and3 = and i32 %b, %a177 %not2 = xor i32 %and3, -1178 %or2 = or i32 %not2, %c179 %and4 = and i32 %or2, %not1180 ret i32 %and4181}182 183define i32 @not_and_or_and_not_and_and_commute2(i32 %a, i32 %b, i32 %c) {184; CHECK-LABEL: @not_and_or_and_not_and_and_commute2(185; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]186; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1187; CHECK-NEXT: ret i32 [[NOT2]]188;189 %and1 = and i32 %c, %b190 %and2 = and i32 %and1, %a191 %not1 = xor i32 %and2, -1192 %and3 = and i32 %b, %a193 %not2 = xor i32 %and3, -1194 %or2 = or i32 %not2, %c195 %and4 = and i32 %or2, %not1196 ret i32 %and4197}198 199define i32 @not_and_or_and_not_and_and_commute3(i32 %a0, i32 %b, i32 %c) {200; CHECK-LABEL: @not_and_or_and_not_and_and_commute3(201; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]202; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[B:%.*]]203; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1204; CHECK-NEXT: ret i32 [[NOT2]]205;206 %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization207 %and1 = and i32 %b, %c208 %and2 = and i32 %a, %and1209 %not1 = xor i32 %and2, -1210 %and3 = and i32 %a, %b211 %not2 = xor i32 %and3, -1212 %or2 = or i32 %not2, %c213 %and4 = and i32 %or2, %not1214 ret i32 %and4215}216 217define i32 @not_and_or_and_not_and_and_commute4(i32 %a, i32 %b0, i32 %c) {218; CHECK-LABEL: @not_and_or_and_not_and_and_commute4(219; CHECK-NEXT: [[B:%.*]] = sdiv i32 42, [[B0:%.*]]220; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B]], [[A:%.*]]221; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1222; CHECK-NEXT: ret i32 [[NOT2]]223;224 %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization225 %and1 = and i32 %a, %c226 %and2 = and i32 %b, %and1227 %not1 = xor i32 %and2, -1228 %and3 = and i32 %b, %a229 %not2 = xor i32 %and3, -1230 %or2 = or i32 %not2, %c231 %and4 = and i32 %or2, %not1232 ret i32 %and4233}234 235define i32 @not_and_or_and_not_and_and_commute5(i32 %a, i32 %b, i32 %c0) {236; CHECK-LABEL: @not_and_or_and_not_and_and_commute5(237; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]238; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1239; CHECK-NEXT: ret i32 [[NOT2]]240;241 %c = sdiv i32 42, %c0 ; thwart complexity-based canonicalization242 %and1 = and i32 %c, %a243 %and2 = and i32 %and1, %b244 %not1 = xor i32 %and2, -1245 %and3 = and i32 %b, %a246 %not2 = xor i32 %and3, -1247 %or2 = or i32 %c, %not2248 %and4 = and i32 %or2, %not1249 ret i32 %and4250}251 252define i32 @not_and_or_and_not_and_and_use1(i32 %a, i32 %b, i32 %c) {253; CHECK-LABEL: @not_and_or_and_not_and_and_use1(254; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]255; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[C:%.*]]256; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[AND2]], -1257; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1258; CHECK-NEXT: call void @use(i32 [[NOT1]])259; CHECK-NEXT: ret i32 [[NOT2]]260;261 %and1 = and i32 %b, %c262 %and2 = and i32 %and1, %a263 %not1 = xor i32 %and2, -1264 %and3 = and i32 %b, %a265 %not2 = xor i32 %and3, -1266 %or2 = or i32 %not2, %c267 %and4 = and i32 %or2, %not1268 call void @use(i32 %not1)269 ret i32 %and4270}271 272define i32 @not_and_or_and_not_and_and_use2(i32 %a, i32 %b, i32 %c) {273; CHECK-LABEL: @not_and_or_and_not_and_and_use2(274; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]275; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[C:%.*]]276; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[AND2]], -1277; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1278; CHECK-NEXT: call void @use(i32 [[NOT1]])279; CHECK-NEXT: ret i32 [[NOT2]]280;281 %and1 = and i32 %a, %c282 %and2 = and i32 %and1, %b283 %not1 = xor i32 %and2, -1284 %and3 = and i32 %b, %a285 %not2 = xor i32 %and3, -1286 %or2 = or i32 %not2, %c287 %and4 = and i32 %or2, %not1288 call void @use(i32 %not1)289 ret i32 %and4290}291 292declare void @use(i32)293