File: xor-of-or.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (164 lines) | stat: -rw-r--r-- 5,022 bytes parent folder | download | duplicates (4)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -instcombine-infinite-loop-threshold=2 -S | FileCheck %s

; Don't do anything for the fully-variable case.
define i4 @t0(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: @t0(
; CHECK-NEXT:    [[I0:%.*]] = or i4 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[I0]], [[Z:%.*]]
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, %y
  %i1 = xor i4 %i0, %z
  ret i4 %i1
}

; If the second operands are immediate constants, we can perform the fold.
define i4 @t1(i4 %x) {
; CHECK-LABEL: @t1(
; CHECK-NEXT:    [[TMP1:%.*]] = and i4 [[X:%.*]], 3
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[TMP1]], 6
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, 12   ; 0b1100
  %i1 = xor i4 %i0, 10 ; 0b1010
  ret i4 %i1
}

; Must not have extra uses.
define i4 @t2(i4 %x) {
; CHECK-LABEL: @t2(
; CHECK-NEXT:    [[I0:%.*]] = or i4 [[X:%.*]], -4
; CHECK-NEXT:    call void @use(i4 [[I0]])
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[I0]], -6
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, 12   ; 0b1100
  call void @use(i4 %i0)
  %i1 = xor i4 %i0, 10 ; 0b1010
  ret i4 %i1
}

; Splat constants are fine too.
define <2 x i4> @t3(<2 x i4> %x) {
; CHECK-LABEL: @t3(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 3>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 6>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 12>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 10>
  ret <2 x i4> %i1
}

; Non-splat constants are fine too.
define <2 x i4> @t4(<2 x i4> %x) {
; CHECK-LABEL: @t4(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 5>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 6>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 10>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 12>
  ret <2 x i4> %i1
}

; Partially-undef constants are fine.
define <2 x i4> @t5(<2 x i4> %x) {
; CHECK-LABEL: @t5(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 undef>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 undef>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 12>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 undef>
  ret <2 x i4> %i1
}
define <2 x i4> @t6(<2 x i4> %x) {
; CHECK-LABEL: @t6(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 0>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 5>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 undef>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 10>
  ret <2 x i4> %i1
}
define <2 x i4> @t7(<2 x i4> %x) {
; CHECK-LABEL: @t7(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 undef>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 undef>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 undef>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 undef>
  ret <2 x i4> %i1
}

; Partially-poison constants are fine.
define <2 x i4> @t8(<2 x i4> %x) {
; CHECK-LABEL: @t8(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 undef>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 poison>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 12>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 poison>
  ret <2 x i4> %i1
}
define <2 x i4> @t9(<2 x i4> %x) {
; CHECK-LABEL: @t9(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 0>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 5>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 poison>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 10>
  ret <2 x i4> %i1
}
define <2 x i4> @t10(<2 x i4> %x) {
; CHECK-LABEL: @t10(
; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], <i4 3, i4 undef>
; CHECK-NEXT:    [[I1:%.*]] = xor <2 x i4> [[TMP1]], <i4 6, i4 poison>
; CHECK-NEXT:    ret <2 x i4> [[I1]]
;
  %i0 = or <2 x i4> %x, <i4 12, i4 poison>
  %i1 = xor <2 x i4> %i0,  <i4 10, i4 poison>
  ret <2 x i4> %i1
}

; Do not deal with general constant expressions.
@G = external global i32
@G2 = external global i32
define i4 @t11(i4 %x) {
; CHECK-LABEL: @t11(
; CHECK-NEXT:    [[I0:%.*]] = or i4 [[X:%.*]], -4
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[I0]], ptrtoint (ptr @G2 to i4)
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, 12
  %i1 = xor i4 %i0, ptrtoint (ptr @G2 to i4)
  ret i4 %i1
}
define i4 @t12(i4 %x) {
; CHECK-LABEL: @t12(
; CHECK-NEXT:    [[I0:%.*]] = or i4 [[X:%.*]], ptrtoint (ptr @G to i4)
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[I0]], -6
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, ptrtoint (ptr @G to i4)
  %i1 = xor i4 %i0, 10
  ret i4 %i1
}
define i4 @t13(i4 %x) {
; CHECK-LABEL: @t13(
; CHECK-NEXT:    [[I0:%.*]] = or i4 [[X:%.*]], ptrtoint (ptr @G to i4)
; CHECK-NEXT:    [[I1:%.*]] = xor i4 [[I0]], ptrtoint (ptr @G2 to i4)
; CHECK-NEXT:    ret i4 [[I1]]
;
  %i0 = or i4 %x, ptrtoint (ptr @G to i4)
  %i1 = xor i4 %i0, ptrtoint (ptr @G2 to i4)
  ret i4 %i1
}

declare void @use(i4)