blob: 36844289aaf0bf3bb30a40375e68d5bad360015a [file] [log] [blame]
Benjamin Kramerc3c18352015-09-08 18:36:56 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
Nick Lewycky8561a492014-06-19 03:51:46 +00002
3; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
4define i39 @test1(i39 %V, i39 %M) {
5 ;; If we have: ((V + N) & C1) | (V & C2)
6 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
7 ;; replace with V+N.
8 %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
9 %N = and i39 %M, 274877906944
10 %A = add i39 %V, %N
11 %B = and i39 %A, %C1
12 %D = and i39 %V, 274877906943
13 %R = or i39 %B, %D
14 ret i39 %R
Jonathan Roelofs49e46ce2015-08-10 19:01:27 +000015; CHECK-LABEL: @test1
Nick Lewycky8561a492014-06-19 03:51:46 +000016; CHECK-NEXT: and {{.*}}, -274877906944
17; CHECK-NEXT: add
18; CHECK-NEXT: ret
19}
20
Benjamin Kramerc3c18352015-09-08 18:36:56 +000021define i7 @test2(i7 %X) {
22 %Y = or i7 %X, 0
23 ret i7 %Y
24; CHECK-LABEL: @test2
25; CHECK-NEXT: ret i7 %X
26}
27
28define i17 @test3(i17 %X) {
29 %Y = or i17 %X, -1
30 ret i17 %Y
31; CHECK-LABEL: @test3
32; CHECK-NEXT: ret i17 -1
33}
34
Nick Lewycky8561a492014-06-19 03:51:46 +000035; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
Benjamin Kramerc3c18352015-09-08 18:36:56 +000036define i399 @test4(i399 %V, i399 %M) {
Nick Lewycky8561a492014-06-19 03:51:46 +000037 ;; If we have: ((V + N) & C1) | (V & C2)
38 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
39 ;; replace with V+N.
40 %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
41 %N = and i399 %M, 18446742974197923840
42 %A = add i399 %V, %N
43 %B = and i399 %A, %C1
44 %D = and i399 %V, 274877906943
45 %R = or i399 %B, %D
46 ret i399 %R
Benjamin Kramerc3c18352015-09-08 18:36:56 +000047; CHECK-LABEL: @test4
Nick Lewycky8561a492014-06-19 03:51:46 +000048; CHECK-NEXT: and {{.*}}, 18446742974197923840
49; CHECK-NEXT: add
50; CHECK-NEXT: ret
51}
Benjamin Kramerc3c18352015-09-08 18:36:56 +000052
53define i777 @test5(i777 %X) {
54 %Y = or i777 %X, 0
55 ret i777 %Y
56; CHECK-LABEL: @test5
57; CHECK-NEXT: ret i777 %X
58}
59
60define i117 @test6(i117 %X) {
61 %Y = or i117 %X, -1
62 ret i117 %Y
63; CHECK-LABEL: @test6
64; CHECK-NEXT: ret i117 -1
65}