• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3; These tests are for Integer BitWidth <= 64 && BitWidth % 2 != 0.
4define i23 @test1(i23 %A) {
5    ;; A | ~A == -1
6    %NotA = xor i23 -1, %A
7    %B = or i23 %A, %NotA
8    ret i23 %B
9; CHECK-LABEL: @test1
10; CHECK-NEXT: ret i23 -1
11}
12
13define i39 @test2(i39 %V, i39 %M) {
14    ;; If we have: ((V + N) & C1) | (V & C2)
15    ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
16    ;; replace with V+N.
17    %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
18    %N = and i39 %M, 274877906944
19    %A = add i39 %V, %N
20    %B = and i39 %A, %C1
21    %D = and i39 %V, 274877906943
22    %R = or i39 %B, %D
23    ret i39 %R
24; CHECK-LABEL: @test2
25; CHECK-NEXT: %N = and i39 %M, -274877906944
26; CHECK-NEXT: %A = add i39 %N, %V
27; CHECK-NEXT: ret i39 %A
28}
29
30define i43 @test3(i43 %A, i43 %B) {
31    ;; (~A | ~B) == (~(A & B)) - De Morgan's Law
32    %NotA = xor i43 %A, -1
33    %NotB = xor i43 %B, -1
34    %C1 = or i43 %NotA, %NotB
35    ret i43 %C1
36; CHECK-LABEL: @test3
37; CHECK-NEXT: %C1.demorgan = and i43 %A, %B
38; CHECK-NEXT: %C1 = xor i43 %C1.demorgan, -1
39; CHECK-NEXT: ret i43 %C1
40}
41
42; These tests are for Integer BitWidth > 64 && BitWidth <= 1024.
43define i1023 @test4(i1023 %A) {
44    ;; A | ~A == -1
45    %NotA = xor i1023 -1, %A
46    %B = or i1023 %A, %NotA
47    ret i1023 %B
48; CHECK-LABEL: @test4
49; CHECK-NEXT: ret i1023 -1
50}
51
52define i399 @test5(i399 %V, i399 %M) {
53    ;; If we have: ((V + N) & C1) | (V & C2)
54    ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
55    ;; replace with V+N.
56    %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
57    %N = and i399 %M, 18446742974197923840
58    %A = add i399 %V, %N
59    %B = and i399 %A, %C1
60    %D = and i399 %V, 274877906943
61    %R = or i399 %B, %D
62    ret i399 %R
63; CHECK-LABEL: @test5
64; CHECK-NEXT: %N = and i399 %M, 18446742974197923840
65; CHECK-NEXT: %A = add i399 %N, %V
66; CHECK-NEXT: ret i399 %A
67}
68
69define i129 @test6(i129 %A, i129 %B) {
70    ;; (~A | ~B) == (~(A & B)) - De Morgan's Law
71    %NotA = xor i129 %A, -1
72    %NotB = xor i129 %B, -1
73    %C1 = or i129 %NotA, %NotB
74    ret i129 %C1
75; CHECK-LABEL: @test6
76; CHECK-NEXT: %C1.demorgan = and i129 %A, %B
77; CHECK-NEXT: %C1 = xor i129 %C1.demorgan, -1
78; CHECK-NEXT: ret i129 %C1
79}
80