• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -o - %s | FileCheck %s
3target triple = "x86_64-unknown-unknown"
4
5; select with and i1/or i1 condition should be implemented as a series of 2
6; cmovs, not by producing two conditions and using and on them.
7
8define i32 @select_and(i32 %a0, i32 %a1, float %a2, float %a3, i32 %a4, i32 %a5) {
9; CHECK-LABEL: select_and:
10; CHECK:       # %bb.0:
11; CHECK-NEXT:    movl %edx, %eax
12; CHECK-NEXT:    ucomiss %xmm0, %xmm1
13; CHECK-NEXT:    cmovbel %ecx, %eax
14; CHECK-NEXT:    cmpl %esi, %edi
15; CHECK-NEXT:    cmovael %ecx, %eax
16; CHECK-NEXT:    retq
17  %cmp0 = icmp ult i32 %a0, %a1
18  %cmp1 = fcmp olt float %a2, %a3
19  %and = and i1 %cmp0, %cmp1
20  %res = select i1 %and, i32 %a4, i32 %a5
21  ret i32 %res
22}
23
24; select with and i1 condition should be implemented as a series of 2 cmovs, not
25; by producing two conditions and using and on them.
26
27define i32 @select_or(i32 %a0, i32 %a1, float %a2, float %a3, i32 %a4, i32 %a5) {
28; CHECK-LABEL: select_or:
29; CHECK:       # %bb.0:
30; CHECK-NEXT:    movl %ecx, %eax
31; CHECK-NEXT:    ucomiss %xmm0, %xmm1
32; CHECK-NEXT:    cmoval %edx, %eax
33; CHECK-NEXT:    cmpl %esi, %edi
34; CHECK-NEXT:    cmovbl %edx, %eax
35; CHECK-NEXT:    retq
36  %cmp0 = icmp ult i32 %a0, %a1
37  %cmp1 = fcmp olt float %a2, %a3
38  %and = or i1 %cmp0, %cmp1
39  %res = select i1 %and, i32 %a4, i32 %a5
40  ret i32 %res
41}
42
43; If one of the conditions is materialized as a 0/1 value anyway, then the
44; sequence of 2 cmovs should not be used.
45
46@var32 = global i32 0
47define i32 @select_noopt(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {
48; CHECK-LABEL: select_noopt:
49; CHECK:       # %bb.0:
50; CHECK-NEXT:    movl %ecx, %eax
51; CHECK-NEXT:    cmpl %esi, %edi
52; CHECK-NEXT:    setb %cl
53; CHECK-NEXT:    cmpl %edx, %esi
54; CHECK-NEXT:    setb %dl
55; CHECK-NEXT:    orb %cl, %dl
56; CHECK-NEXT:    movzbl %dl, %ecx
57; CHECK-NEXT:    movl %ecx, {{.*}}(%rip)
58; CHECK-NEXT:    testb %cl, %cl
59; CHECK-NEXT:    cmovel %r8d, %eax
60; CHECK-NEXT:    retq
61  %cmp0 = icmp ult i32 %a0, %a1
62  %cmp1 = icmp ult i32 %a1, %a2
63  %or = or i1 %cmp0, %cmp1
64  %zero_one = zext i1 %or to i32
65  store volatile i32 %zero_one, i32* @var32
66  %res = select i1 %or, i32 %a3, i32 %a4
67  ret i32 %res
68}
69