1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4; Test an already canonical branch to make sure we don't flip those. 5define i32 @eq(i32 %X, i32 %Y) { 6; CHECK-LABEL: @eq( 7; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]] 8; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !0 9; CHECK: T: 10; CHECK-NEXT: ret i32 12 11; CHECK: F: 12; CHECK-NEXT: ret i32 123 13; 14 %C = icmp eq i32 %X, %Y 15 br i1 %C, label %T, label %F, !prof !0 16T: 17 ret i32 12 18F: 19 ret i32 123 20} 21 22define i32 @ne(i32 %X, i32 %Y) { 23; CHECK-LABEL: @ne( 24; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]] 25; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !1 26; CHECK: T: 27; CHECK-NEXT: ret i32 12 28; CHECK: F: 29; CHECK-NEXT: ret i32 123 30; 31 %C = icmp ne i32 %X, %Y 32 br i1 %C, label %T, label %F, !prof !1 33T: 34 ret i32 12 35F: 36 ret i32 123 37} 38 39define i32 @ugt(i32 %X, i32 %Y) { 40; CHECK-LABEL: @ugt( 41; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]] 42; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !2 43; CHECK: T: 44; CHECK-NEXT: ret i32 12 45; CHECK: F: 46; CHECK-NEXT: ret i32 123 47; 48 %C = icmp ugt i32 %X, %Y 49 br i1 %C, label %T, label %F, !prof !2 50T: 51 ret i32 12 52F: 53 ret i32 123 54} 55 56define i32 @uge(i32 %X, i32 %Y) { 57; CHECK-LABEL: @uge( 58; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]] 59; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !3 60; CHECK: T: 61; CHECK-NEXT: ret i32 12 62; CHECK: F: 63; CHECK-NEXT: ret i32 123 64; 65 %C = icmp uge i32 %X, %Y 66 br i1 %C, label %T, label %F, !prof !3 67T: 68 ret i32 12 69F: 70 ret i32 123 71} 72 73define i32 @ult(i32 %X, i32 %Y) { 74; CHECK-LABEL: @ult( 75; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]] 76; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !4 77; CHECK: T: 78; CHECK-NEXT: ret i32 12 79; CHECK: F: 80; CHECK-NEXT: ret i32 123 81; 82 %C = icmp ult i32 %X, %Y 83 br i1 %C, label %T, label %F, !prof !4 84T: 85 ret i32 12 86F: 87 ret i32 123 88} 89 90define i32 @ule(i32 %X, i32 %Y) { 91; CHECK-LABEL: @ule( 92; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]] 93; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !5 94; CHECK: T: 95; CHECK-NEXT: ret i32 12 96; CHECK: F: 97; CHECK-NEXT: ret i32 123 98; 99 %C = icmp ule i32 %X, %Y 100 br i1 %C, label %T, label %F, !prof !5 101T: 102 ret i32 12 103F: 104 ret i32 123 105} 106 107define i32 @sgt(i32 %X, i32 %Y) { 108; CHECK-LABEL: @sgt( 109; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]] 110; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !6 111; CHECK: T: 112; CHECK-NEXT: ret i32 12 113; CHECK: F: 114; CHECK-NEXT: ret i32 123 115; 116 %C = icmp sgt i32 %X, %Y 117 br i1 %C, label %T, label %F, !prof !6 118T: 119 ret i32 12 120F: 121 ret i32 123 122} 123 124define i32 @sge(i32 %X, i32 %Y) { 125; CHECK-LABEL: @sge( 126; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]] 127; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !7 128; CHECK: T: 129; CHECK-NEXT: ret i32 12 130; CHECK: F: 131; CHECK-NEXT: ret i32 123 132; 133 %C = icmp sge i32 %X, %Y 134 br i1 %C, label %T, label %F, !prof !7 135T: 136 ret i32 12 137F: 138 ret i32 123 139} 140 141define i32 @slt(i32 %X, i32 %Y) { 142; CHECK-LABEL: @slt( 143; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]] 144; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !8 145; CHECK: T: 146; CHECK-NEXT: ret i32 12 147; CHECK: F: 148; CHECK-NEXT: ret i32 123 149; 150 %C = icmp slt i32 %X, %Y 151 br i1 %C, label %T, label %F, !prof !8 152T: 153 ret i32 12 154F: 155 ret i32 123 156} 157 158define i32 @sle(i32 %X, i32 %Y) { 159; CHECK-LABEL: @sle( 160; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]] 161; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !9 162; CHECK: T: 163; CHECK-NEXT: ret i32 12 164; CHECK: F: 165; CHECK-NEXT: ret i32 123 166; 167 %C = icmp sle i32 %X, %Y 168 br i1 %C, label %T, label %F, !prof !9 169T: 170 ret i32 12 171F: 172 ret i32 123 173} 174 175define i32 @f_false(float %X, float %Y) { 176; CHECK-LABEL: @f_false( 177; CHECK-NEXT: br i1 false, label [[T:%.*]], label [[F:%.*]], !prof !10 178; CHECK: T: 179; CHECK-NEXT: ret i32 12 180; CHECK: F: 181; CHECK-NEXT: ret i32 123 182; 183 %C = fcmp false float %X, %Y 184 br i1 %C, label %T, label %F, !prof !10 185T: 186 ret i32 12 187F: 188 ret i32 123 189} 190 191define i32 @f_oeq(float %X, float %Y) { 192; CHECK-LABEL: @f_oeq( 193; CHECK-NEXT: [[C:%.*]] = fcmp oeq float [[X:%.*]], [[Y:%.*]] 194; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !11 195; CHECK: T: 196; CHECK-NEXT: ret i32 12 197; CHECK: F: 198; CHECK-NEXT: ret i32 123 199; 200 %C = fcmp oeq float %X, %Y 201 br i1 %C, label %T, label %F, !prof !11 202T: 203 ret i32 12 204F: 205 ret i32 123 206} 207 208define i32 @f_ogt(float %X, float %Y) { 209; CHECK-LABEL: @f_ogt( 210; CHECK-NEXT: [[C:%.*]] = fcmp ogt float [[X:%.*]], [[Y:%.*]] 211; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !12 212; CHECK: T: 213; CHECK-NEXT: ret i32 12 214; CHECK: F: 215; CHECK-NEXT: ret i32 123 216; 217 %C = fcmp ogt float %X, %Y 218 br i1 %C, label %T, label %F, !prof !12 219T: 220 ret i32 12 221F: 222 ret i32 123 223} 224 225define i32 @f_oge(float %X, float %Y) { 226; CHECK-LABEL: @f_oge( 227; CHECK-NEXT: [[C:%.*]] = fcmp ult float [[X:%.*]], [[Y:%.*]] 228; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !13 229; CHECK: T: 230; CHECK-NEXT: ret i32 12 231; CHECK: F: 232; CHECK-NEXT: ret i32 123 233; 234 %C = fcmp oge float %X, %Y 235 br i1 %C, label %T, label %F, !prof !13 236T: 237 ret i32 12 238F: 239 ret i32 123 240} 241 242define i32 @f_olt(float %X, float %Y) { 243; CHECK-LABEL: @f_olt( 244; CHECK-NEXT: [[C:%.*]] = fcmp olt float [[X:%.*]], [[Y:%.*]] 245; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !14 246; CHECK: T: 247; CHECK-NEXT: ret i32 12 248; CHECK: F: 249; CHECK-NEXT: ret i32 123 250; 251 %C = fcmp olt float %X, %Y 252 br i1 %C, label %T, label %F, !prof !14 253T: 254 ret i32 12 255F: 256 ret i32 123 257} 258 259define i32 @f_ole(float %X, float %Y) { 260; CHECK-LABEL: @f_ole( 261; CHECK-NEXT: [[C:%.*]] = fcmp ugt float [[X:%.*]], [[Y:%.*]] 262; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !15 263; CHECK: T: 264; CHECK-NEXT: ret i32 12 265; CHECK: F: 266; CHECK-NEXT: ret i32 123 267; 268 %C = fcmp ole float %X, %Y 269 br i1 %C, label %T, label %F, !prof !15 270T: 271 ret i32 12 272F: 273 ret i32 123 274} 275 276define i32 @f_one(float %X, float %Y) { 277; CHECK-LABEL: @f_one( 278; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[X:%.*]], [[Y:%.*]] 279; CHECK-NEXT: br i1 [[C]], label [[F:%.*]], label [[T:%.*]], !prof !16 280; CHECK: T: 281; CHECK-NEXT: ret i32 12 282; CHECK: F: 283; CHECK-NEXT: ret i32 123 284; 285 %C = fcmp one float %X, %Y 286 br i1 %C, label %T, label %F, !prof !16 287T: 288 ret i32 12 289F: 290 ret i32 123 291} 292 293define i32 @f_ord(float %X, float %Y) { 294; CHECK-LABEL: @f_ord( 295; CHECK-NEXT: [[C:%.*]] = fcmp ord float [[X:%.*]], [[Y:%.*]] 296; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !17 297; CHECK: T: 298; CHECK-NEXT: ret i32 12 299; CHECK: F: 300; CHECK-NEXT: ret i32 123 301; 302 %C = fcmp ord float %X, %Y 303 br i1 %C, label %T, label %F, !prof !17 304T: 305 ret i32 12 306F: 307 ret i32 123 308} 309 310define i32 @f_uno(float %X, float %Y) { 311; CHECK-LABEL: @f_uno( 312; CHECK-NEXT: [[C:%.*]] = fcmp uno float [[X:%.*]], [[Y:%.*]] 313; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !18 314; CHECK: T: 315; CHECK-NEXT: ret i32 12 316; CHECK: F: 317; CHECK-NEXT: ret i32 123 318; 319 %C = fcmp uno float %X, %Y 320 br i1 %C, label %T, label %F, !prof !18 321T: 322 ret i32 12 323F: 324 ret i32 123 325} 326 327define i32 @f_ueq(float %X, float %Y) { 328; CHECK-LABEL: @f_ueq( 329; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[X:%.*]], [[Y:%.*]] 330; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !19 331; CHECK: T: 332; CHECK-NEXT: ret i32 12 333; CHECK: F: 334; CHECK-NEXT: ret i32 123 335; 336 %C = fcmp ueq float %X, %Y 337 br i1 %C, label %T, label %F, !prof !19 338T: 339 ret i32 12 340F: 341 ret i32 123 342} 343 344define i32 @f_ugt(float %X, float %Y) { 345; CHECK-LABEL: @f_ugt( 346; CHECK-NEXT: [[C:%.*]] = fcmp ugt float [[X:%.*]], [[Y:%.*]] 347; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !20 348; CHECK: T: 349; CHECK-NEXT: ret i32 12 350; CHECK: F: 351; CHECK-NEXT: ret i32 123 352; 353 %C = fcmp ugt float %X, %Y 354 br i1 %C, label %T, label %F, !prof !20 355T: 356 ret i32 12 357F: 358 ret i32 123 359} 360 361define i32 @f_uge(float %X, float %Y) { 362; CHECK-LABEL: @f_uge( 363; CHECK-NEXT: [[C:%.*]] = fcmp uge float [[X:%.*]], [[Y:%.*]] 364; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !21 365; CHECK: T: 366; CHECK-NEXT: ret i32 12 367; CHECK: F: 368; CHECK-NEXT: ret i32 123 369; 370 %C = fcmp uge float %X, %Y 371 br i1 %C, label %T, label %F, !prof !21 372T: 373 ret i32 12 374F: 375 ret i32 123 376} 377 378define i32 @f_ult(float %X, float %Y) { 379; CHECK-LABEL: @f_ult( 380; CHECK-NEXT: [[C:%.*]] = fcmp ult float [[X:%.*]], [[Y:%.*]] 381; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !22 382; CHECK: T: 383; CHECK-NEXT: ret i32 12 384; CHECK: F: 385; CHECK-NEXT: ret i32 123 386; 387 %C = fcmp ult float %X, %Y 388 br i1 %C, label %T, label %F, !prof !22 389T: 390 ret i32 12 391F: 392 ret i32 123 393} 394 395define i32 @f_ule(float %X, float %Y) { 396; CHECK-LABEL: @f_ule( 397; CHECK-NEXT: [[C:%.*]] = fcmp ule float [[X:%.*]], [[Y:%.*]] 398; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !23 399; CHECK: T: 400; CHECK-NEXT: ret i32 12 401; CHECK: F: 402; CHECK-NEXT: ret i32 123 403; 404 %C = fcmp ule float %X, %Y 405 br i1 %C, label %T, label %F, !prof !23 406T: 407 ret i32 12 408F: 409 ret i32 123 410} 411 412define i32 @f_une(float %X, float %Y) { 413; CHECK-LABEL: @f_une( 414; CHECK-NEXT: [[C:%.*]] = fcmp une float [[X:%.*]], [[Y:%.*]] 415; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]], !prof !24 416; CHECK: T: 417; CHECK-NEXT: ret i32 12 418; CHECK: F: 419; CHECK-NEXT: ret i32 123 420; 421 %C = fcmp une float %X, %Y 422 br i1 %C, label %T, label %F, !prof !24 423T: 424 ret i32 12 425F: 426 ret i32 123 427} 428 429define i32 @f_true(float %X, float %Y) { 430; CHECK-LABEL: @f_true( 431; CHECK-NEXT: br i1 true, label [[T:%.*]], label [[F:%.*]], !prof !25 432; CHECK: T: 433; CHECK-NEXT: ret i32 12 434; CHECK: F: 435; CHECK-NEXT: ret i32 123 436; 437 %C = fcmp true float %X, %Y 438 br i1 %C, label %T, label %F, !prof !25 439T: 440 ret i32 12 441F: 442 ret i32 123 443} 444 445 446!0 = !{!"branch_weights", i32 0, i32 99} 447!1 = !{!"branch_weights", i32 1, i32 99} 448!2 = !{!"branch_weights", i32 2, i32 99} 449!3 = !{!"branch_weights", i32 3, i32 99} 450!4 = !{!"branch_weights", i32 4, i32 99} 451!5 = !{!"branch_weights", i32 5, i32 99} 452!6 = !{!"branch_weights", i32 6, i32 99} 453!7 = !{!"branch_weights", i32 7, i32 99} 454!8 = !{!"branch_weights", i32 8, i32 99} 455!9 = !{!"branch_weights", i32 9, i32 99} 456!10 = !{!"branch_weights", i32 10, i32 99} 457!11 = !{!"branch_weights", i32 11, i32 99} 458!12 = !{!"branch_weights", i32 12, i32 99} 459!13 = !{!"branch_weights", i32 13, i32 99} 460!14 = !{!"branch_weights", i32 14, i32 99} 461!15 = !{!"branch_weights", i32 15, i32 99} 462!16 = !{!"branch_weights", i32 16, i32 99} 463!17 = !{!"branch_weights", i32 17, i32 99} 464!18 = !{!"branch_weights", i32 18, i32 99} 465!19 = !{!"branch_weights", i32 19, i32 99} 466!20 = !{!"branch_weights", i32 20, i32 99} 467!21 = !{!"branch_weights", i32 21, i32 99} 468!22 = !{!"branch_weights", i32 22, i32 99} 469!23 = !{!"branch_weights", i32 23, i32 99} 470!24 = !{!"branch_weights", i32 24, i32 99} 471!25 = !{!"branch_weights", i32 25, i32 99} 472 473; Ensure that the branch metadata is reversed to match the reversals above. 474; CHECK: !0 = {{.*}} i32 0, i32 99} 475; CHECK: !1 = {{.*}} i32 99, i32 1} 476; CHECK: !2 = {{.*}} i32 2, i32 99} 477; CHECK: !3 = {{.*}} i32 99, i32 3} 478; CHECK: !4 = {{.*}} i32 4, i32 99} 479; CHECK: !5 = {{.*}} i32 99, i32 5} 480; CHECK: !6 = {{.*}} i32 6, i32 99} 481; CHECK: !7 = {{.*}} i32 99, i32 7} 482; CHECK: !8 = {{.*}} i32 8, i32 99} 483; CHECK: !9 = {{.*}} i32 99, i32 9} 484; CHECK: !10 = {{.*}} i32 10, i32 99} 485; CHECK: !11 = {{.*}} i32 11, i32 99} 486; CHECK: !12 = {{.*}} i32 12, i32 99} 487; CHECK: !13 = {{.*}} i32 99, i32 13} 488; CHECK: !14 = {{.*}} i32 14, i32 99} 489; CHECK: !15 = {{.*}} i32 99, i32 15} 490; CHECK: !16 = {{.*}} i32 99, i32 16} 491; CHECK: !17 = {{.*}} i32 17, i32 99} 492; CHECK: !18 = {{.*}} i32 18, i32 99} 493; CHECK: !19 = {{.*}} i32 19, i32 99} 494; CHECK: !20 = {{.*}} i32 20, i32 99} 495; CHECK: !21 = {{.*}} i32 21, i32 99} 496; CHECK: !22 = {{.*}} i32 22, i32 99} 497; CHECK: !23 = {{.*}} i32 23, i32 99} 498; CHECK: !24 = {{.*}} i32 24, i32 99} 499; CHECK: !25 = {{.*}} i32 25, i32 99} 500 501