aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/InstCombine/fold-a-or-b-zero.ll
blob: 66a7eb7314ffa47a70042add95123d6af3604f4b (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -S -passes=instcombine | FileCheck %s

declare void @use(i1)

define i1 @a_or_b(i32 %a, i32 %b)  {
; CHECK-LABEL: define i1 @a_or_b(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[TMP1]], [[TMP2]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_zero = icmp eq i32 %a, 0
  %b_ne_zero = icmp ne i32 %b, 0
  %and.1 = and i1 %a_eq_zero, %b_ne_zero
  %a_ne_zero = icmp ne i32 %a, 0
  %b_eq_zero = icmp eq i32 %b, 0
  %and.2 = and i1 %a_ne_zero, %b_eq_zero
  %or = or i1 %and.1, %and.2
  ret i1 %or
}

define i1 @a_or_b_not_inv(i32 %a, i32 %b){
; CHECK-LABEL: define i1 @a_or_b_not_inv(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
; CHECK-NEXT:    [[A_EQ_ZERO:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT:    [[B_NE_ZERO:%.*]] = icmp ne i32 [[B]], 0
; CHECK-NEXT:    [[AND_1:%.*]] = and i1 [[A_EQ_ZERO]], [[B_NE_ZERO]]
; CHECK-NEXT:    [[A_NE_ZERO:%.*]] = icmp ne i32 [[A]], 0
; CHECK-NEXT:    [[B_EQ_1:%.*]] = icmp eq i32 [[B]], 1
; CHECK-NEXT:    [[AND_2:%.*]] = and i1 [[A_NE_ZERO]], [[B_EQ_1]]
; CHECK-NEXT:    [[OR:%.*]] = or i1 [[AND_1]], [[AND_2]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_zero = icmp eq i32 %a, 0
  %b_ne_zero = icmp ne i32 %b, 0
  %and.1 = and i1 %a_eq_zero, %b_ne_zero
  %a_ne_zero = icmp ne i32 %a, 0
  %b_eq_1 = icmp eq i32 %b, 1
  %and.2 = and i1 %a_ne_zero, %b_eq_1
  %or = or i1 %and.1, %and.2
  ret i1 %or
}

define i1 @a_or_b_const(i32 %a, i32 %b, i32 %c)  {
; CHECK-LABEL: define i1 @a_or_b_const(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) {
; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[A]], [[C]]
; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[B]], [[C]]
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[TMP1]], [[TMP2]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_c = icmp eq i32 %a, %c
  %b_ne_c = icmp ne i32 %b, %c
  %and.1 = and i1 %a_eq_c, %b_ne_c
  %a_ne_c = icmp ne i32 %a, %c
  %b_eq_c = icmp eq i32 %b, %c
  %and.2 = and i1 %a_ne_c, %b_eq_c
  %or = or i1 %and.1, %and.2
  ret i1 %or
}

define i1 @a_or_b_const2(i32 %a, i32 %b, i32 %c, i32 %d)  {
; CHECK-LABEL: define i1 @a_or_b_const2(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]], i32 [[D:%.*]]) {
; CHECK-NEXT:    [[A_EQ_C:%.*]] = icmp eq i32 [[A]], [[C]]
; CHECK-NEXT:    [[B_EQ_D:%.*]] = icmp eq i32 [[B]], [[D]]
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[A_EQ_C]], [[B_EQ_D]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_c = icmp eq i32 %a, %c
  %b_ne_d = icmp ne i32 %b, %d
  %and.1 = and i1 %a_eq_c, %b_ne_d
  %a_ne_c = icmp ne i32 %a, %c
  %b_eq_d = icmp eq i32 %b, %d
  %and.2 = and i1 %a_ne_c, %b_eq_d
  %or = or i1 %and.1, %and.2
  ret i1 %or
}
define i1 @a_or_b_nullptr(ptr %a, ptr %b) {
; CHECK-LABEL: define i1 @a_or_b_nullptr(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) {
; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq ptr [[A]], null
; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq ptr [[B]], null
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[TMP1]], [[TMP2]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_null = icmp eq ptr %a, null
  %b_null = icmp eq ptr %b, null
  %a_not_null = icmp ne ptr %a, null
  %b_not_null = icmp ne ptr %b, null
  %and.1 = and i1 %a_null, %b_not_null
  %and.2 = and i1 %a_not_null, %b_null
  %or = or i1 %and.1, %and.2
  ret i1 %or
}

define i1 @a_or_b_multiple_uses(i32 %a, i32 %b)  {
; CHECK-LABEL: define i1 @a_or_b_multiple_uses(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT:    [[A_NE_ZERO:%.*]] = icmp ne i32 [[A]], 0
; CHECK-NEXT:    [[B_EQ_ZERO:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT:    [[AND_2:%.*]] = and i1 [[A_NE_ZERO]], [[B_EQ_ZERO]]
; CHECK-NEXT:    call void @use(i1 [[AND_2]])
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[TMP1]], [[B_EQ_ZERO]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_zero = icmp eq i32 %a, 0
  %b_ne_zero = icmp ne i32 %b, 0
  %and.1 = and i1 %a_eq_zero, %b_ne_zero
  %a_ne_zero = icmp ne i32 %a, 0
  %b_eq_zero = icmp eq i32 %b, 0
  %and.2 = and i1 %a_ne_zero, %b_eq_zero
  call void @use(i1 %and.2)
  %or = or i1 %and.1, %and.2
  ret i1 %or
}

define i1 @a_or_b_multiple_uses_2(i32 %a, i32 %b)  {
; CHECK-LABEL: define i1 @a_or_b_multiple_uses_2(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
; CHECK-NEXT:    [[A_EQ_ZERO:%.*]] = icmp eq i32 [[A]], 0
; CHECK-NEXT:    [[B_NE_ZERO:%.*]] = icmp ne i32 [[B]], 0
; CHECK-NEXT:    call void @use(i1 [[B_NE_ZERO]])
; CHECK-NEXT:    [[AND_1:%.*]] = and i1 [[A_EQ_ZERO]], [[B_NE_ZERO]]
; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT:    call void @use(i1 [[AND_1]])
; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[A_EQ_ZERO]], [[TMP1]]
; CHECK-NEXT:    ret i1 [[OR]]
;
  %a_eq_zero = icmp eq i32 %a, 0
  %b_ne_zero = icmp ne i32 %b, 0
  call void @use(i1 %b_ne_zero)
  %and.1 = and i1 %a_eq_zero, %b_ne_zero
  %a_ne_zero = icmp ne i32 %a, 0
  %b_eq_zero = icmp eq i32 %b, 0
  %and.2 = and i1 %a_ne_zero, %b_eq_zero
  call void @use(i1 %and.1)
  %or = or i1 %and.1, %and.2
  ret i1 %or
}