1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
4 ; cmp with single-use load, should not form branch.
5 define i32 @test1(double %a, double* nocapture %b, i32 %x, i32 %y) {
8 ; CHECK-NEXT: movl %esi, %eax
9 ; CHECK-NEXT: ucomisd (%rdi), %xmm0
10 ; CHECK-NEXT: cmovbel %edx, %eax
12 %load = load double, double* %b, align 8
13 %cmp = fcmp olt double %load, %a
14 %cond = select i1 %cmp, i32 %x, i32 %y
18 ; Sanity check: no load.
19 define i32 @test2(double %a, double %b, i32 %x, i32 %y) {
22 ; CHECK-NEXT: movl %edi, %eax
23 ; CHECK-NEXT: ucomisd %xmm1, %xmm0
24 ; CHECK-NEXT: cmovbel %esi, %eax
26 %cmp = fcmp ogt double %a, %b
27 %cond = select i1 %cmp, i32 %x, i32 %y
31 ; Multiple uses of the load.
32 define i32 @test4(i32 %a, i32* nocapture %b, i32 %x, i32 %y) {
35 ; CHECK-NEXT: movl (%rsi), %eax
36 ; CHECK-NEXT: cmpl %edi, %eax
37 ; CHECK-NEXT: cmovael %ecx, %edx
38 ; CHECK-NEXT: addl %edx, %eax
40 %load = load i32, i32* %b, align 4
41 %cmp = icmp ult i32 %load, %a
42 %cond = select i1 %cmp, i32 %x, i32 %y
43 %add = add i32 %cond, %load
47 ; Multiple uses of the cmp.
48 define i32 @test5(i32 %a, i32* nocapture %b, i32 %x, i32 %y) {
51 ; CHECK-NEXT: movl %ecx, %eax
52 ; CHECK-NEXT: cmpl %edi, (%rsi)
53 ; CHECK-NEXT: cmoval %edi, %eax
54 ; CHECK-NEXT: cmovael %edx, %eax
56 %load = load i32, i32* %b, align 4
57 %cmp = icmp ult i32 %load, %a
58 %cmp1 = icmp ugt i32 %load, %a
59 %cond = select i1 %cmp1, i32 %a, i32 %y
60 %cond5 = select i1 %cmp, i32 %cond, i32 %x
64 ; Zero-extended select.
65 define void @test6(i32 %a, i32 %x, i32* %y.ptr, i64* %z.ptr) {
67 ; CHECK: # %bb.0: # %entry
68 ; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
69 ; CHECK-NEXT: testl %edi, %edi
70 ; CHECK-NEXT: cmovnsl (%rdx), %esi
71 ; CHECK-NEXT: movq %rsi, (%rcx)
74 %y = load i32, i32* %y.ptr
75 %cmp = icmp slt i32 %a, 0
76 %z = select i1 %cmp, i32 %x, i32 %y
77 %z.ext = zext i32 %z to i64
78 store i64 %z.ext, i64* %z.ptr
82 ; If a select is not obviously predictable, don't turn it into a branch.
83 define i32 @weighted_select1(i32 %a, i32 %b) {
84 ; CHECK-LABEL: weighted_select1:
86 ; CHECK-NEXT: movl %esi, %eax
87 ; CHECK-NEXT: testl %edi, %edi
88 ; CHECK-NEXT: cmovnel %edi, %eax
90 %cmp = icmp ne i32 %a, 0
91 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !0
95 ; If a select is obviously predictable, turn it into a branch.
96 define i32 @weighted_select2(i32 %a, i32 %b) {
97 ; CHECK-LABEL: weighted_select2:
99 ; CHECK-NEXT: movl %edi, %eax
100 ; CHECK-NEXT: testl %edi, %edi
101 ; CHECK-NEXT: jne .LBB6_2
102 ; CHECK-NEXT: # %bb.1: # %select.false
103 ; CHECK-NEXT: movl %esi, %eax
104 ; CHECK-NEXT: .LBB6_2: # %select.end
106 %cmp = icmp ne i32 %a, 0
107 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !1
111 ; Note the reversed profile weights: it doesn't matter if it's
112 ; obviously true or obviously false.
113 ; Either one should become a branch rather than conditional move.
114 ; TODO: But likely true vs. likely false should affect basic block placement?
115 define i32 @weighted_select3(i32 %a, i32 %b) {
116 ; CHECK-LABEL: weighted_select3:
118 ; CHECK-NEXT: movl %edi, %eax
119 ; CHECK-NEXT: testl %edi, %edi
120 ; CHECK-NEXT: je .LBB7_1
121 ; CHECK-NEXT: # %bb.2: # %select.end
123 ; CHECK-NEXT: .LBB7_1: # %select.false
124 ; CHECK-NEXT: movl %esi, %eax
126 %cmp = icmp ne i32 %a, 0
127 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !2
131 ; Weightlessness is no reason to die.
132 define i32 @unweighted_select(i32 %a, i32 %b) {
133 ; CHECK-LABEL: unweighted_select:
135 ; CHECK-NEXT: movl %esi, %eax
136 ; CHECK-NEXT: testl %edi, %edi
137 ; CHECK-NEXT: cmovnel %edi, %eax
139 %cmp = icmp ne i32 %a, 0
140 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !3
144 !0 = !{!"branch_weights", i32 1, i32 99}
145 !1 = !{!"branch_weights", i32 1, i32 100}
146 !2 = !{!"branch_weights", i32 100, i32 1}
147 !3 = !{!"branch_weights", i32 0, i32 0}