1 ; RUN: opt < %s -instcombine -S | FileCheck %s 2 3 ; Test an already canonical branch to make sure we don't flip those. 4 define i32 @test0(i32 %X, i32 %Y) { 5 %C = icmp eq i32 %X, %Y 6 br i1 %C, label %T, label %F, !prof !0 7 8 ; CHECK: @test0 9 ; CHECK: %C = icmp eq i32 %X, %Y 10 ; CHECK: br i1 %C, label %T, label %F 11 12 T: 13 ret i32 12 14 F: 15 ret i32 123 16 } 17 18 define i32 @test1(i32 %X, i32 %Y) { 19 %C = icmp ne i32 %X, %Y 20 br i1 %C, label %T, label %F, !prof !1 21 22 ; CHECK: @test1 23 ; CHECK: %C = icmp eq i32 %X, %Y 24 ; CHECK: br i1 %C, label %F, label %T 25 26 T: 27 ret i32 12 28 F: 29 ret i32 123 30 } 31 32 define i32 @test2(i32 %X, i32 %Y) { 33 %C = icmp ule i32 %X, %Y 34 br i1 %C, label %T, label %F, !prof !2 35 36 ; CHECK: @test2 37 ; CHECK: %C = icmp ugt i32 %X, %Y 38 ; CHECK: br i1 %C, label %F, label %T 39 40 T: 41 ret i32 12 42 F: 43 ret i32 123 44 } 45 46 define i32 @test3(i32 %X, i32 %Y) { 47 %C = icmp uge i32 %X, %Y 48 br i1 %C, label %T, label %F, !prof !3 49 50 ; CHECK: @test3 51 ; CHECK: %C = icmp ult i32 %X, %Y 52 ; CHECK: br i1 %C, label %F, label %T 53 54 T: 55 ret i32 12 56 F: 57 ret i32 123 58 } 59 60 !0 = metadata !{metadata !"branch_weights", i32 1, i32 2} 61 !1 = metadata !{metadata !"branch_weights", i32 3, i32 4} 62 !2 = metadata !{metadata !"branch_weights", i32 5, i32 6} 63 !3 = metadata !{metadata !"branch_weights", i32 7, i32 8} 64 ; Base case shouldn't change. 65 ; CHECK: !0 = {{.*}} i32 1, i32 2} 66 ; Ensure that the branch metadata is reversed to match the reversals above. 67 ; CHECK: !1 = {{.*}} i32 4, i32 3} 68 ; CHECK: !2 = {{.*}} i32 6, i32 5} 69 ; CHECK: !3 = {{.*}} i32 8, i32 7} 70