1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instsimplify -S | FileCheck %s 3 4define i32 @select_and_icmp(i32 %x, i32 %y, i32 %z) { 5; CHECK-LABEL: @select_and_icmp( 6; CHECK-NEXT: ret i32 [[X:%.*]] 7; 8 %A = icmp eq i32 %x, %z 9 %B = icmp eq i32 %y, %z 10 %C = and i1 %A, %B 11 %D = select i1 %C, i32 %z, i32 %x 12 ret i32 %D 13} 14 15define <2 x i8> @select_and_icmp_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { 16; CHECK-LABEL: @select_and_icmp_vec( 17; CHECK-NEXT: ret <2 x i8> [[X:%.*]] 18; 19 %A = icmp eq <2 x i8> %x, %z 20 %B = icmp eq <2 x i8> %y, %z 21 %C = and <2 x i1> %A, %B 22 %D = select <2 x i1> %C, <2 x i8> %z, <2 x i8> %x 23 ret <2 x i8> %D 24} 25 26define i32 @select_and_icmp2(i32 %x, i32 %y, i32 %z) { 27; CHECK-LABEL: @select_and_icmp2( 28; CHECK-NEXT: ret i32 [[Y:%.*]] 29; 30 %A = icmp eq i32 %x, %z 31 %B = icmp eq i32 %y, %z 32 %C = and i1 %A, %B 33 %D = select i1 %C, i32 %z, i32 %y 34 ret i32 %D 35} 36 37define i32 @select_and_icmp_alt(i32 %x, i32 %y, i32 %z) { 38; CHECK-LABEL: @select_and_icmp_alt( 39; CHECK-NEXT: ret i32 [[Z:%.*]] 40; 41 %A = icmp eq i32 %x, %z 42 %B = icmp eq i32 %y, %z 43 %C = and i1 %A, %B 44 %D = select i1 %C, i32 %x, i32 %z 45 ret i32 %D 46} 47 48define i32 @select_and_icmp_alt2(i32 %x, i32 %y, i32 %z) { 49; CHECK-LABEL: @select_and_icmp_alt2( 50; CHECK-NEXT: ret i32 [[Z:%.*]] 51; 52 %A = icmp eq i32 %x, %z 53 %B = icmp eq i32 %y, %z 54 %C = and i1 %A, %B 55 %D = select i1 %C, i32 %y, i32 %z 56 ret i32 %D 57} 58 59define i32 @select_and_icmp_inv_alt(i32 %x, i32 %y, i32 %z) { 60; CHECK-LABEL: @select_and_icmp_inv_alt( 61; CHECK-NEXT: ret i32 [[Z:%.*]] 62; 63 %A = icmp eq i32 %z, %x 64 %B = icmp eq i32 %z, %y 65 %C = and i1 %A, %B 66 %D = select i1 %C, i32 %x, i32 %z 67 ret i32 %D 68} 69 70define i32 @select_and_inv_icmp_alt(i32 %x, i32 %y, i32 %z) { 71; CHECK-LABEL: @select_and_inv_icmp_alt( 72; CHECK-NEXT: ret i32 [[Z:%.*]] 73; 74 %A = icmp eq i32 %x, %z 75 %B = icmp eq i32 %y, %z 76 %C = and i1 %B, %A 77 %D = select i1 %C, i32 %x, i32 %z 78 ret i32 %D 79} 80 81define i32 @select_and_inv_icmp(i32 %x, i32 %y, i32 %z) { 82; CHECK-LABEL: @select_and_inv_icmp( 83; CHECK-NEXT: ret i32 [[X:%.*]] 84; 85 %A = icmp eq i32 %x, %z 86 %B = icmp eq i32 %y, %z 87 %C = and i1 %B , %A 88 %D = select i1 %C, i32 %z, i32 %x 89 ret i32 %D 90} 91 92define <2 x i8> @select_and_icmp_alt_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) { 93; CHECK-LABEL: @select_and_icmp_alt_vec( 94; CHECK-NEXT: ret <2 x i8> [[Z:%.*]] 95; 96 %A = icmp eq <2 x i8> %x, %z 97 %B = icmp eq <2 x i8> %y, %z 98 %C = and <2 x i1> %A, %B 99 %D = select <2 x i1> %C, <2 x i8> %x, <2 x i8> %z 100 ret <2 x i8> %D 101} 102 103 104define i32 @select_and_icmp_inv(i32 %x, i32 %y, i32 %z) { 105; CHECK-LABEL: @select_and_icmp_inv( 106; CHECK-NEXT: ret i32 [[X:%.*]] 107; 108 %A = icmp eq i32 %z, %x 109 %B = icmp eq i32 %z, %y 110 %C = and i1 %A, %B 111 %D = select i1 %C, i32 %z, i32 %x 112 ret i32 %D 113} 114 115; Negative tests 116define i32 @select_and_icmp_pred_bad_1(i32 %x, i32 %y, i32 %z) { 117; CHECK-LABEL: @select_and_icmp_pred_bad_1( 118; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 119; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]] 120; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 121; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]] 122; CHECK-NEXT: ret i32 [[D]] 123; 124 %A = icmp eq i32 %x, %z 125 %B = icmp ne i32 %y, %z 126 %C = and i1 %A, %B 127 %D = select i1 %C, i32 %z, i32 %x 128 ret i32 %D 129} 130 131define i32 @select_and_icmp_pred_bad_2(i32 %x, i32 %y, i32 %z) { 132; CHECK-LABEL: @select_and_icmp_pred_bad_2( 133; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]] 134; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 135; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 136; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]] 137; CHECK-NEXT: ret i32 [[D]] 138; 139 %A = icmp ne i32 %x, %z 140 %B = icmp eq i32 %y, %z 141 %C = and i1 %A, %B 142 %D = select i1 %C, i32 %z, i32 %x 143 ret i32 %D 144} 145 146define i32 @select_and_icmp_pred_bad_3(i32 %x, i32 %y, i32 %z) { 147; CHECK-LABEL: @select_and_icmp_pred_bad_3( 148; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]] 149; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]] 150; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 151; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]] 152; CHECK-NEXT: ret i32 [[D]] 153; 154 %A = icmp ne i32 %x, %z 155 %B = icmp ne i32 %y, %z 156 %C = and i1 %A, %B 157 %D = select i1 %C, i32 %z, i32 %x 158 ret i32 %D 159} 160 161define i32 @select_and_icmp_pred_bad_4(i32 %x, i32 %y, i32 %z) { 162; CHECK-LABEL: @select_and_icmp_pred_bad_4( 163; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 164; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 165; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]] 166; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]] 167; CHECK-NEXT: ret i32 [[D]] 168; 169 %A = icmp eq i32 %x, %z 170 %B = icmp eq i32 %y, %z 171 %C = or i1 %A, %B 172 %D = select i1 %C, i32 %z, i32 %x 173 ret i32 %D 174} 175 176define i32 @select_and_icmp_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) { 177; CHECK-LABEL: @select_and_icmp_bad_true_val( 178; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 179; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 180; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 181; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[X]] 182; CHECK-NEXT: ret i32 [[D]] 183; 184 %A = icmp eq i32 %x, %z 185 %B = icmp eq i32 %y, %z 186 %C = and i1 %A, %B 187 %D = select i1 %C, i32 %k, i32 %x 188 ret i32 %D 189} 190 191define i32 @select_and_icmp_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) { 192; CHECK-LABEL: @select_and_icmp_bad_false_val( 193; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 194; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 195; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 196; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[K:%.*]] 197; CHECK-NEXT: ret i32 [[D]] 198; 199 %A = icmp eq i32 %x, %z 200 %B = icmp eq i32 %y, %z 201 %C = and i1 %A, %B 202 %D = select i1 %C, i32 %z, i32 %k 203 ret i32 %D 204} 205 206define i32 @select_and_icmp_bad_op(i32 %x, i32 %y, i32 %z, i32 %k) { 207; CHECK-LABEL: @select_and_icmp_bad_op( 208; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[K:%.*]], [[Z:%.*]] 209; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 210; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 211; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X:%.*]] 212; CHECK-NEXT: ret i32 [[D]] 213; 214 %A = icmp eq i32 %k, %z 215 %B = icmp eq i32 %y, %z 216 %C = and i1 %A, %B 217 %D = select i1 %C, i32 %z, i32 %x 218 ret i32 %D 219} 220 221define i32 @select_and_icmp_bad_op_2(i32 %x, i32 %y, i32 %z, i32 %k) { 222; CHECK-LABEL: @select_and_icmp_bad_op_2( 223; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[K:%.*]] 224; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z:%.*]] 225; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 226; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]] 227; CHECK-NEXT: ret i32 [[D]] 228; 229 %A = icmp eq i32 %x, %k 230 %B = icmp eq i32 %y, %z 231 %C = and i1 %A, %B 232 %D = select i1 %C, i32 %z, i32 %x 233 ret i32 %D 234} 235 236define i32 @select_and_icmp_alt_bad_1(i32 %x, i32 %y, i32 %z) { 237; CHECK-LABEL: @select_and_icmp_alt_bad_1( 238; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 239; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]] 240; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 241; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]] 242; CHECK-NEXT: ret i32 [[D]] 243; 244 %A = icmp eq i32 %x, %z 245 %B = icmp ne i32 %y, %z 246 %C = and i1 %A, %B 247 %D = select i1 %C, i32 %x, i32 %z 248 ret i32 %D 249} 250 251define i32 @select_and_icmp_alt_bad_2(i32 %x, i32 %y, i32 %z) { 252; CHECK-LABEL: @select_and_icmp_alt_bad_2( 253; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]] 254; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 255; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 256; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]] 257; CHECK-NEXT: ret i32 [[D]] 258; 259 %A = icmp ne i32 %x, %z 260 %B = icmp eq i32 %y, %z 261 %C = and i1 %A, %B 262 %D = select i1 %C, i32 %x, i32 %z 263 ret i32 %D 264} 265 266define i32 @select_and_icmp_alt_bad_3(i32 %x, i32 %y, i32 %z) { 267; CHECK-LABEL: @select_and_icmp_alt_bad_3( 268; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]] 269; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]] 270; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 271; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]] 272; CHECK-NEXT: ret i32 [[D]] 273; 274 %A = icmp ne i32 %x, %z 275 %B = icmp ne i32 %y, %z 276 %C = and i1 %A, %B 277 %D = select i1 %C, i32 %x, i32 %z 278 ret i32 %D 279} 280 281define i32 @select_and_icmp_alt_bad_4(i32 %x, i32 %y, i32 %z) { 282; CHECK-LABEL: @select_and_icmp_alt_bad_4( 283; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 284; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 285; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]] 286; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]] 287; CHECK-NEXT: ret i32 [[D]] 288; 289 %A = icmp eq i32 %x, %z 290 %B = icmp eq i32 %y, %z 291 %C = or i1 %A, %B 292 %D = select i1 %C, i32 %x, i32 %z 293 ret i32 %D 294} 295 296define i32 @select_and_icmp_alt_bad_5(i32 %x, i32 %y, i32 %z, i32 %k) { 297; CHECK-LABEL: @select_and_icmp_alt_bad_5( 298; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[K:%.*]] 299; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z:%.*]] 300; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]] 301; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]] 302; CHECK-NEXT: ret i32 [[D]] 303; 304 %A = icmp eq i32 %x, %k 305 %B = icmp eq i32 %y, %z 306 %C = or i1 %A, %B 307 %D = select i1 %C, i32 %x, i32 %z 308 ret i32 %D 309} 310 311define i32 @select_and_icmp_alt_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) { 312; CHECK-LABEL: @select_and_icmp_alt_bad_true_val( 313; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 314; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 315; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 316; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[Z]] 317; CHECK-NEXT: ret i32 [[D]] 318; 319 %A = icmp eq i32 %x, %z 320 %B = icmp eq i32 %y, %z 321 %C = and i1 %A, %B 322 %D = select i1 %C, i32 %k, i32 %z 323 ret i32 %D 324} 325 326define i32 @select_and_icmp_alt_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) { 327; CHECK-LABEL: @select_and_icmp_alt_bad_false_val( 328; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]] 329; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]] 330; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]] 331; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[K:%.*]] 332; CHECK-NEXT: ret i32 [[D]] 333; 334 %A = icmp eq i32 %x, %z 335 %B = icmp eq i32 %y, %z 336 %C = and i1 %A, %B 337 %D = select i1 %C, i32 %x, i32 %k 338 ret i32 %D 339} 340