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