aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/CodeGen/X86/pr160612.ll
blob: 6572c421b7fe6482f4b044a788101011163b37ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -O2 | FileCheck %s

; Test for issue #160612: OR conditions in branches should use multiple branches
; instead of materializing booleans with SETCC when no special optimizations apply.

declare void @subroutine_foo()
declare void @subroutine_bar()

; Original issue: (x == 0 || y == 0) was generating SETCC + TEST + BRANCH
; instead of using two conditional branches directly.
define void @func_a(i32 noundef %x, i32 noundef %y) {
; CHECK-LABEL: func_a:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    testl %edi, %edi
; CHECK-NEXT:    je subroutine_foo@PLT # TAILCALL
; CHECK-NEXT:  # %bb.1: # %entry
; CHECK-NEXT:    testl %esi, %esi
; CHECK-NEXT:    jne subroutine_bar@PLT # TAILCALL
; CHECK-NEXT:  # %bb.2: # %if.then
; CHECK-NEXT:    jmp subroutine_foo@PLT # TAILCALL
entry:
  %cmp = icmp eq i32 %x, 0
  %cmp1 = icmp eq i32 %y, 0
  %or.cond = or i1 %cmp, %cmp1
  br i1 %or.cond, label %if.then, label %if.else

if.then:
  tail call void @subroutine_foo()
  br label %if.end

if.else:
  tail call void @subroutine_bar()
  br label %if.end

if.end:
  ret void
}

; Reference implementation that already generated optimal code.
; This should continue to generate the same optimal code.
define void @func_b(i32 noundef %x, i32 noundef %y) {
; CHECK-LABEL: func_b:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    testl %edi, %edi
; CHECK-NEXT:    je subroutine_foo@PLT # TAILCALL
; CHECK-NEXT:  # %bb.1: # %if.else
; CHECK-NEXT:    testl %esi, %esi
; CHECK-NEXT:    je subroutine_foo@PLT # TAILCALL
; CHECK-NEXT:  # %bb.2: # %if.else3
; CHECK-NEXT:    jmp subroutine_bar@PLT # TAILCALL
entry:
  %cmp = icmp eq i32 %x, 0
  br i1 %cmp, label %if.then, label %if.else

if.then:
  tail call void @subroutine_foo()
  br label %if.end4

if.else:
  %cmp1 = icmp eq i32 %y, 0
  br i1 %cmp1, label %if.then2, label %if.else3

if.then2:
  tail call void @subroutine_foo()
  br label %if.end4

if.else3:
  tail call void @subroutine_bar()
  br label %if.end4

if.end4:
  ret void
}