brintos

brintos / llvm-project-archived public Read only

0
0
Text · 63.2 KiB · e6de063 Raw
1640 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare i1 @gen()5 6declare void @use(i8)7declare void @use1(i1)8declare void @use2(<2 x i1>)9 10define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) {11; CHECK-LABEL: @foo(12; CHECK-NEXT:    [[E_NOT:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]13; CHECK-NEXT:    [[J:%.*]] = select i1 [[E_NOT]], i32 [[C:%.*]], i32 [[D:%.*]]14; CHECK-NEXT:    ret i32 [[J]]15;16  %e = icmp slt i32 %a, %b17  %f = sext i1 %e to i3218  %g = and i32 %c, %f19  %h = xor i32 %f, -120  %i = and i32 %d, %h21  %j = or i32 %g, %i22  ret i32 %j23}24 25define i32 @bar(i32 %a, i32 %b, i32 %c, i32 %d) {26; CHECK-LABEL: @bar(27; CHECK-NEXT:    [[E_NOT:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]28; CHECK-NEXT:    [[J:%.*]] = select i1 [[E_NOT]], i32 [[C:%.*]], i32 [[D:%.*]]29; CHECK-NEXT:    ret i32 [[J]]30;31  %e = icmp slt i32 %a, %b32  %f = sext i1 %e to i3233  %g = and i32 %c, %f34  %h = xor i32 %f, -135  %i = and i32 %d, %h36  %j = or i32 %i, %g37  ret i32 %j38}39 40define i32 @goo(i32 %a, i32 %b, i32 %c, i32 %d) {41; CHECK-LABEL: @goo(42; CHECK-NEXT:    [[T0_NOT:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]43; CHECK-NEXT:    [[T3:%.*]] = select i1 [[T0_NOT]], i32 [[C:%.*]], i32 [[D:%.*]]44; CHECK-NEXT:    ret i32 [[T3]]45;46  %t0 = icmp slt i32 %a, %b47  %iftmp.0.0 = select i1 %t0, i32 -1, i32 048  %t1 = and i32 %iftmp.0.0, %c49  %not = xor i32 %iftmp.0.0, -150  %t2 = and i32 %not, %d51  %t3 = or i32 %t1, %t252  ret i32 %t353}54 55define i32 @poo(i32 %a, i32 %b, i32 %c, i32 %d) {56; CHECK-LABEL: @poo(57; CHECK-NEXT:    [[T0_NOT:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]58; CHECK-NEXT:    [[T3:%.*]] = select i1 [[T0_NOT]], i32 [[C:%.*]], i32 [[D:%.*]]59; CHECK-NEXT:    ret i32 [[T3]]60;61  %t0 = icmp slt i32 %a, %b62  %iftmp.0.0 = select i1 %t0, i32 -1, i32 063  %t1 = and i32 %iftmp.0.0, %c64  %iftmp = select i1 %t0, i32 0, i32 -165  %t2 = and i32 %iftmp, %d66  %t3 = or i32 %t1, %t267  ret i32 %t368}69 70; PR32791 - https://bugs.llvm.org//show_bug.cgi?id=3279171; The 2nd compare/select are canonicalized, so CSE and another round of instcombine or some other pass will fold this.72 73define i32 @fold_inverted_icmp_preds(i32 %a, i32 %b, i32 %c, i32 %d) {74; CHECK-LABEL: @fold_inverted_icmp_preds(75; CHECK-NEXT:    [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]76; CHECK-NEXT:    [[SEL1:%.*]] = select i1 [[CMP1]], i32 [[C:%.*]], i32 077; CHECK-NEXT:    [[CMP2_NOT:%.*]] = icmp slt i32 [[A]], [[B]]78; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[CMP2_NOT]], i32 0, i32 [[D:%.*]]79; CHECK-NEXT:    [[OR:%.*]] = or i32 [[SEL1]], [[SEL2]]80; CHECK-NEXT:    ret i32 [[OR]]81;82  %cmp1 = icmp slt i32 %a, %b83  %sel1 = select i1 %cmp1, i32 %c, i32 084  %cmp2 = icmp sge i32 %a, %b85  %sel2 = select i1 %cmp2, i32 %d, i32 086  %or = or i32 %sel1, %sel287  ret i32 %or88}89 90; The 2nd compare/select are canonicalized, so CSE and another round of instcombine or some other pass will fold this.91 92define i32 @fold_inverted_icmp_preds_reverse(i32 %a, i32 %b, i32 %c, i32 %d) {93; CHECK-LABEL: @fold_inverted_icmp_preds_reverse(94; CHECK-NEXT:    [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]95; CHECK-NEXT:    [[SEL1:%.*]] = select i1 [[CMP1]], i32 0, i32 [[C:%.*]]96; CHECK-NEXT:    [[CMP2_NOT:%.*]] = icmp slt i32 [[A]], [[B]]97; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[CMP2_NOT]], i32 [[D:%.*]], i32 098; CHECK-NEXT:    [[OR:%.*]] = or i32 [[SEL1]], [[SEL2]]99; CHECK-NEXT:    ret i32 [[OR]]100;101  %cmp1 = icmp slt i32 %a, %b102  %sel1 = select i1 %cmp1, i32 0, i32 %c103  %cmp2 = icmp sge i32 %a, %b104  %sel2 = select i1 %cmp2, i32 0, i32 %d105  %or = or i32 %sel1, %sel2106  ret i32 %or107}108 109; TODO: Should fcmp have the same sort of predicate canonicalization as icmp?110 111define i32 @fold_inverted_fcmp_preds(float %a, float %b, i32 %c, i32 %d) {112; CHECK-LABEL: @fold_inverted_fcmp_preds(113; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[A:%.*]], [[B:%.*]]114; CHECK-NEXT:    [[SEL1:%.*]] = select i1 [[CMP1]], i32 [[C:%.*]], i32 0115; CHECK-NEXT:    [[CMP2:%.*]] = fcmp uge float [[A]], [[B]]116; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[CMP2]], i32 [[D:%.*]], i32 0117; CHECK-NEXT:    [[OR:%.*]] = or i32 [[SEL1]], [[SEL2]]118; CHECK-NEXT:    ret i32 [[OR]]119;120  %cmp1 = fcmp olt float %a, %b121  %sel1 = select i1 %cmp1, i32 %c, i32 0122  %cmp2 = fcmp uge float %a, %b123  %sel2 = select i1 %cmp2, i32 %d, i32 0124  %or = or i32 %sel1, %sel2125  ret i32 %or126}127 128; The 2nd compare/select are canonicalized, so CSE and another round of instcombine or some other pass will fold this.129 130define <2 x i32> @fold_inverted_icmp_vector_preds(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c, <2 x i32> %d) {131; CHECK-LABEL: @fold_inverted_icmp_vector_preds(132; CHECK-NEXT:    [[CMP1_NOT:%.*]] = icmp eq <2 x i32> [[A:%.*]], [[B:%.*]]133; CHECK-NEXT:    [[SEL1:%.*]] = select <2 x i1> [[CMP1_NOT]], <2 x i32> zeroinitializer, <2 x i32> [[C:%.*]]134; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq <2 x i32> [[A]], [[B]]135; CHECK-NEXT:    [[SEL2:%.*]] = select <2 x i1> [[CMP2]], <2 x i32> [[D:%.*]], <2 x i32> zeroinitializer136; CHECK-NEXT:    [[OR:%.*]] = or <2 x i32> [[SEL1]], [[SEL2]]137; CHECK-NEXT:    ret <2 x i32> [[OR]]138;139  %cmp1 = icmp ne <2 x i32> %a, %b140  %sel1 = select <2 x i1> %cmp1, <2 x i32> %c, <2 x i32> <i32 0, i32 0>141  %cmp2 = icmp eq <2 x i32> %a, %b142  %sel2 = select <2 x i1> %cmp2, <2 x i32> %d, <2 x i32> <i32 0, i32 0>143  %or = or <2 x i32> %sel1, %sel2144  ret <2 x i32> %or145}146 147define i32 @par(i32 %a, i32 %b, i32 %c, i32 %d) {148; CHECK-LABEL: @par(149; CHECK-NEXT:    [[T0_NOT:%.*]] = icmp slt i32 [[A:%.*]], [[B:%.*]]150; CHECK-NEXT:    [[T3:%.*]] = select i1 [[T0_NOT]], i32 [[C:%.*]], i32 [[D:%.*]]151; CHECK-NEXT:    ret i32 [[T3]]152;153  %t0 = icmp slt i32 %a, %b154  %iftmp.1.0 = select i1 %t0, i32 -1, i32 0155  %t1 = and i32 %iftmp.1.0, %c156  %not = xor i32 %iftmp.1.0, -1157  %t2 = and i32 %not, %d158  %t3 = or i32 %t1, %t2159  ret i32 %t3160}161 162; In the following tests (8 commutation variants), verify that a bitcast doesn't get163; in the way of a select transform. These bitcasts are common in SSE/AVX and possibly164; other vector code because of canonicalization to i64 elements for vectors.165 166; The fptosi instructions are included to avoid commutation canonicalization based on167; operator weight. Using another cast operator ensures that both operands of all logic168; ops are equally weighted, and this ensures that we're testing all commutation169; possibilities.170 171define <2 x i64> @bitcast_select_swap0(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {172; CHECK-LABEL: @bitcast_select_swap0(173; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>174; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>175; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>176; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>177; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]178; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>179; CHECK-NEXT:    ret <2 x i64> [[OR]]180;181  %sia = fptosi <2 x double> %a to <2 x i64>182  %sib = fptosi <2 x double> %b to <2 x i64>183  %sext = sext <4 x i1> %cmp to <4 x i32>184  %bc1 = bitcast <4 x i32> %sext to <2 x i64>185  %and1 = and <2 x i64> %bc1, %sia186  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>187  %bc2 = bitcast <4 x i32> %neg to <2 x i64>188  %and2 = and <2 x i64> %bc2, %sib189  %or = or <2 x i64> %and1, %and2190  ret <2 x i64> %or191}192 193define <2 x i64> @bitcast_select_swap1(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {194; CHECK-LABEL: @bitcast_select_swap1(195; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>196; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>197; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>198; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>199; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]200; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>201; CHECK-NEXT:    ret <2 x i64> [[OR]]202;203  %sia = fptosi <2 x double> %a to <2 x i64>204  %sib = fptosi <2 x double> %b to <2 x i64>205  %sext = sext <4 x i1> %cmp to <4 x i32>206  %bc1 = bitcast <4 x i32> %sext to <2 x i64>207  %and1 = and <2 x i64> %bc1, %sia208  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>209  %bc2 = bitcast <4 x i32> %neg to <2 x i64>210  %and2 = and <2 x i64> %bc2, %sib211  %or = or <2 x i64> %and2, %and1212  ret <2 x i64> %or213}214 215define <2 x i64> @bitcast_select_swap2(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {216; CHECK-LABEL: @bitcast_select_swap2(217; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>218; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>219; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>220; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>221; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]222; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>223; CHECK-NEXT:    ret <2 x i64> [[OR]]224;225  %sia = fptosi <2 x double> %a to <2 x i64>226  %sib = fptosi <2 x double> %b to <2 x i64>227  %sext = sext <4 x i1> %cmp to <4 x i32>228  %bc1 = bitcast <4 x i32> %sext to <2 x i64>229  %and1 = and <2 x i64> %bc1, %sia230  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>231  %bc2 = bitcast <4 x i32> %neg to <2 x i64>232  %and2 = and <2 x i64> %sib, %bc2233  %or = or <2 x i64> %and1, %and2234  ret <2 x i64> %or235}236 237define <2 x i64> @bitcast_select_swap3(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {238; CHECK-LABEL: @bitcast_select_swap3(239; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>240; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>241; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>242; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>243; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]244; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>245; CHECK-NEXT:    ret <2 x i64> [[OR]]246;247  %sia = fptosi <2 x double> %a to <2 x i64>248  %sib = fptosi <2 x double> %b to <2 x i64>249  %sext = sext <4 x i1> %cmp to <4 x i32>250  %bc1 = bitcast <4 x i32> %sext to <2 x i64>251  %and1 = and <2 x i64> %bc1, %sia252  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>253  %bc2 = bitcast <4 x i32> %neg to <2 x i64>254  %and2 = and <2 x i64> %sib, %bc2255  %or = or <2 x i64> %and2, %and1256  ret <2 x i64> %or257}258 259define <2 x i64> @bitcast_select_swap4(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {260; CHECK-LABEL: @bitcast_select_swap4(261; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>262; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>263; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>264; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>265; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]266; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>267; CHECK-NEXT:    ret <2 x i64> [[OR]]268;269  %sia = fptosi <2 x double> %a to <2 x i64>270  %sib = fptosi <2 x double> %b to <2 x i64>271  %sext = sext <4 x i1> %cmp to <4 x i32>272  %bc1 = bitcast <4 x i32> %sext to <2 x i64>273  %and1 = and <2 x i64> %sia, %bc1274  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>275  %bc2 = bitcast <4 x i32> %neg to <2 x i64>276  %and2 = and <2 x i64> %bc2, %sib277  %or = or <2 x i64> %and1, %and2278  ret <2 x i64> %or279}280 281define <2 x i64> @bitcast_select_swap5(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {282; CHECK-LABEL: @bitcast_select_swap5(283; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>284; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>285; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>286; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>287; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]288; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>289; CHECK-NEXT:    ret <2 x i64> [[OR]]290;291  %sia = fptosi <2 x double> %a to <2 x i64>292  %sib = fptosi <2 x double> %b to <2 x i64>293  %sext = sext <4 x i1> %cmp to <4 x i32>294  %bc1 = bitcast <4 x i32> %sext to <2 x i64>295  %and1 = and <2 x i64> %sia, %bc1296  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>297  %bc2 = bitcast <4 x i32> %neg to <2 x i64>298  %and2 = and <2 x i64> %bc2, %sib299  %or = or <2 x i64> %and2, %and1300  ret <2 x i64> %or301}302 303define <2 x i64> @bitcast_select_swap6(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {304; CHECK-LABEL: @bitcast_select_swap6(305; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>306; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>307; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>308; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>309; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]310; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>311; CHECK-NEXT:    ret <2 x i64> [[OR]]312;313  %sia = fptosi <2 x double> %a to <2 x i64>314  %sib = fptosi <2 x double> %b to <2 x i64>315  %sext = sext <4 x i1> %cmp to <4 x i32>316  %bc1 = bitcast <4 x i32> %sext to <2 x i64>317  %and1 = and <2 x i64> %sia, %bc1318  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>319  %bc2 = bitcast <4 x i32> %neg to <2 x i64>320  %and2 = and <2 x i64> %sib, %bc2321  %or = or <2 x i64> %and1, %and2322  ret <2 x i64> %or323}324 325define <2 x i64> @bitcast_select_swap7(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {326; CHECK-LABEL: @bitcast_select_swap7(327; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>328; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>329; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[SIA]] to <4 x i32>330; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[SIB]] to <4 x i32>331; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i32> [[TMP1]], <4 x i32> [[TMP2]]332; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i32> [[TMP3]] to <2 x i64>333; CHECK-NEXT:    ret <2 x i64> [[OR]]334;335  %sia = fptosi <2 x double> %a to <2 x i64>336  %sib = fptosi <2 x double> %b to <2 x i64>337  %sext = sext <4 x i1> %cmp to <4 x i32>338  %bc1 = bitcast <4 x i32> %sext to <2 x i64>339  %and1 = and <2 x i64> %sia, %bc1340  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>341  %bc2 = bitcast <4 x i32> %neg to <2 x i64>342  %and2 = and <2 x i64> %sib, %bc2343  %or = or <2 x i64> %and2, %and1344  ret <2 x i64> %or345}346 347define <2 x i64> @bitcast_select_multi_uses(<4 x i1> %cmp, <2 x i64> %a, <2 x i64> %b) {348; CHECK-LABEL: @bitcast_select_multi_uses(349; CHECK-NEXT:    [[SEXT:%.*]] = sext <4 x i1> [[CMP:%.*]] to <4 x i32>350; CHECK-NEXT:    [[BC1:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>351; CHECK-NEXT:    [[AND1:%.*]] = and <2 x i64> [[A:%.*]], [[BC1]]352; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i32> [[SEXT]] to <2 x i64>353; CHECK-NEXT:    [[BC2:%.*]] = xor <2 x i64> [[TMP1]], splat (i64 -1)354; CHECK-NEXT:    [[AND2:%.*]] = and <2 x i64> [[B:%.*]], [[BC2]]355; CHECK-NEXT:    [[OR:%.*]] = or <2 x i64> [[AND2]], [[AND1]]356; CHECK-NEXT:    [[ADD:%.*]] = add <2 x i64> [[AND2]], [[BC2]]357; CHECK-NEXT:    [[SUB:%.*]] = sub <2 x i64> [[OR]], [[ADD]]358; CHECK-NEXT:    ret <2 x i64> [[SUB]]359;360  %sext = sext <4 x i1> %cmp to <4 x i32>361  %bc1 = bitcast <4 x i32> %sext to <2 x i64>362  %and1 = and <2 x i64> %a, %bc1363  %neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>364  %bc2 = bitcast <4 x i32> %neg to <2 x i64>365  %and2 = and <2 x i64> %b, %bc2366  %or = or <2 x i64> %and2, %and1367  %add = add <2 x i64> %and2, %bc2368  %sub = sub <2 x i64> %or, %add369  ret <2 x i64> %sub370}371 372define i1 @bools(i1 %a, i1 %b, i1 %c) {373; CHECK-LABEL: @bools(374; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]375; CHECK-NEXT:    ret i1 [[OR]]376;377  %not = xor i1 %c, -1378  %and1 = and i1 %not, %a379  %and2 = and i1 %c, %b380  %or = or i1 %and1, %and2381  ret i1 %or382}383 384define i1 @bools_logical(i1 %a, i1 %b, i1 %c) {385; CHECK-LABEL: @bools_logical(386; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]387; CHECK-NEXT:    ret i1 [[OR]]388;389  %not = xor i1 %c, -1390  %and1 = select i1 %not, i1 %a, i1 false391  %and2 = select i1 %c, i1 %b, i1 false392  %or = select i1 %and1, i1 true, i1 %and2393  ret i1 %or394}395 396; Form a select if we know we can replace 2 simple logic ops.397 398define i1 @bools_multi_uses1(i1 %a, i1 %b, i1 %c) {399; CHECK-LABEL: @bools_multi_uses1(400; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true401; CHECK-NEXT:    [[AND1:%.*]] = and i1 [[A:%.*]], [[NOT]]402; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C]], i1 [[B:%.*]], i1 [[A]]403; CHECK-NEXT:    [[XOR:%.*]] = xor i1 [[OR]], [[AND1]]404; CHECK-NEXT:    ret i1 [[XOR]]405;406  %not = xor i1 %c, -1407  %and1 = and i1 %not, %a408  %and2 = and i1 %c, %b409  %or = or i1 %and1, %and2410  %xor = xor i1 %or, %and1411  ret i1 %xor412}413 414define i1 @bools_multi_uses1_logical(i1 %a, i1 %b, i1 %c) {415; CHECK-LABEL: @bools_multi_uses1_logical(416; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true417; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[NOT]], i1 [[A:%.*]], i1 false418; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C]], i1 [[B:%.*]], i1 [[A]]419; CHECK-NEXT:    [[XOR:%.*]] = xor i1 [[OR]], [[AND1]]420; CHECK-NEXT:    ret i1 [[XOR]]421;422  %not = xor i1 %c, -1423  %and1 = select i1 %not, i1 %a, i1 false424  %and2 = select i1 %c, i1 %b, i1 false425  %or = select i1 %and1, i1 true, i1 %and2426  %xor = xor i1 %or, %and1427  ret i1 %xor428}429 430; Don't replace a cheap logic op with a potentially expensive select431; unless we can also eliminate one of the other original ops.432 433define i1 @bools_multi_uses2(i1 %a, i1 %b, i1 %c) {434; CHECK-LABEL: @bools_multi_uses2(435; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]436; CHECK-NEXT:    ret i1 [[OR]]437;438  %not = xor i1 %c, -1439  %and1 = and i1 %not, %a440  %and2 = and i1 %c, %b441  %or = or i1 %and1, %and2442  %add = add i1 %and1, %and2443  %and3 = and i1 %or, %add444  ret i1 %and3445}446 447define i1 @bools_multi_uses2_logical(i1 %a, i1 %b, i1 %c) {448; CHECK-LABEL: @bools_multi_uses2_logical(449; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true450; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[NOT]], i1 [[A:%.*]], i1 false451; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[C]], i1 [[B:%.*]], i1 false452; CHECK-NEXT:    [[OR:%.*]] = select i1 [[C]], i1 [[B]], i1 [[A]]453; CHECK-NEXT:    [[ADD:%.*]] = xor i1 [[AND1]], [[AND2]]454; CHECK-NEXT:    [[AND3:%.*]] = select i1 [[OR]], i1 [[ADD]], i1 false455; CHECK-NEXT:    ret i1 [[AND3]]456;457  %not = xor i1 %c, -1458  %and1 = select i1 %not, i1 %a, i1 false459  %and2 = select i1 %c, i1 %b, i1 false460  %or = select i1 %and1, i1 true, i1 %and2461  %add = add i1 %and1, %and2462  %and3 = select i1 %or, i1 %add, i1 false463  ret i1 %and3464}465 466define <4 x i1> @vec_of_bools(<4 x i1> %a, <4 x i1> %b, <4 x i1> %c) {467; CHECK-LABEL: @vec_of_bools(468; CHECK-NEXT:    [[OR:%.*]] = select <4 x i1> [[C:%.*]], <4 x i1> [[B:%.*]], <4 x i1> [[A:%.*]]469; CHECK-NEXT:    ret <4 x i1> [[OR]]470;471  %not = xor <4 x i1> %c, <i1 true, i1 true, i1 true, i1 true>472  %and1 = and <4 x i1> %not, %a473  %and2 = and <4 x i1> %b, %c474  %or = or <4 x i1> %and2, %and1475  ret <4 x i1> %or476}477 478define <vscale x 1 x i1> @vec_of_bools_scalable(<vscale x 1 x i1> %a, <vscale x 1 x i1> %c, <vscale x 1 x i1> %d) {479; CHECK-LABEL: @vec_of_bools_scalable(480; CHECK-NEXT:    [[R:%.*]] = select <vscale x 1 x i1> [[A:%.*]], <vscale x 1 x i1> [[C:%.*]], <vscale x 1 x i1> [[D:%.*]]481; CHECK-NEXT:    ret <vscale x 1 x i1> [[R]]482;483  %b = xor <vscale x 1 x i1> %a, splat (i1 true)484  %t11 = and <vscale x 1 x i1> %a, %c485  %t12 = and <vscale x 1 x i1> %b, %d486  %r = or <vscale x 1 x i1> %t11, %t12487  ret <vscale x 1 x i1> %r488}489 490define i4 @vec_of_casted_bools(i4 %a, i4 %b, <4 x i1> %c) {491; CHECK-LABEL: @vec_of_casted_bools(492; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i4 [[B:%.*]] to <4 x i1>493; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i4 [[A:%.*]] to <4 x i1>494; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[C:%.*]], <4 x i1> [[TMP1]], <4 x i1> [[TMP2]]495; CHECK-NEXT:    [[OR:%.*]] = bitcast <4 x i1> [[TMP3]] to i4496; CHECK-NEXT:    ret i4 [[OR]]497;498  %not = xor <4 x i1> %c, <i1 true, i1 true, i1 true, i1 true>499  %bc1 = bitcast <4 x i1> %not to i4500  %bc2 = bitcast <4 x i1> %c to i4501  %and1 = and i4 %a, %bc1502  %and2 = and i4 %bc2, %b503  %or = or i4 %and1, %and2504  ret i4 %or505}506 507define <vscale x 1 x i64> @vec_of_casted_bools_scalable(<vscale x 1 x i64> %a, <vscale x 1 x i64> %b, <vscale x 8 x i1> %cond) {508; CHECK-LABEL: @vec_of_casted_bools_scalable(509; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <vscale x 1 x i64> [[A:%.*]] to <vscale x 8 x i8>510; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <vscale x 1 x i64> [[B:%.*]] to <vscale x 8 x i8>511; CHECK-NEXT:    [[TMP3:%.*]] = select <vscale x 8 x i1> [[COND:%.*]], <vscale x 8 x i8> [[TMP1]], <vscale x 8 x i8> [[TMP2]]512; CHECK-NEXT:    [[OR:%.*]] = bitcast <vscale x 8 x i8> [[TMP3]] to <vscale x 1 x i64>513; CHECK-NEXT:    ret <vscale x 1 x i64> [[OR]]514;515  %scond = sext <vscale x 8 x i1> %cond to <vscale x 8 x i8>516  %notcond = xor <vscale x 8 x i1> %cond, splat (i1 true)517  %snotcond = sext <vscale x 8 x i1> %notcond to <vscale x 8 x i8>518  %bc1 = bitcast <vscale x 8 x i8> %scond to <vscale x 1 x i64>519  %bc2 = bitcast <vscale x 8 x i8> %snotcond to <vscale x 1 x i64>520  %and1 = and <vscale x 1 x i64> %a, %bc1521  %and2 = and <vscale x 1 x i64> %bc2, %b522  %or = or <vscale x 1 x i64> %and1, %and2523  ret <vscale x 1 x i64> %or524}525 526; Inverted 'and' constants mean this is a select which is canonicalized to a shuffle.527 528define <4 x i32> @vec_sel_consts(<4 x i32> %a, <4 x i32> %b) {529; CHECK-LABEL: @vec_sel_consts(530; CHECK-NEXT:    [[OR:%.*]] = shufflevector <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], <4 x i32> <i32 0, i32 5, i32 6, i32 3>531; CHECK-NEXT:    ret <4 x i32> [[OR]]532;533  %and1 = and <4 x i32> %a, <i32 -1, i32 0, i32 0, i32 -1>534  %and2 = and <4 x i32> %b, <i32 0, i32 -1, i32 -1, i32 0>535  %or = or <4 x i32> %and1, %and2536  ret <4 x i32> %or537}538 539define <3 x i129> @vec_sel_consts_weird(<3 x i129> %a, <3 x i129> %b) {540; CHECK-LABEL: @vec_sel_consts_weird(541; CHECK-NEXT:    [[OR:%.*]] = shufflevector <3 x i129> [[A:%.*]], <3 x i129> [[B:%.*]], <3 x i32> <i32 0, i32 4, i32 2>542; CHECK-NEXT:    ret <3 x i129> [[OR]]543;544  %and1 = and <3 x i129> %a, <i129 -1, i129 0, i129 -1>545  %and2 = and <3 x i129> %b, <i129 0, i129 -1, i129 0>546  %or = or <3 x i129> %and2, %and1547  ret <3 x i129> %or548}549 550; The mask elements must be inverted for this to be a select.551 552define <4 x i32> @vec_not_sel_consts(<4 x i32> %a, <4 x i32> %b) {553; CHECK-LABEL: @vec_not_sel_consts(554; CHECK-NEXT:    [[AND1:%.*]] = and <4 x i32> [[A:%.*]], <i32 -1, i32 0, i32 0, i32 0>555; CHECK-NEXT:    [[AND2:%.*]] = and <4 x i32> [[B:%.*]], <i32 0, i32 -1, i32 0, i32 -1>556; CHECK-NEXT:    [[OR:%.*]] = or <4 x i32> [[AND1]], [[AND2]]557; CHECK-NEXT:    ret <4 x i32> [[OR]]558;559  %and1 = and <4 x i32> %a, <i32 -1, i32 0, i32 0, i32 0>560  %and2 = and <4 x i32> %b, <i32 0, i32 -1, i32 0, i32 -1>561  %or = or <4 x i32> %and1, %and2562  ret <4 x i32> %or563}564 565define <4 x i32> @vec_not_sel_consts_undef_elts(<4 x i32> %a, <4 x i32> %b) {566; CHECK-LABEL: @vec_not_sel_consts_undef_elts(567; CHECK-NEXT:    [[AND1:%.*]] = and <4 x i32> [[A:%.*]], <i32 -1, i32 undef, i32 0, i32 0>568; CHECK-NEXT:    [[AND2:%.*]] = and <4 x i32> [[B:%.*]], <i32 0, i32 -1, i32 0, i32 undef>569; CHECK-NEXT:    [[OR:%.*]] = or <4 x i32> [[AND1]], [[AND2]]570; CHECK-NEXT:    ret <4 x i32> [[OR]]571;572  %and1 = and <4 x i32> %a, <i32 -1, i32 undef, i32 0, i32 0>573  %and2 = and <4 x i32> %b, <i32 0, i32 -1, i32 0, i32 undef>574  %or = or <4 x i32> %and1, %and2575  ret <4 x i32> %or576}577 578; The inverted constants may be operands of xor instructions.579 580define <4 x i32> @vec_sel_xor(<4 x i32> %a, <4 x i32> %b, <4 x i1> %c) {581; CHECK-LABEL: @vec_sel_xor(582; CHECK-NEXT:    [[TMP1:%.*]] = xor <4 x i1> [[C:%.*]], <i1 false, i1 true, i1 true, i1 true>583; CHECK-NEXT:    [[OR:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]]584; CHECK-NEXT:    ret <4 x i32> [[OR]]585;586  %mask = sext <4 x i1> %c to <4 x i32>587  %mask_flip1 = xor <4 x i32> %mask, <i32 -1, i32 0, i32 0, i32 0>588  %not_mask_flip1 = xor <4 x i32> %mask, <i32 0, i32 -1, i32 -1, i32 -1>589  %and1 = and <4 x i32> %not_mask_flip1, %a590  %and2 = and <4 x i32> %mask_flip1, %b591  %or = or <4 x i32> %and1, %and2592  ret <4 x i32> %or593}594 595; Allow the transform even if the mask values have multiple uses because596; there's still a net reduction of instructions from removing the and/and/or.597 598define <4 x i32> @vec_sel_xor_multi_use(<4 x i32> %a, <4 x i32> %b, <4 x i1> %c) {599; CHECK-LABEL: @vec_sel_xor_multi_use(600; CHECK-NEXT:    [[TMP1:%.*]] = xor <4 x i1> [[C:%.*]], <i1 true, i1 false, i1 false, i1 false>601; CHECK-NEXT:    [[MASK_FLIP1:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i32>602; CHECK-NEXT:    [[TMP2:%.*]] = xor <4 x i1> [[C]], <i1 false, i1 true, i1 true, i1 true>603; CHECK-NEXT:    [[OR:%.*]] = select <4 x i1> [[TMP2]], <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]]604; CHECK-NEXT:    [[ADD:%.*]] = add <4 x i32> [[OR]], [[MASK_FLIP1]]605; CHECK-NEXT:    ret <4 x i32> [[ADD]]606;607  %mask = sext <4 x i1> %c to <4 x i32>608  %mask_flip1 = xor <4 x i32> %mask, <i32 -1, i32 0, i32 0, i32 0>609  %not_mask_flip1 = xor <4 x i32> %mask, <i32 0, i32 -1, i32 -1, i32 -1>610  %and1 = and <4 x i32> %not_mask_flip1, %a611  %and2 = and <4 x i32> %mask_flip1, %b612  %or = or <4 x i32> %and1, %and2613  %add = add <4 x i32> %or, %mask_flip1614  ret <4 x i32> %add615}616 617; The 'ashr' guarantees that we have a bitmask, so this is select with truncated condition.618 619define i32 @allSignBits(i32 %cond, i32 %tval, i32 %fval) {620; CHECK-LABEL: @allSignBits(621; CHECK-NEXT:    [[ISNEG1:%.*]] = icmp slt i32 [[COND:%.*]], 0622; CHECK-NEXT:    [[A1:%.*]] = select i1 [[ISNEG1]], i32 [[TVAL:%.*]], i32 0623; CHECK-NEXT:    [[ISNEG:%.*]] = icmp slt i32 [[COND]], 0624; CHECK-NEXT:    [[A2:%.*]] = select i1 [[ISNEG]], i32 0, i32 [[FVAL:%.*]]625; CHECK-NEXT:    [[SEL:%.*]] = or i32 [[A1]], [[A2]]626; CHECK-NEXT:    ret i32 [[SEL]]627;628  %bitmask = ashr i32 %cond, 31629  %not_bitmask = xor i32 %bitmask, -1630  %a1 = and i32 %tval, %bitmask631  %a2 = and i32 %not_bitmask, %fval632  %sel = or i32 %a1, %a2633  ret i32 %sel634}635 636define <4 x i8> @allSignBits_vec(<4 x i8> %cond, <4 x i8> %tval, <4 x i8> %fval) {637; CHECK-LABEL: @allSignBits_vec(638; CHECK-NEXT:    [[ISNEG1:%.*]] = icmp slt <4 x i8> [[COND:%.*]], zeroinitializer639; CHECK-NEXT:    [[A1:%.*]] = select <4 x i1> [[ISNEG1]], <4 x i8> [[TVAL:%.*]], <4 x i8> zeroinitializer640; CHECK-NEXT:    [[ISNEG:%.*]] = icmp slt <4 x i8> [[COND]], zeroinitializer641; CHECK-NEXT:    [[A2:%.*]] = select <4 x i1> [[ISNEG]], <4 x i8> zeroinitializer, <4 x i8> [[FVAL:%.*]]642; CHECK-NEXT:    [[SEL:%.*]] = or <4 x i8> [[A2]], [[A1]]643; CHECK-NEXT:    ret <4 x i8> [[SEL]]644;645  %bitmask = ashr <4 x i8> %cond, <i8 7, i8 7, i8 7, i8 7>646  %not_bitmask = xor <4 x i8> %bitmask, <i8 -1, i8 -1, i8 -1, i8 -1>647  %a1 = and <4 x i8> %tval, %bitmask648  %a2 = and <4 x i8> %fval, %not_bitmask649  %sel = or <4 x i8> %a2, %a1650  ret <4 x i8> %sel651}652 653; Negative test - make sure that bitcasts from FP do not cause a crash.654 655define <2 x i64> @fp_bitcast(<4 x i1> %cmp, <2 x double> %a, <2 x double> %b) {656; CHECK-LABEL: @fp_bitcast(657; CHECK-NEXT:    [[SIA:%.*]] = fptosi <2 x double> [[A:%.*]] to <2 x i64>658; CHECK-NEXT:    [[SIB:%.*]] = fptosi <2 x double> [[B:%.*]] to <2 x i64>659; CHECK-NEXT:    [[BC1:%.*]] = bitcast <2 x double> [[A]] to <2 x i64>660; CHECK-NEXT:    [[AND1:%.*]] = and <2 x i64> [[SIA]], [[BC1]]661; CHECK-NEXT:    [[BC2:%.*]] = bitcast <2 x double> [[B]] to <2 x i64>662; CHECK-NEXT:    [[AND2:%.*]] = and <2 x i64> [[SIB]], [[BC2]]663; CHECK-NEXT:    [[OR:%.*]] = or <2 x i64> [[AND2]], [[AND1]]664; CHECK-NEXT:    ret <2 x i64> [[OR]]665;666  %sia = fptosi <2 x double> %a to <2 x i64>667  %sib = fptosi <2 x double> %b to <2 x i64>668  %bc1 = bitcast <2 x double> %a to <2 x i64>669  %and1 = and <2 x i64> %sia, %bc1670  %bc2 = bitcast <2 x double> %b to <2 x i64>671  %and2 = and <2 x i64> %sib, %bc2672  %or = or <2 x i64> %and2, %and1673  ret <2 x i64> %or674}675 676define <4 x i32> @computesignbits_through_shuffles(<4 x float> %x, <4 x float> %y, <4 x float> %z) {677; CHECK-LABEL: @computesignbits_through_shuffles(678; CHECK-NEXT:    [[CMP:%.*]] = fcmp ole <4 x float> [[X:%.*]], [[Y:%.*]]679; CHECK-NEXT:    [[TMP4:%.*]] = shufflevector <4 x i1> [[CMP]], <4 x i1> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 1>680; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <4 x i1> [[CMP]], <4 x i1> poison, <4 x i32> <i32 2, i32 2, i32 3, i32 3>681; CHECK-NEXT:    [[TMP3:%.*]] = or <4 x i1> [[TMP4]], [[TMP2]]682; CHECK-NEXT:    [[S3:%.*]] = shufflevector <4 x i1> [[TMP3]], <4 x i1> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 1>683; CHECK-NEXT:    [[S4:%.*]] = shufflevector <4 x i1> [[TMP3]], <4 x i1> poison, <4 x i32> <i32 2, i32 2, i32 3, i32 3>684; CHECK-NEXT:    [[TMP1:%.*]] = or <4 x i1> [[S3]], [[S4]]685; CHECK-NEXT:    [[SEL_V:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[Z:%.*]], <4 x float> [[X]]686; CHECK-NEXT:    [[SEL:%.*]] = bitcast <4 x float> [[SEL_V]] to <4 x i32>687; CHECK-NEXT:    ret <4 x i32> [[SEL]]688;689  %cmp = fcmp ole <4 x float> %x, %y690  %sext = sext <4 x i1> %cmp to <4 x i32>691  %s1 = shufflevector <4 x i32> %sext, <4 x i32> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 1>692  %s2 = shufflevector <4 x i32> %sext, <4 x i32> undef, <4 x i32> <i32 2, i32 2, i32 3, i32 3>693  %shuf_or1 = or <4 x i32> %s1, %s2694  %s3 = shufflevector <4 x i32> %shuf_or1, <4 x i32> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 1>695  %s4 = shufflevector <4 x i32> %shuf_or1, <4 x i32> undef, <4 x i32> <i32 2, i32 2, i32 3, i32 3>696  %shuf_or2 = or <4 x i32> %s3, %s4697  %not_or2 = xor <4 x i32> %shuf_or2, <i32 -1, i32 -1, i32 -1, i32 -1>698  %xbc = bitcast <4 x float> %x to <4 x i32>699  %zbc = bitcast <4 x float> %z to <4 x i32>700  %and1 = and <4 x i32> %not_or2, %xbc701  %and2 = and <4 x i32> %shuf_or2, %zbc702  %sel = or <4 x i32> %and1, %and2703  ret <4 x i32> %sel704}705 706define <4 x i32> @computesignbits_through_two_input_shuffle(<4 x i32> %x, <4 x i32> %y, <4 x i1> %cond1, <4 x i1> %cond2) {707; CHECK-LABEL: @computesignbits_through_two_input_shuffle(708; CHECK-NEXT:    [[COND:%.*]] = shufflevector <4 x i1> [[COND1:%.*]], <4 x i1> [[COND2:%.*]], <4 x i32> <i32 0, i32 2, i32 4, i32 6>709; CHECK-NEXT:    [[SEL:%.*]] = select <4 x i1> [[COND]], <4 x i32> [[Y:%.*]], <4 x i32> [[X:%.*]]710; CHECK-NEXT:    ret <4 x i32> [[SEL]]711;712  %sext1 = sext <4 x i1> %cond1 to <4 x i32>713  %sext2 = sext <4 x i1> %cond2 to <4 x i32>714  %cond = shufflevector <4 x i32> %sext1, <4 x i32> %sext2, <4 x i32> <i32 0, i32 2, i32 4, i32 6>715  %notcond = xor <4 x i32> %cond, <i32 -1, i32 -1, i32 -1, i32 -1>716  %and1 = and <4 x i32> %notcond, %x717  %and2 = and <4 x i32> %cond, %y718  %sel = or <4 x i32> %and1, %and2719  ret <4 x i32> %sel720}721 722; Bitcast of condition from narrow source element type can be converted to select.723 724define <2 x i64> @bitcast_vec_cond(<16 x i1> %cond, <2 x i64> %c, <2 x i64> %d) {725; CHECK-LABEL: @bitcast_vec_cond(726; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i64> [[D:%.*]] to <16 x i8>727; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[C:%.*]] to <16 x i8>728; CHECK-NEXT:    [[TMP3:%.*]] = select <16 x i1> [[COND:%.*]], <16 x i8> [[TMP1]], <16 x i8> [[TMP2]]729; CHECK-NEXT:    [[R:%.*]] = bitcast <16 x i8> [[TMP3]] to <2 x i64>730; CHECK-NEXT:    ret <2 x i64> [[R]]731;732  %s = sext <16 x i1> %cond to <16 x i8>733  %t9 = bitcast <16 x i8> %s to <2 x i64>734  %nott9 = xor <2 x i64> %t9, <i64 -1, i64 -1>735  %t11 = and <2 x i64> %nott9, %c736  %t12 = and <2 x i64> %t9, %d737  %r = or <2 x i64> %t11, %t12738  ret <2 x i64> %r739}740 741define <vscale x 2 x i64> @bitcast_vec_cond_scalable(<vscale x 16 x i1> %cond, <vscale x 2 x i64> %c, <vscale x 2 x i64> %d) {742; CHECK-LABEL: @bitcast_vec_cond_scalable(743; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <vscale x 2 x i64> [[D:%.*]] to <vscale x 16 x i8>744; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <vscale x 2 x i64> [[C:%.*]] to <vscale x 16 x i8>745; CHECK-NEXT:    [[TMP3:%.*]] = select <vscale x 16 x i1> [[COND:%.*]], <vscale x 16 x i8> [[TMP1]], <vscale x 16 x i8> [[TMP2]]746; CHECK-NEXT:    [[R:%.*]] = bitcast <vscale x 16 x i8> [[TMP3]] to <vscale x 2 x i64>747; CHECK-NEXT:    ret <vscale x 2 x i64> [[R]]748;749  %s = sext <vscale x 16 x i1> %cond to <vscale x 16 x i8>750  %t9 = bitcast <vscale x 16 x i8> %s to <vscale x 2 x i64>751  %nott9 = xor <vscale x 2 x i64> %t9, splat (i64 -1)752  %t11 = and <vscale x 2 x i64> %nott9, %c753  %t12 = and <vscale x 2 x i64> %t9, %d754  %r = or <vscale x 2 x i64> %t11, %t12755  ret <vscale x 2 x i64> %r756}757 758; Negative test - bitcast of condition from wide source element type cannot be converted to select.759 760define <8 x i3> @bitcast_vec_cond_commute1(<3 x i1> noundef %cond, <8 x i3> %pc, <8 x i3> %d) {761; CHECK-LABEL: @bitcast_vec_cond_commute1(762; CHECK-NEXT:    [[C:%.*]] = mul <8 x i3> [[PC:%.*]], [[PC]]763; CHECK-NEXT:    [[S:%.*]] = sext <3 x i1> [[COND:%.*]] to <3 x i8>764; CHECK-NEXT:    [[T9:%.*]] = bitcast <3 x i8> [[S]] to <8 x i3>765; CHECK-NEXT:    [[NOTT9:%.*]] = xor <8 x i3> [[T9]], splat (i3 -1)766; CHECK-NEXT:    [[T11:%.*]] = and <8 x i3> [[C]], [[NOTT9]]767; CHECK-NEXT:    [[T12:%.*]] = and <8 x i3> [[D:%.*]], [[T9]]768; CHECK-NEXT:    [[R:%.*]] = or disjoint <8 x i3> [[T11]], [[T12]]769; CHECK-NEXT:    ret <8 x i3> [[R]]770;771  %c = mul <8 x i3> %pc, %pc ; thwart complexity-based canonicalization772  %s = sext <3 x i1> %cond to <3 x i8>773  %t9 = bitcast <3 x i8> %s to <8 x i3>774  %nott9 = xor <8 x i3> %t9, <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>775  %t11 = and <8 x i3> %c, %nott9776  %t12 = and <8 x i3> %t9, %d777  %r = or <8 x i3> %t11, %t12778  ret <8 x i3> %r779}780 781define <2 x i16> @bitcast_vec_cond_commute2(<4 x i1> %cond, <2 x i16> %pc, <2 x i16> %pd) {782; CHECK-LABEL: @bitcast_vec_cond_commute2(783; CHECK-NEXT:    [[C:%.*]] = mul <2 x i16> [[PC:%.*]], [[PC]]784; CHECK-NEXT:    [[D:%.*]] = mul <2 x i16> [[PD:%.*]], [[PD]]785; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i16> [[D]] to <4 x i8>786; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i16> [[C]] to <4 x i8>787; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[COND:%.*]], <4 x i8> [[TMP1]], <4 x i8> [[TMP2]]788; CHECK-NEXT:    [[R:%.*]] = bitcast <4 x i8> [[TMP3]] to <2 x i16>789; CHECK-NEXT:    ret <2 x i16> [[R]]790;791  %c = mul <2 x i16> %pc, %pc ; thwart complexity-based canonicalization792  %d = mul <2 x i16> %pd, %pd ; thwart complexity-based canonicalization793  %s = sext <4 x i1> %cond to <4 x i8>794  %t9 = bitcast <4 x i8> %s to <2 x i16>795  %nott9 = xor <2 x i16> %t9, <i16 -1, i16 -1>796  %t11 = and <2 x i16> %c, %nott9797  %t12 = and <2 x i16> %d, %t9798  %r = or <2 x i16> %t11, %t12799  ret <2 x i16> %r800}801 802; Condition doesn't have to be a bool vec - just all signbits.803 804define <2 x i16> @bitcast_vec_cond_commute3(<4 x i8> %cond, <2 x i16> %pc, <2 x i16> %pd) {805; CHECK-LABEL: @bitcast_vec_cond_commute3(806; CHECK-NEXT:    [[C:%.*]] = mul <2 x i16> [[PC:%.*]], [[PC]]807; CHECK-NEXT:    [[D:%.*]] = mul <2 x i16> [[PD:%.*]], [[PD]]808; CHECK-NEXT:    [[DOTNOT2:%.*]] = icmp slt <4 x i8> [[COND:%.*]], zeroinitializer809; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i16> [[D]] to <4 x i8>810; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i16> [[C]] to <4 x i8>811; CHECK-NEXT:    [[TMP3:%.*]] = select <4 x i1> [[DOTNOT2]], <4 x i8> [[TMP1]], <4 x i8> [[TMP2]]812; CHECK-NEXT:    [[R:%.*]] = bitcast <4 x i8> [[TMP3]] to <2 x i16>813; CHECK-NEXT:    ret <2 x i16> [[R]]814;815  %c = mul <2 x i16> %pc, %pc ; thwart complexity-based canonicalization816  %d = mul <2 x i16> %pd, %pd ; thwart complexity-based canonicalization817  %s = ashr <4 x i8> %cond, <i8 7, i8 7, i8 7, i8 7>818  %t9 = bitcast <4 x i8> %s to <2 x i16>819  %nott9 = xor <2 x i16> %t9, <i16 -1, i16 -1>820  %t11 = and <2 x i16> %c, %nott9821  %t12 = and <2 x i16> %d, %t9822  %r = or <2 x i16> %t11, %t12823  ret <2 x i16> %r824}825 826; Don't crash on invalid type for compute signbits.827 828define <2 x i64> @bitcast_fp_vec_cond(<2 x double> noundef %s, <2 x i64> %c, <2 x i64> %d) {829; CHECK-LABEL: @bitcast_fp_vec_cond(830; CHECK-NEXT:    [[T9:%.*]] = bitcast <2 x double> [[S:%.*]] to <2 x i64>831; CHECK-NEXT:    [[NOTT9:%.*]] = xor <2 x i64> [[T9]], splat (i64 -1)832; CHECK-NEXT:    [[T11:%.*]] = and <2 x i64> [[C:%.*]], [[NOTT9]]833; CHECK-NEXT:    [[T12:%.*]] = and <2 x i64> [[D:%.*]], [[T9]]834; CHECK-NEXT:    [[R:%.*]] = or disjoint <2 x i64> [[T11]], [[T12]]835; CHECK-NEXT:    ret <2 x i64> [[R]]836;837  %t9 = bitcast <2 x double> %s to <2 x i64>838  %nott9 = xor <2 x i64> %t9, <i64 -1, i64 -1>839  %t11 = and <2 x i64> %nott9, %c840  %t12 = and <2 x i64> %t9, %d841  %r = or <2 x i64> %t11, %t12842  ret <2 x i64> %r843}844 845; Wider source type would be ok except poison could leak across elements.846 847define <2 x i64> @bitcast_int_vec_cond(i1 noundef %b, <2 x i64> %c, <2 x i64> %d) {848; CHECK-LABEL: @bitcast_int_vec_cond(849; CHECK-NEXT:    [[S:%.*]] = sext i1 [[B:%.*]] to i128850; CHECK-NEXT:    [[T9:%.*]] = bitcast i128 [[S]] to <2 x i64>851; CHECK-NEXT:    [[NOTT9:%.*]] = xor <2 x i64> [[T9]], splat (i64 -1)852; CHECK-NEXT:    [[T11:%.*]] = and <2 x i64> [[C:%.*]], [[NOTT9]]853; CHECK-NEXT:    [[T12:%.*]] = and <2 x i64> [[D:%.*]], [[T9]]854; CHECK-NEXT:    [[R:%.*]] = or disjoint <2 x i64> [[T11]], [[T12]]855; CHECK-NEXT:    ret <2 x i64> [[R]]856;857  %s = sext i1 %b to i128858  %t9 = bitcast i128 %s to <2 x i64>859  %nott9 = xor <2 x i64> %t9, <i64 -1, i64 -1>860  %t11 = and <2 x i64> %nott9, %c861  %t12 = and <2 x i64> %t9, %d862  %r = or <2 x i64> %t11, %t12863  ret <2 x i64> %r864}865 866; Converting integer logic ops to vector select is allowed.867 868define i64 @bitcast_int_scalar_cond(<2 x i1> %b, i64 %c, i64 %d) {869; CHECK-LABEL: @bitcast_int_scalar_cond(870; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i64 [[D:%.*]] to <2 x i32>871; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i64 [[C:%.*]] to <2 x i32>872; CHECK-NEXT:    [[TMP3:%.*]] = select <2 x i1> [[B:%.*]], <2 x i32> [[TMP1]], <2 x i32> [[TMP2]]873; CHECK-NEXT:    [[R:%.*]] = bitcast <2 x i32> [[TMP3]] to i64874; CHECK-NEXT:    ret i64 [[R]]875;876  %s = sext <2 x i1> %b to <2 x i32>877  %t9 = bitcast <2 x i32> %s to i64878  %nott9 = xor i64 %t9, -1879  %t11 = and i64 %nott9, %c880  %t12 = and i64 %t9, %d881  %r = or i64 %t11, %t12882  ret i64 %r883}884 885; Peek through bitcasts and sexts to find negated bool condition.886 887define <1 x i6> @bitcast_sext_cond(<2 x i1> %cmp, <1 x i6> %a, <1 x i6> %b) {888; CHECK-LABEL: @bitcast_sext_cond(889; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <1 x i6> [[A:%.*]] to <2 x i3>890; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <1 x i6> [[B:%.*]] to <2 x i3>891; CHECK-NEXT:    [[TMP3:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i3> [[TMP1]], <2 x i3> [[TMP2]]892; CHECK-NEXT:    [[OR:%.*]] = bitcast <2 x i3> [[TMP3]] to <1 x i6>893; CHECK-NEXT:    ret <1 x i6> [[OR]]894;895  %sext = sext <2 x i1> %cmp to <2 x i3>896  %bc1 = bitcast <2 x i3> %sext to <1 x i6>897  %neg = xor <2 x i1> %cmp, <i1 -1, i1 -1>898  %sext2 = sext <2 x i1> %neg to <2 x i3>899  %bc2 = bitcast <2 x i3> %sext2 to <1 x i6>900  %and1 = and <1 x i6> %bc1, %a901  %and2 = and <1 x i6> %bc2, %b902  %or = or <1 x i6> %and1, %and2903  ret <1 x i6> %or904}905 906; Extra uses may prevent other transforms from creating the canonical patterns.907 908define i8 @sext_cond_extra_uses(i1 %cmp, i8 %a, i8 %b) {909; CHECK-LABEL: @sext_cond_extra_uses(910; CHECK-NEXT:    [[NEG:%.*]] = xor i1 [[CMP:%.*]], true911; CHECK-NEXT:    [[SEXT1:%.*]] = sext i1 [[CMP]] to i8912; CHECK-NEXT:    call void @use(i8 [[SEXT1]])913; CHECK-NEXT:    [[SEXT2:%.*]] = sext i1 [[NEG]] to i8914; CHECK-NEXT:    call void @use(i8 [[SEXT2]])915; CHECK-NEXT:    [[OR:%.*]] = select i1 [[CMP]], i8 [[A:%.*]], i8 [[B:%.*]]916; CHECK-NEXT:    ret i8 [[OR]]917;918  %neg = xor i1 %cmp, -1919  %sext1 = sext i1 %cmp to i8920  call void @use(i8 %sext1)921  %sext2 = sext i1 %neg to i8922  call void @use(i8 %sext2)923  %and1 = and i8 %sext1, %a924  %and2 = and i8 %sext2, %b925  %or = or i8 %and1, %and2926  ret i8 %or927}928 929define i1 @xor_commute0(i1 %x, i1 %y) {930; CHECK-LABEL: @xor_commute0(931; CHECK-NEXT:    [[AND2:%.*]] = xor i1 [[X:%.*]], [[Y:%.*]]932; CHECK-NEXT:    ret i1 [[AND2]]933;934  %and = select i1 %x, i1 %y, i1 false935  %or = select i1 %x, i1 true, i1 %y936  %nand = xor i1 %and, true937  %and2 = select i1 %nand, i1 %or, i1 false938  ret i1 %and2939}940 941define i1 @xor_commute1(i1 %x, i1 %y) {942; CHECK-LABEL: @xor_commute1(943; CHECK-NEXT:    [[AND:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false944; CHECK-NEXT:    [[NAND:%.*]] = xor i1 [[AND]], true945; CHECK-NEXT:    call void @use1(i1 [[NAND]])946; CHECK-NEXT:    [[AND2:%.*]] = xor i1 [[X]], [[Y]]947; CHECK-NEXT:    ret i1 [[AND2]]948;949  %and = select i1 %x, i1 %y, i1 false950  %or = select i1 %y, i1 true, i1 %x951  %nand = xor i1 %and, true952  call void @use1(i1 %nand)953  %and2 = select i1 %nand, i1 %or, i1 false954  ret i1 %and2955}956 957define i1 @xor_commute2(i1 %x, i1 %y) {958; CHECK-LABEL: @xor_commute2(959; CHECK-NEXT:    [[AND:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false960; CHECK-NEXT:    call void @use1(i1 [[AND]])961; CHECK-NEXT:    [[OR:%.*]] = select i1 [[X]], i1 true, i1 [[Y]]962; CHECK-NEXT:    call void @use1(i1 [[OR]])963; CHECK-NEXT:    [[NAND:%.*]] = xor i1 [[AND]], true964; CHECK-NEXT:    call void @use1(i1 [[NAND]])965; CHECK-NEXT:    [[AND2:%.*]] = xor i1 [[X]], [[Y]]966; CHECK-NEXT:    ret i1 [[AND2]]967;968  %and = select i1 %x, i1 %y, i1 false969  call void @use1(i1 %and)970  %or = select i1 %x, i1 true, i1 %y971  call void @use1(i1 %or)972  %nand = xor i1 %and, true973  call void @use1(i1 %nand)974  %and2 = select i1 %or, i1 %nand, i1 false975  ret i1 %and2976}977 978define <2 x i1> @xor_commute3(<2 x i1> %x, <2 x i1> %y) {979; CHECK-LABEL: @xor_commute3(980; CHECK-NEXT:    [[AND2:%.*]] = xor <2 x i1> [[X:%.*]], [[Y:%.*]]981; CHECK-NEXT:    ret <2 x i1> [[AND2]]982;983  %and = select <2 x i1> %x, <2 x i1> %y, <2 x i1> <i1 false, i1 false>984  %or = select <2 x i1> %y, <2 x i1> <i1 true, i1 true>, <2 x i1> %x985  %nand = xor <2 x i1> %and, <i1 true, i1 true>986  %and2 = select <2 x i1> %or, <2 x i1> %nand, <2 x i1> <i1 false, i1 false>987  ret <2 x i1> %and2988}989 990define i1 @not_d_bools_commute00(i1 %c, i1 %x, i1 %y) {991; CHECK-LABEL: @not_d_bools_commute00(992; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[Y:%.*]], true993; CHECK-NEXT:    [[R:%.*]] = select i1 [[C:%.*]], i1 [[X:%.*]], i1 [[TMP1]]994; CHECK-NEXT:    ret i1 [[R]]995;996  %y_c = or i1 %c, %y997  %and2 = xor i1 %y_c, true998  %and1 = and i1 %c, %x999  %r = or i1 %and1, %and21000  ret i1 %r1001}1002 1003define i1 @not_d_bools_commute01(i1 %c, i1 %x, i1 %y) {1004; CHECK-LABEL: @not_d_bools_commute01(1005; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[Y:%.*]], true1006; CHECK-NEXT:    [[R:%.*]] = select i1 [[C:%.*]], i1 [[X:%.*]], i1 [[TMP1]]1007; CHECK-NEXT:    ret i1 [[R]]1008;1009  %y_c = or i1 %y, %c1010  %and2 = xor i1 %y_c, true1011  %and1 = and i1 %c, %x1012  %r = or i1 %and1, %and21013  ret i1 %r1014}1015 1016define i1 @not_d_bools_commute10(i1 %c, i1 %x, i1 %y) {1017; CHECK-LABEL: @not_d_bools_commute10(1018; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[Y:%.*]], true1019; CHECK-NEXT:    [[R:%.*]] = select i1 [[C:%.*]], i1 [[X:%.*]], i1 [[TMP1]]1020; CHECK-NEXT:    ret i1 [[R]]1021;1022  %y_c = or i1 %c, %y1023  %and2 = xor i1 %y_c, true1024  %and1 = and i1 %x, %c1025  %r = or i1 %and1, %and21026  ret i1 %r1027}1028 1029define i1 @not_d_bools_commute11(i1 %c, i1 %x, i1 %y) {1030; CHECK-LABEL: @not_d_bools_commute11(1031; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[Y:%.*]], true1032; CHECK-NEXT:    [[R:%.*]] = select i1 [[C:%.*]], i1 [[X:%.*]], i1 [[TMP1]]1033; CHECK-NEXT:    ret i1 [[R]]1034;1035  %y_c = or i1 %y, %c1036  %and2 = xor i1 %y_c, true1037  %and1 = and i1 %x, %c1038  %r = or i1 %and1, %and21039  ret i1 %r1040}1041 1042define <2 x i1> @not_d_bools_vector(<2 x i1> %c, <2 x i1> %x, <2 x i1> %y) {1043; CHECK-LABEL: @not_d_bools_vector(1044; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)1045; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i1> [[X:%.*]], <2 x i1> [[TMP1]]1046; CHECK-NEXT:    ret <2 x i1> [[R]]1047;1048  %y_c = or <2 x i1> %y, %c1049  %and2 = xor <2 x i1> %y_c, <i1 true, i1 true>1050  %and1 = and <2 x i1> %x, %c1051  %r = or <2 x i1> %and1, %and21052  ret <2 x i1> %r1053}1054 1055define <2 x i1> @not_d_bools_vector_poison(<2 x i1> %c, <2 x i1> %x, <2 x i1> %y) {1056; CHECK-LABEL: @not_d_bools_vector_poison(1057; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)1058; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i1> [[X:%.*]], <2 x i1> [[TMP1]]1059; CHECK-NEXT:    ret <2 x i1> [[R]]1060;1061  %y_c = or <2 x i1> %y, %c1062  %and2 = xor <2 x i1> %y_c, <i1 poison, i1 true>1063  %and1 = and <2 x i1> %x, %c1064  %r = or <2 x i1> %and1, %and21065  ret <2 x i1> %r1066}1067 1068define i32 @not_d_allSignBits(i32 %cond, i32 %tval, i32 %fval) {1069; CHECK-LABEL: @not_d_allSignBits(1070; CHECK-NEXT:    [[DOTNOT2:%.*]] = icmp slt i32 [[COND:%.*]], 01071; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[FVAL:%.*]], -11072; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[DOTNOT2]], i32 [[TVAL:%.*]], i32 [[TMP1]]1073; CHECK-NEXT:    ret i32 [[SEL]]1074;1075  %bitmask = ashr i32 %cond, 311076  %a1 = and i32 %tval, %bitmask1077  %or = or i32 %bitmask, %fval1078  %a2 = xor i32 %or, -11079  %sel = or i32 %a1, %a21080  ret i32 %sel1081}1082 1083define i1 @not_d_bools_use2(i1 %c, i1 %x, i1 %y) {1084; CHECK-LABEL: @not_d_bools_use2(1085; CHECK-NEXT:    [[Y_C:%.*]] = or i1 [[C:%.*]], [[Y:%.*]]1086; CHECK-NEXT:    [[AND1:%.*]] = and i1 [[C]], [[X:%.*]]1087; CHECK-NEXT:    [[TMP1:%.*]] = xor i1 [[Y]], true1088; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i1 [[X]], i1 [[TMP1]]1089; CHECK-NEXT:    call void @use1(i1 [[AND1]])1090; CHECK-NEXT:    call void @use1(i1 [[Y_C]])1091; CHECK-NEXT:    ret i1 [[R]]1092;1093  %y_c = or i1 %c, %y1094  %and2 = xor i1 %y_c, true1095  %and1 = and i1 %c, %x1096  %r = or i1 %and1, %and21097  call void @use1(i1 %and1)1098  call void @use1(i1 %y_c)1099  ret i1 %r1100}1101 1102; negative test: both op is not one-use1103 1104define i1 @not_d_bools_negative_use2(i1 %c, i1 %x, i1 %y) {1105; CHECK-LABEL: @not_d_bools_negative_use2(1106; CHECK-NEXT:    [[Y_C:%.*]] = or i1 [[C:%.*]], [[Y:%.*]]1107; CHECK-NEXT:    [[AND2:%.*]] = xor i1 [[Y_C]], true1108; CHECK-NEXT:    [[AND1:%.*]] = and i1 [[C]], [[X:%.*]]1109; CHECK-NEXT:    [[R:%.*]] = or i1 [[AND1]], [[AND2]]1110; CHECK-NEXT:    call void @use1(i1 [[AND2]])1111; CHECK-NEXT:    call void @use1(i1 [[AND1]])1112; CHECK-NEXT:    ret i1 [[R]]1113;1114  %y_c = or i1 %c, %y1115  %and2 = xor i1 %y_c, true1116  %and1 = and i1 %c, %x1117  %r = or i1 %and1, %and21118  call void @use1(i1 %and2)1119  call void @use1(i1 %and1)1120  ret i1 %r1121}1122 1123; A & (~C | B)1124define i1 @logical_and_or_with_not_op(i1 %a, i1 %b, i1 %c) {1125; CHECK-LABEL: @logical_and_or_with_not_op(1126; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true1127; CHECK-NEXT:    [[OR:%.*]] = or i1 [[B:%.*]], [[NOT]]1128; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A:%.*]], i1 [[OR]], i1 false1129; CHECK-NEXT:    ret i1 [[AND]]1130;1131  %not = xor i1 %c, true1132  %or = or i1 %not, %b1133  %and = select i1 %a, i1 %or, i1 zeroinitializer1134  ret i1 %and1135}1136 1137; As logical_and_or_with_not_op but with C=A1138; A & (~A | B) --> A & B1139define i1 @logical_and_or_with_common_not_op_variant1(i1 %a, i1 %b) {1140; CHECK-LABEL: @logical_and_or_with_common_not_op_variant1(1141; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false1142; CHECK-NEXT:    ret i1 [[AND]]1143;1144  %not = xor i1 %a, true1145  %or = or i1 %not, %b1146  %and = select i1 %a, i1 %or, i1 zeroinitializer1147  ret i1 %and1148}1149 1150; As logical_and_or_with_common_not_op_variant1 but operating on vectors1151; A & (~A | B) --> A & B1152define <2 x i1> @logical_and_or_with_common_not_op_variant2(<2 x i1> %a, <2 x i1> %b) {1153; CHECK-LABEL: @logical_and_or_with_common_not_op_variant2(1154; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[A:%.*]], <2 x i1> [[B:%.*]], <2 x i1> zeroinitializer1155; CHECK-NEXT:    ret <2 x i1> [[AND]]1156;1157  %not = xor <2 x i1> %a, <i1 true, i1 true>1158  %or = or <2 x i1> %not, %b1159  %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer1160  ret <2 x i1> %and1161}1162 1163; As logical_and_or_with_common_not_op_variant1 but with "or" implemented as1164; "select X, true, Y"1165; A & (~A | B) --> A & B1166define i1 @logical_and_or_with_common_not_op_variant3(i1 %a, i1 %b) {1167; CHECK-LABEL: @logical_and_or_with_common_not_op_variant3(1168; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false1169; CHECK-NEXT:    ret i1 [[AND]]1170;1171  %not = xor i1 %a, true1172  %or = select i1 %not, i1 true, i1 %b1173  %and = select i1 %a, i1 %or, i1 zeroinitializer1174  ret i1 %and1175}1176 1177; As logical_and_or_with_common_not_op_variant3 but operating on vectors where1178; each operand has other uses1179; A & (~A | B) --> A & B1180define <2 x i1> @logical_and_or_with_common_not_op_variant4(<2 x i1> %a, <2 x i1> %b) {1181; CHECK-LABEL: @logical_and_or_with_common_not_op_variant4(1182; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], splat (i1 true)1183; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[NOT]], <2 x i1> splat (i1 true), <2 x i1> [[B:%.*]]1184; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[A]], <2 x i1> [[B]], <2 x i1> zeroinitializer1185; CHECK-NEXT:    call void @use2(<2 x i1> [[A]])1186; CHECK-NEXT:    call void @use2(<2 x i1> [[B]])1187; CHECK-NEXT:    call void @use2(<2 x i1> [[OR]])1188; CHECK-NEXT:    ret <2 x i1> [[AND]]1189;1190  %not = xor <2 x i1> %a, <i1 true, i1 true>1191  %or = select <2 x i1> %not, <2 x i1> <i1 true, i1 true>, <2 x i1> %b1192  %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer1193  call void @use2(<2 x i1> %a)1194  call void @use2(<2 x i1> %b)1195  call void @use2(<2 x i1> %or)1196  ret <2 x i1> %and1197}1198 1199; As logical_and_or_with_common_not_op_variant1 but with |'s operands swapped1200; A & (B | ~A) --> A & B1201define i1 @logical_and_or_with_common_not_op_variant5(i1 %a) {1202; CHECK-LABEL: @logical_and_or_with_common_not_op_variant5(1203; CHECK-NEXT:    [[B:%.*]] = call i1 @gen()1204; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A:%.*]], i1 [[B]], i1 false1205; CHECK-NEXT:    ret i1 [[AND]]1206;1207  %b = call i1 @gen()1208  %not = xor i1 %a, true1209  %or = or i1 %b, %not1210  %and = select i1 %a, i1 %or, i1 zeroinitializer1211  ret i1 %and1212}1213 1214; A | (~C & B)1215define i1 @logical_or_and_with_not_op(i1 %a, i1 %b, i1 %c) {1216; CHECK-LABEL: @logical_or_and_with_not_op(1217; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true1218; CHECK-NEXT:    [[AND:%.*]] = and i1 [[B:%.*]], [[NOT]]1219; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[AND]]1220; CHECK-NEXT:    ret i1 [[OR]]1221;1222  %not = xor i1 %c, true1223  %and = and i1 %not, %b1224  %or = select i1 %a, i1 true, i1 %and1225  ret i1 %or1226}1227 1228; As logical_or_and_with_not_op but with C=A1229; A | (~A & B) --> A | B1230define i1 @logical_or_and_with_common_not_op_variant1(i1 %a, i1 %b) {1231; CHECK-LABEL: @logical_or_and_with_common_not_op_variant1(1232; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]1233; CHECK-NEXT:    ret i1 [[OR]]1234;1235  %not = xor i1 %a, true1236  %and = and i1 %not, %b1237  %or = select i1 %a, i1 true, i1 %and1238  ret i1 %or1239}1240 1241; As logical_or_and_with_common_not_op_variant1 but operating on vectors1242; A | (~A & B) --> A | B1243define <2 x i1> @logical_or_and_with_common_not_op_variant2(<2 x i1> %a, <2 x i1> %b) {1244; CHECK-LABEL: @logical_or_and_with_common_not_op_variant2(1245; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[A:%.*]], <2 x i1> splat (i1 true), <2 x i1> [[B:%.*]]1246; CHECK-NEXT:    ret <2 x i1> [[OR]]1247;1248  %not = xor <2 x i1> %a, <i1 true, i1 true>1249  %and = and <2 x i1> %not, %b1250  %or = select <2 x i1> %a, <2 x i1> <i1 true, i1 true>, <2 x i1> %and1251  ret <2 x i1> %or1252}1253 1254; As logical_or_and_with_common_not_op_variant1 but with "and" implemented as1255; "select X, Y, false"1256; A | (~A & B) --> A | B1257define i1 @logical_or_and_with_common_not_op_variant3(i1 %a, i1 %b) {1258; CHECK-LABEL: @logical_or_and_with_common_not_op_variant3(1259; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]1260; CHECK-NEXT:    ret i1 [[OR]]1261;1262  %not = xor i1 %a, true1263  %and = select i1 %not, i1 %b, i1 false1264  %or = select i1 %a, i1 true, i1 %and1265  ret i1 %or1266}1267 1268; As logical_or_and_with_common_not_op_variant3 but operating on vectors where1269; each operand has other uses1270; A | (~A & B) --> A | B1271define <2 x i1> @logical_or_and_with_common_not_op_variant4(<2 x i1> %a, <2 x i1> %b) {1272; CHECK-LABEL: @logical_or_and_with_common_not_op_variant4(1273; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], splat (i1 true)1274; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[NOT]], <2 x i1> [[B:%.*]], <2 x i1> zeroinitializer1275; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[A]], <2 x i1> splat (i1 true), <2 x i1> [[B]]1276; CHECK-NEXT:    call void @use2(<2 x i1> [[A]])1277; CHECK-NEXT:    call void @use2(<2 x i1> [[B]])1278; CHECK-NEXT:    call void @use2(<2 x i1> [[AND]])1279; CHECK-NEXT:    ret <2 x i1> [[OR]]1280;1281  %not = xor <2 x i1> %a, <i1 true, i1 true>1282  %and = select <2 x i1> %not, <2 x i1> %b, <2 x i1> zeroinitializer1283  %or = select <2 x i1> %a, <2 x i1> <i1 true, i1 true>, <2 x i1> %and1284  call void @use2(<2 x i1> %a)1285  call void @use2(<2 x i1> %b)1286  call void @use2(<2 x i1> %and)1287  ret <2 x i1> %or1288}1289 1290; As logical_or_and_with_common_not_op_variant1 but with &'s operands swapped1291; A | (B & ~A) --> A | B1292define i1 @logical_or_and_with_common_not_op_variant5(i1 %a) {1293; CHECK-LABEL: @logical_or_and_with_common_not_op_variant5(1294; CHECK-NEXT:    [[B:%.*]] = call i1 @gen()1295; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B]]1296; CHECK-NEXT:    ret i1 [[OR]]1297;1298  %b = call i1 @gen()1299  %not = xor i1 %a, true1300  %and = and i1 %b, %not1301  %or = select i1 %a, i1 true, i1 %and1302  ret i1 %or1303}1304 1305define i1 @reduce_logical_and1(i1 %a, i32 %b, i32 %c) {1306; CHECK-LABEL: @reduce_logical_and1(1307; CHECK-NEXT:  bb:1308; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61309; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1310; CHECK-NEXT:    [[TMP0:%.*]] = and i1 [[CMP1]], [[CMP]]1311; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 [[TMP0]], i1 false1312; CHECK-NEXT:    ret i1 [[AND2]]1313;1314bb:1315  %cmp = icmp slt i32 %b, 61316  %cmp1 = icmp sgt i32 %c, %b1317  %and1 = select i1 %a, i1 %cmp1, i1 false1318  %and2 = select i1 %and1, i1 %cmp, i1 false1319  ret i1 %and21320}1321 1322define i1 @reduce_logical_and2(i1 %a, i1 %b, i1 %c) {1323; CHECK-LABEL: @reduce_logical_and2(1324; CHECK-NEXT:  bb:1325; CHECK-NEXT:    [[TMP0:%.*]] = xor i1 [[C:%.*]], true1326; CHECK-NEXT:    [[TMP1:%.*]] = and i1 [[B:%.*]], [[TMP0]]1327; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false1328; CHECK-NEXT:    ret i1 [[AND2]]1329;1330bb:1331  %or = xor i1 %c, %b1332  %and1 = select i1 %a, i1 %or, i1 false1333  %and2 = select i1 %and1, i1 %b, i1 false1334  ret i1 %and21335}1336 1337define i1 @reduce_logical_and3(i1 %a, i32 %b, i32 noundef %c) {1338; CHECK-LABEL: @reduce_logical_and3(1339; CHECK-NEXT:  bb:1340; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61341; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1342; CHECK-NEXT:    [[TMP0:%.*]] = and i1 [[CMP]], [[CMP1]]1343; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 [[TMP0]], i1 false1344; CHECK-NEXT:    ret i1 [[AND2]]1345;1346bb:1347  %cmp = icmp slt i32 %b, 61348  %cmp1 = icmp sgt i32 %c, %b1349  %and1 = select i1 %a, i1 %cmp, i1 false1350  %and2 = select i1 %and1, i1 %cmp1, i1 false1351  ret i1 %and21352}1353 1354define i1 @reduce_logical_or1(i1 %a, i32 %b, i32 %c) {1355; CHECK-LABEL: @reduce_logical_or1(1356; CHECK-NEXT:  bb:1357; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61358; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1359; CHECK-NEXT:    [[TMP0:%.*]] = or i1 [[CMP1]], [[CMP]]1360; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[TMP0]]1361; CHECK-NEXT:    ret i1 [[AND2]]1362;1363bb:1364  %cmp = icmp slt i32 %b, 61365  %cmp1 = icmp sgt i32 %c, %b1366  %and1 = select i1 %a, i1 true, i1 %cmp11367  %and2 = select i1 %and1, i1 true, i1 %cmp1368  ret i1 %and21369}1370 1371define i1 @reduce_logical_or2(i1 %a, i1 %b, i1 %c) {1372; CHECK-LABEL: @reduce_logical_or2(1373; CHECK-NEXT:  bb:1374; CHECK-NEXT:    [[TMP0:%.*]] = or i1 [[C:%.*]], [[B:%.*]]1375; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[TMP0]]1376; CHECK-NEXT:    ret i1 [[AND2]]1377;1378bb:1379  %or = xor i1 %c, %b1380  %and1 = select i1 %a, i1 true, i1 %or1381  %and2 = select i1 %and1, i1 true, i1 %b1382  ret i1 %and21383}1384 1385define i1 @reduce_logical_or3(i1 %a, i32 %b, i32 noundef %c) {1386; CHECK-LABEL: @reduce_logical_or3(1387; CHECK-NEXT:  bb:1388; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61389; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1390; CHECK-NEXT:    [[TMP0:%.*]] = or i1 [[CMP]], [[CMP1]]1391; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[TMP0]]1392; CHECK-NEXT:    ret i1 [[AND2]]1393;1394bb:1395  %cmp = icmp slt i32 %b, 61396  %cmp1 = icmp sgt i32 %c, %b1397  %and1 = select i1 %a, i1 true, i1 %cmp1398  %and2 = select i1 %and1, i1 true, i1 %cmp11399  ret i1 %and21400}1401 1402define i1 @reduce_logical_and_fail1(i1 %a, i32 %b, i32 %c) {1403; CHECK-LABEL: @reduce_logical_and_fail1(1404; CHECK-NEXT:  bb:1405; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61406; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1407; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 [[CMP]], i1 false1408; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[AND1]], i1 [[CMP1]], i1 false1409; CHECK-NEXT:    ret i1 [[AND2]]1410;1411bb:1412  %cmp = icmp slt i32 %b, 61413  %cmp1 = icmp sgt i32 %c, %b1414  %and1 = select i1 %a, i1 %cmp, i1 false1415  %and2 = select i1 %and1, i1 %cmp1, i1 false1416  ret i1 %and21417}1418 1419define i1 @reduce_logical_and_fail2(i1 %a, i32 %b, i32 %c) {1420; CHECK-LABEL: @reduce_logical_and_fail2(1421; CHECK-NEXT:  bb:1422; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61423; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], 71424; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 [[CMP]], i1 false1425; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[AND1]], i1 [[CMP1]], i1 false1426; CHECK-NEXT:    ret i1 [[AND2]]1427;1428bb:1429  %cmp = icmp slt i32 %b, 61430  %cmp1 = icmp sgt i32 %c, 71431  %and1 = select i1 %a, i1 %cmp, i1 false1432  %and2 = select i1 %and1, i1 %cmp1, i1 false1433  ret i1 %and21434}1435 1436define i1 @reduce_logical_or_fail1(i1 %a, i32 %b, i32 %c) {1437; CHECK-LABEL: @reduce_logical_or_fail1(1438; CHECK-NEXT:  bb:1439; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61440; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1441; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[CMP]]1442; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[AND1]], i1 true, i1 [[CMP1]]1443; CHECK-NEXT:    ret i1 [[AND2]]1444;1445bb:1446  %cmp = icmp slt i32 %b, 61447  %cmp1 = icmp sgt i32 %c, %b1448  %and1 = select i1 %a, i1 true, i1 %cmp1449  %and2 = select i1 %and1, i1 true, i1 %cmp11450  ret i1 %and21451}1452 1453define i1 @reduce_logical_or_fail2(i1 %a, i32 %b, i32 %c) {1454; CHECK-LABEL: @reduce_logical_or_fail2(1455; CHECK-NEXT:  bb:1456; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61457; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], 71458; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[CMP]]1459; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[AND1]], i1 true, i1 [[CMP1]]1460; CHECK-NEXT:    ret i1 [[AND2]]1461;1462bb:1463  %cmp = icmp slt i32 %b, 61464  %cmp1 = icmp sgt i32 %c, 71465  %and1 = select i1 %a, i1 true, i1 %cmp1466  %and2 = select i1 %and1, i1 true, i1 %cmp11467  ret i1 %and21468}1469 1470define i1 @reduce_logical_and_multiuse(i1 %a, i32 %b, i32 %c) {1471; CHECK-LABEL: @reduce_logical_and_multiuse(1472; CHECK-NEXT:  bb:1473; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61474; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1475; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 [[CMP1]], i1 false1476; CHECK-NEXT:    call void @use1(i1 [[AND1]])1477; CHECK-NEXT:    [[AND2:%.*]] = select i1 [[AND1]], i1 [[CMP]], i1 false1478; CHECK-NEXT:    ret i1 [[AND2]]1479;1480bb:1481  %cmp = icmp slt i32 %b, 61482  %cmp1 = icmp sgt i32 %c, %b1483  %and1 = select i1 %a, i1 %cmp1, i1 false1484  call void @use1(i1 %and1)1485  %and2 = select i1 %and1, i1 %cmp, i1 false1486  ret i1 %and21487}1488 1489define i1 @reduce_bitwise_and1(i1 %a, i32 %b, i32 %c) {1490; CHECK-LABEL: @reduce_bitwise_and1(1491; CHECK-NEXT:  bb:1492; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61493; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1494; CHECK-NEXT:    [[AND1:%.*]] = or i1 [[A:%.*]], [[CMP1]]1495; CHECK-NEXT:    [[AND2:%.*]] = and i1 [[AND1]], [[CMP]]1496; CHECK-NEXT:    ret i1 [[AND2]]1497;1498bb:1499  %cmp = icmp slt i32 %b, 61500  %cmp1 = icmp sgt i32 %c, %b1501  %and1 = or i1 %a, %cmp11502  %and2 = select i1 %and1, i1 %cmp, i1 false1503  ret i1 %and21504}1505 1506define i1 @reduce_bitwise_and2(i1 %a, i32 %b, i32 %c) {1507; CHECK-LABEL: @reduce_bitwise_and2(1508; CHECK-NEXT:  bb:1509; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], 61510; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[C:%.*]], [[B]]1511; CHECK-NEXT:    [[AND1:%.*]] = select i1 [[A:%.*]], i1 [[CMP1]], i1 false1512; CHECK-NEXT:    [[AND2:%.*]] = or i1 [[AND1]], [[CMP]]1513; CHECK-NEXT:    ret i1 [[AND2]]1514;1515bb:1516  %cmp = icmp slt i32 %b, 61517  %cmp1 = icmp sgt i32 %c, %b1518  %and1 = select i1 %a, i1 %cmp1, i1 false1519  %and2 = or i1 %and1, %cmp1520  ret i1 %and21521}1522 1523define i1 @test_logical_and_icmp_samesign(i8 %x) {1524; CHECK-LABEL: @test_logical_and_icmp_samesign(1525; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i8 [[X:%.*]], 91526; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult i8 [[X]], 111527; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]1528; CHECK-NEXT:    ret i1 [[AND]]1529;1530  %cmp1 = icmp ne i8 %x, 91531  %cmp2 = icmp samesign ult i8 %x, 111532  %and = select i1 %cmp1, i1 %cmp2, i1 false1533  ret i1 %and1534}1535 1536define i1 @test_logical_or_icmp_samesign(i8 %x) {1537; CHECK-LABEL: @test_logical_or_icmp_samesign(1538; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], -91539; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult i8 [[X]], -111540; CHECK-NEXT:    [[OR:%.*]] = or i1 [[CMP1]], [[CMP2]]1541; CHECK-NEXT:    ret i1 [[OR]]1542;1543  %cmp1 = icmp eq i8 %x, -91544  %cmp2 = icmp samesign ult i8 %x, -111545  %or = select i1 %cmp1, i1 true, i1 %cmp21546  ret i1 %or1547}1548 1549define i1 @test_double_logical_and_icmp_samesign1(i1 %cond, i32 %y) {1550; CHECK-LABEL: @test_double_logical_and_icmp_samesign1(1551; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult i32 [[Y:%.*]], 41552; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[SEL1:%.*]], i1 [[CMP2]], i1 false1553; CHECK-NEXT:    ret i1 [[SEL2]]1554;1555  %cmp1 = icmp ne i32 %y, 51556  %sel1 = select i1 %cond, i1 %cmp1, i1 false1557  %cmp2 = icmp samesign ult i32 %y, 41558  %sel2 = select i1 %sel1, i1 %cmp2, i1 false1559  ret i1 %sel21560}1561 1562define i1 @test_double_logical_and_icmp_samesign2(i1 %cond, i32 %y) {1563; CHECK-LABEL: @test_double_logical_and_icmp_samesign2(1564; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[Y:%.*]], -655361565; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i32 [[TMP1]], 10485761566; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[SEL1:%.*]], i1 [[CMP2]], i1 false1567; CHECK-NEXT:    ret i1 [[SEL2]]1568;1569  %cmp1 = icmp samesign ugt i32 %y, 655351570  %sel1 = select i1 %cond, i1 %cmp1, i1 false1571  %cmp2 = icmp samesign ult i32 %y, 11141121572  %sel2 = select i1 %sel1, i1 %cmp2, i1 false1573  ret i1 %sel21574}1575 1576define <2 x i1> @test_logical_and_icmp_samesign_vec(<2 x i8> %x) {1577; CHECK-LABEL: @test_logical_and_icmp_samesign_vec(1578; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], splat (i8 9)1579; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], splat (i8 11)1580; CHECK-NEXT:    [[AND:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]1581; CHECK-NEXT:    ret <2 x i1> [[AND]]1582;1583  %cmp1 = icmp ne <2 x i8> %x, splat(i8 9)1584  %cmp2 = icmp samesign ult <2 x i8> %x, splat(i8 11)1585  %and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer1586  ret <2 x i1> %and1587}1588 1589define <2 x i1> @test_logical_and_icmp_samesign_vec_with_poison_cond(<2 x i8> %x) {1590; CHECK-LABEL: @test_logical_and_icmp_samesign_vec_with_poison_cond(1591; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 9, i8 poison>1592; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], splat (i8 11)1593; CHECK-NEXT:    [[AND:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]1594; CHECK-NEXT:    ret <2 x i1> [[AND]]1595;1596  %cmp1 = icmp ne <2 x i8> %x, <i8 9, i8 poison>1597  %cmp2 = icmp samesign ult <2 x i8> %x, splat(i8 11)1598  %and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer1599  ret <2 x i1> %and1600}1601 1602define i1 @test_logical_and_icmp_samesign_do_not_imply(i8 %x) {1603; CHECK-LABEL: @test_logical_and_icmp_samesign_do_not_imply(1604; CHECK-NEXT:    [[AND:%.*]] = icmp ult i8 [[X:%.*]], 111605; CHECK-NEXT:    ret i1 [[AND]]1606;1607  %cmp1 = icmp ne i8 %x, -91608  %cmp2 = icmp samesign ult i8 %x, 111609  %and = select i1 %cmp1, i1 %cmp2, i1 false1610  ret i1 %and1611}1612 1613define i1 @test_logical_and_icmp_no_samesign(i8 %x) {1614; CHECK-LABEL: @test_logical_and_icmp_no_samesign(1615; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i8 [[X:%.*]], 91616; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i8 [[X]], 111617; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]1618; CHECK-NEXT:    ret i1 [[AND]]1619;1620  %cmp1 = icmp ne i8 %x, 91621  %cmp2 = icmp ult i8 %x, 111622  %and = select i1 %cmp1, i1 %cmp2, i1 false1623  ret i1 %and1624}1625 1626; Negative tests1627 1628define <2 x i1> @test_logical_and_icmp_samesign_vec_with_poison_tv(<2 x i8> %x) {1629; CHECK-LABEL: @test_logical_and_icmp_samesign_vec_with_poison_tv(1630; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne <2 x i8> [[X:%.*]], splat (i8 9)1631; CHECK-NEXT:    [[CMP2:%.*]] = icmp samesign ult <2 x i8> [[X]], <i8 11, i8 poison>1632; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[CMP1]], <2 x i1> [[CMP2]], <2 x i1> zeroinitializer1633; CHECK-NEXT:    ret <2 x i1> [[AND]]1634;1635  %cmp1 = icmp ne <2 x i8> %x, splat(i8 9)1636  %cmp2 = icmp samesign ult <2 x i8> %x, <i8 11, i8 poison>1637  %and = select <2 x i1> %cmp1, <2 x i1> %cmp2, <2 x i1> zeroinitializer1638  ret <2 x i1> %and1639}1640