blob: e3dc2c48fb40b775f3fa7bb971b7acd07e49fa2e [file] [log] [blame]
Sanjay Patel69632442016-03-25 20:12:25 +00001; NOTE: Assertions have been autogenerated by update_test_checks.py
Benjamin Kramerc3c18352015-09-08 18:36:56 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
Nick Lewycky8561a492014-06-19 03:51:46 +00003
4; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
5define i39 @test1(i39 %V, i39 %M) {
Sanjay Patel69632442016-03-25 20:12:25 +00006; CHECK-LABEL: @test1(
7; CHECK: [[N:%.*]] = and i39 %M, -274877906944
8; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]]
9; CHECK-NEXT: ret i39 [[A]]
10;
Nick Lewycky8561a492014-06-19 03:51:46 +000011 ;; If we have: ((V + N) & C1) | (V & C2)
12 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
13 ;; replace with V+N.
14 %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
15 %N = and i39 %M, 274877906944
16 %A = add i39 %V, %N
17 %B = and i39 %A, %C1
18 %D = and i39 %V, 274877906943
19 %R = or i39 %B, %D
20 ret i39 %R
Nick Lewycky8561a492014-06-19 03:51:46 +000021}
22
Benjamin Kramerc3c18352015-09-08 18:36:56 +000023define i7 @test2(i7 %X) {
Sanjay Patel69632442016-03-25 20:12:25 +000024; CHECK-LABEL: @test2(
25; CHECK: ret i7 %X
26;
Benjamin Kramerc3c18352015-09-08 18:36:56 +000027 %Y = or i7 %X, 0
28 ret i7 %Y
Benjamin Kramerc3c18352015-09-08 18:36:56 +000029}
30
31define i17 @test3(i17 %X) {
Sanjay Patel69632442016-03-25 20:12:25 +000032; CHECK-LABEL: @test3(
33; CHECK: ret i17 -1
34;
Benjamin Kramerc3c18352015-09-08 18:36:56 +000035 %Y = or i17 %X, -1
36 ret i17 %Y
Benjamin Kramerc3c18352015-09-08 18:36:56 +000037}
38
Sanjay Patel69632442016-03-25 20:12:25 +000039; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
Benjamin Kramerc3c18352015-09-08 18:36:56 +000040define i399 @test4(i399 %V, i399 %M) {
Sanjay Patel69632442016-03-25 20:12:25 +000041; CHECK-LABEL: @test4(
42; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840
43; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]]
44; CHECK-NEXT: ret i399 [[A]]
45;
Nick Lewycky8561a492014-06-19 03:51:46 +000046 ;; If we have: ((V + N) & C1) | (V & C2)
47 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
48 ;; replace with V+N.
49 %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
50 %N = and i399 %M, 18446742974197923840
51 %A = add i399 %V, %N
52 %B = and i399 %A, %C1
53 %D = and i399 %V, 274877906943
54 %R = or i399 %B, %D
55 ret i399 %R
Nick Lewycky8561a492014-06-19 03:51:46 +000056}
Benjamin Kramerc3c18352015-09-08 18:36:56 +000057
58define i777 @test5(i777 %X) {
Sanjay Patel69632442016-03-25 20:12:25 +000059; CHECK-LABEL: @test5(
60; CHECK: ret i777 %X
61;
Benjamin Kramerc3c18352015-09-08 18:36:56 +000062 %Y = or i777 %X, 0
63 ret i777 %Y
Benjamin Kramerc3c18352015-09-08 18:36:56 +000064}
65
66define i117 @test6(i117 %X) {
Sanjay Patel69632442016-03-25 20:12:25 +000067; CHECK-LABEL: @test6(
68; CHECK: ret i117 -1
69;
Benjamin Kramerc3c18352015-09-08 18:36:56 +000070 %Y = or i117 %X, -1
71 ret i117 %Y
Benjamin Kramerc3c18352015-09-08 18:36:56 +000072}