Skip to content

Commit 4fbe1a0

Browse files
author
Jan Voung
committed
Add a llvm lit test for NaCl ARM/X86 support for bswap i16, i32, i64.
Slowly trying to promote "dev" intrinsics that are being tested to be accepted. Luckily, bswap is supported without compiler_rt for ARM and x86 at least. Test at default level and -O0. Also tested by gcc/testsuite/gcc.dg/builtin-bswap-[1,2,3,4,5].c, and a couple of other gcc tests. We may want to blacklist odd argument sizes like i8, and i1, which the x86 backend won't handle. The i16 case is also interesting, however, it's easy to do if you have an i32 bswap. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3378 [email protected] Review URL: https://codereview.chromium.org/14971004
1 parent 0e6d484 commit 4fbe1a0

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

test/NaCl/ARM/intrinsics-bitmanip.ll

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; RUN: llc -mtriple=armv7-unknown-nacl -filetype=asm %s -o - | FileCheck %s
2+
; RUN: llc -mtriple=armv7-unknown-nacl -O0 -filetype=asm %s -o - | FileCheck %s
3+
4+
; Test that various bit manipulation intrinsics are supported by the
5+
; NaCl ARM backend.
6+
7+
declare i16 @llvm.bswap.i16(i16)
8+
declare i32 @llvm.bswap.i32(i32)
9+
declare i64 @llvm.bswap.i64(i64)
10+
11+
; CHECK: test_bswap_16
12+
; CHECK: rev [[REG:r[0-9]+]], {{r[0-9]+}}
13+
; CHECK-NEXT: lsr {{.*}}[[REG]], {{.*}}[[REG]], #16
14+
define i16 @test_bswap_16(i16 %a) {
15+
%b = call i16 @llvm.bswap.i16(i16 %a)
16+
ret i16 %b
17+
}
18+
19+
; CHECK: test_bswap_const_16
20+
; 0xcdab
21+
; CHECK: movw r0, #52651
22+
define i16 @test_bswap_const_16() {
23+
; 0xabcd
24+
%a = call i16 @llvm.bswap.i16(i16 43981)
25+
ret i16 %a
26+
}
27+
28+
; CHECK: test_bswap_32
29+
; CHECK: rev [[REG:r[0-9]+]], {{r[0-9]+}}
30+
define i32 @test_bswap_32(i32 %a) {
31+
%b = call i32 @llvm.bswap.i32(i32 %a)
32+
ret i32 %b
33+
}
34+
35+
; CHECK: test_bswap_const_32
36+
; 0x01ef cdab
37+
; CHECK: movw r0, #52651
38+
; CHECK: movt r0, #495
39+
define i32 @test_bswap_const_32() {
40+
; 0xabcdef01
41+
%a = call i32 @llvm.bswap.i32(i32 2882400001)
42+
ret i32 %a
43+
}
44+
45+
; CHECK: test_bswap_64
46+
; CHECK: rev [[REG1:r[0-9]+]], {{r[0-9]+}}
47+
; CHECK: rev {{r[0-9]+}}, {{r[0-9]+}}
48+
; CHECK: mov r0, {{.*}}[[REG1]]
49+
define i64 @test_bswap_64(i64 %a) {
50+
%b = call i64 @llvm.bswap.i64(i64 %a)
51+
ret i64 %b
52+
}
53+
54+
; CHECK: test_bswap_const_64
55+
; 0x8967 4523 01ef cdab
56+
; Just checking movw, since O0 and O2 have different schedules for the
57+
; movw/movt of r0/r1.
58+
; CHECK: movw r0, #52651
59+
; CHECK: movw r1, #17699
60+
define i64 @test_bswap_const_64() {
61+
; 0xabcdef01 23456789
62+
%a = call i64 @llvm.bswap.i64(i64 12379813738877118345)
63+
ret i64 %a
64+
}

test/NaCl/X86/intrinsics-bitmanip.ll

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; RUN: llc -mtriple=i686-unknown-nacl -O0 -filetype=asm %s -o - | FileCheck %s \
2+
; RUN: --check-prefix=NACL32
3+
; RUN: llc -mtriple=i686-unknown-nacl -filetype=asm %s -o - | FileCheck %s \
4+
; RUN: --check-prefix=NACL32
5+
; RUN: llc -mtriple=x86_64-unknown-nacl -O0 -filetype=asm %s -o - | \
6+
; RUN: FileCheck %s --check-prefix=NACL64
7+
; RUN: llc -mtriple=x86_64-unknown-nacl -filetype=asm %s -o - | \
8+
; RUN: FileCheck %s --check-prefix=NACL64
9+
10+
; Test that various bit manipulation intrinsics are supported by the
11+
; NaCl X86-32 and X86-64 backends.
12+
13+
declare i16 @llvm.bswap.i16(i16)
14+
declare i32 @llvm.bswap.i32(i32)
15+
declare i64 @llvm.bswap.i64(i64)
16+
17+
; NACL32: test_bswap_16
18+
; NACL32: rolw $8, %{{.*}}
19+
; NACL64: test_bswap_16
20+
; NACL64: rolw $8, %{{.*}}
21+
define i16 @test_bswap_16(i16 %a) {
22+
%b = call i16 @llvm.bswap.i16(i16 %a)
23+
ret i16 %b
24+
}
25+
26+
; NACL32: test_bswap_const_16
27+
; NACL32: movw $-12885, %ax # imm = 0xFFFFFFFFFFFFCDAB
28+
; NACL64: test_bswap_const_16
29+
; NACL64: movw $-12885, %ax # imm = 0xFFFFFFFFFFFFCDAB
30+
define i16 @test_bswap_const_16() {
31+
; 0xabcd
32+
%a = call i16 @llvm.bswap.i16(i16 43981)
33+
ret i16 %a
34+
}
35+
36+
; NACL32: test_bswap_32
37+
; NACL32: bswapl %eax
38+
; NACL64: test_bswap_32
39+
; NACL64: bswapl %edi
40+
define i32 @test_bswap_32(i32 %a) {
41+
%b = call i32 @llvm.bswap.i32(i32 %a)
42+
ret i32 %b
43+
}
44+
45+
; NACL32: test_bswap_const_32
46+
; NACL32: movl $32492971, %eax # imm = 0x1EFCDAB
47+
; NACL64: test_bswap_const_32
48+
; NACL64: movl $32492971, %eax # imm = 0x1EFCDAB
49+
define i32 @test_bswap_const_32() {
50+
; 0xabcdef01
51+
%a = call i32 @llvm.bswap.i32(i32 2882400001)
52+
ret i32 %a
53+
}
54+
55+
; NACL32: test_bswap_64
56+
; NACL32: bswapl %e{{.*}}
57+
; NACL32: bswapl %e{{.*}}
58+
; NACL64: test_bswap_64
59+
; NACL64: bswapq %rdi
60+
define i64 @test_bswap_64(i64 %a) {
61+
%b = call i64 @llvm.bswap.i64(i64 %a)
62+
ret i64 %b
63+
}
64+
65+
; NACL32: test_bswap_const_64
66+
; NACL32: movl $32492971, %eax # imm = 0x1EFCDAB
67+
; NACL32: movl $-1989720797, %edx # imm = 0xFFFFFFFF89674523
68+
; NACL64: test_bswap_const_64
69+
; NACL64: movabsq $-8545785751253561941, %rax # imm = 0x8967452301EFCDAB
70+
define i64 @test_bswap_const_64(i64 %a) {
71+
; 0xabcdef01 23456789
72+
%b = call i64 @llvm.bswap.i64(i64 12379813738877118345)
73+
ret i64 %b
74+
}

0 commit comments

Comments
 (0)