xref: /llvm-project/llvm/test/CodeGen/X86/cmp-merge.ll (revision 03de1cb715c9a106f3ea4139042a33afcd7ca6ae)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=i686--| FileCheck %s --check-prefixes=X86
3; RUN: llc < %s -mtriple=x86_64--| FileCheck %s --check-prefixes=X64
4
5;
6; PR35202
7;
8
9declare void @on_less()
10declare void @on_equal()
11declare void @on_greater()
12
13define void @eq_first(i32 %0, i32 %1) {
14; X86-LABEL: eq_first:
15; X86:       # %bb.0:
16; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
17; X86-NEXT:    cmpl %eax, {{[0-9]+}}(%esp)
18; X86-NEXT:    jl on_less@PLT # TAILCALL
19; X86-NEXT:  # %bb.1:
20; X86-NEXT:    je on_equal@PLT # TAILCALL
21; X86-NEXT:  # %bb.2:
22; X86-NEXT:    jmp on_greater@PLT # TAILCALL
23;
24; X64-LABEL: eq_first:
25; X64:       # %bb.0:
26; X64-NEXT:    cmpl %esi, %edi
27; X64-NEXT:    jl on_less@PLT # TAILCALL
28; X64-NEXT:  # %bb.1:
29; X64-NEXT:    je on_equal@PLT # TAILCALL
30; X64-NEXT:  # %bb.2:
31; X64-NEXT:    jmp on_greater@PLT # TAILCALL
32  %3 = icmp slt i32 %0, %1
33  br i1 %3, label %4, label %5
344:
35  tail call void @on_less()
36  br label %9
375:
38  %6 = icmp eq i32 %0, %1
39  br i1 %6, label %7, label %8
407:
41  tail call void @on_equal()
42  br label %9
438:
44  tail call void @on_greater()
45  br label %9
469:
47  ret void
48}
49
50define void @gt_first(i32 %0, i32 %1) {
51; X86-LABEL: gt_first:
52; X86:       # %bb.0:
53; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
54; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
55; X86-NEXT:    cmpl %eax, %ecx
56; X86-NEXT:    jl on_less@PLT # TAILCALL
57; X86-NEXT:  # %bb.1:
58; X86-NEXT:    jg on_greater@PLT # TAILCALL
59; X86-NEXT:  # %bb.2:
60; X86-NEXT:    jmp on_equal@PLT # TAILCALL
61;
62; X64-LABEL: gt_first:
63; X64:       # %bb.0:
64; X64-NEXT:    cmpl %esi, %edi
65; X64-NEXT:    jl on_less@PLT # TAILCALL
66; X64-NEXT:  # %bb.1:
67; X64-NEXT:    jg on_greater@PLT # TAILCALL
68; X64-NEXT:  # %bb.2:
69; X64-NEXT:    jmp on_equal@PLT # TAILCALL
70  %3 = icmp slt i32 %0, %1
71  br i1 %3, label %4, label %5
724:
73  tail call void @on_less()
74  br label %9
755:
76  %6 = icmp slt i32 %1, %0
77  br i1 %6, label %7, label %8
787:
79  tail call void @on_greater()
80  br label %9
818:
82  tail call void @on_equal()
83  br label %9
849:
85  ret void
86}
87
88define void @cmp_sub_same_order(i32 %x, i32 %y, ptr %p) {
89; X86-LABEL: cmp_sub_same_order:
90; X86:       # %bb.0: # %entry
91; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
92; X86-NEXT:    subl {{[0-9]+}}(%esp), %eax
93; X86-NEXT:    jge .LBB2_2
94; X86-NEXT:  # %bb.1: # %cond.true
95; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
96; X86-NEXT:    movl %eax, (%ecx)
97; X86-NEXT:  .LBB2_2: # %cond.end
98; X86-NEXT:    retl
99;
100; X64-LABEL: cmp_sub_same_order:
101; X64:       # %bb.0: # %entry
102; X64-NEXT:    subl %esi, %edi
103; X64-NEXT:    jge .LBB2_2
104; X64-NEXT:  # %bb.1: # %cond.true
105; X64-NEXT:    movl %edi, (%rdx)
106; X64-NEXT:  .LBB2_2: # %cond.end
107; X64-NEXT:    retq
108entry:
109  %cmp = icmp slt i32 %x, %y
110  br i1 %cmp, label %cond.true, label %cond.end
111
112cond.true:
113  %sub = sub nsw i32 %x, %y
114  store i32 %sub, ptr %p
115  br label %cond.end
116
117cond.end:
118  ret void
119}
120
121define void @cmp_sub_different_order(i32 %x, i32 %y, ptr %p) {
122; X86-LABEL: cmp_sub_different_order:
123; X86:       # %bb.0: # %entry
124; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
125; X86-NEXT:    subl {{[0-9]+}}(%esp), %eax
126; X86-NEXT:    jge .LBB3_2
127; X86-NEXT:  # %bb.1: # %cond.true
128; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
129; X86-NEXT:    movl %eax, (%ecx)
130; X86-NEXT:  .LBB3_2: # %cond.end
131; X86-NEXT:    retl
132;
133; X64-LABEL: cmp_sub_different_order:
134; X64:       # %bb.0: # %entry
135; X64-NEXT:    subl %esi, %edi
136; X64-NEXT:    jge .LBB3_2
137; X64-NEXT:  # %bb.1: # %cond.true
138; X64-NEXT:    movl %edi, (%rdx)
139; X64-NEXT:  .LBB3_2: # %cond.end
140; X64-NEXT:    retq
141entry:
142  %cmp = icmp sgt i32 %y, %x
143  br i1 %cmp, label %cond.true, label %cond.end
144
145cond.true:
146  %sub = sub nsw i32 %x, %y
147  store i32 %sub, ptr %p
148  br label %cond.end
149
150cond.end:
151  ret void
152}
153
154declare void @use(i32)
155