Skip to content

Commit 5fb39f0

Browse files
committed
[AArch64][x86] add tests for bswap demanded bits; NFC
1 parent 6ca192d commit 5fb39f0

File tree

2 files changed

+112
-8
lines changed

2 files changed

+112
-8
lines changed
Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,117 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
12
; RUN: llc < %s -mtriple=aarch64-apple-darwin | FileCheck %s
23

34
declare i16 @llvm.bswap.i16(i16)
45
declare i32 @llvm.bswap.i32(i32)
6+
declare i64 @llvm.bswap.i64(i64)
57

6-
; CHECK-LABEL: @test1
7-
; CHECK: mov w0, #1
88
define i1 @test1(i16 %arg) {
9+
; CHECK-LABEL: test1:
10+
; CHECK: ; %bb.0:
11+
; CHECK-NEXT: mov w0, #1
12+
; CHECK-NEXT: ret
913
%a = or i16 %arg, 511
1014
%b = call i16 @llvm.bswap.i16(i16 %a)
1115
%and = and i16 %b, 256
1216
%res = icmp eq i16 %and, 256
1317
ret i1 %res
1418
}
1519

16-
; CHECK-LABEL: @test2
17-
; CHECK: mov w0, #1
1820
define i1 @test2(i16 %arg) {
21+
; CHECK-LABEL: test2:
22+
; CHECK: ; %bb.0:
23+
; CHECK-NEXT: mov w0, #1
24+
; CHECK-NEXT: ret
1925
%a = or i16 %arg, 1
2026
%b = call i16 @llvm.bswap.i16(i16 %a)
2127
%and = and i16 %b, 256
2228
%res = icmp eq i16 %and, 256
2329
ret i1 %res
2430
}
2531

26-
; CHECK-LABEL: @test3
27-
; CHECK: mov w0, #1
2832
define i1 @test3(i16 %arg) {
33+
; CHECK-LABEL: test3:
34+
; CHECK: ; %bb.0:
35+
; CHECK-NEXT: mov w0, #1
36+
; CHECK-NEXT: ret
2937
%a = or i16 %arg, 256
3038
%b = call i16 @llvm.bswap.i16(i16 %a)
3139
%and = and i16 %b, 1
3240
%res = icmp eq i16 %and, 1
3341
ret i1 %res
3442
}
3543

36-
; CHECK-LABEL: @test4
37-
; CHECK: mov w0, #1
3844
define i1 @test4(i32 %arg) {
45+
; CHECK-LABEL: test4:
46+
; CHECK: ; %bb.0:
47+
; CHECK-NEXT: mov w0, #1
48+
; CHECK-NEXT: ret
3949
%a = or i32 %arg, 2147483647 ; i32_MAX
4050
%b = call i32 @llvm.bswap.i32(i32 %a)
4151
%and = and i32 %b, 127
4252
%res = icmp eq i32 %and, 127
4353
ret i1 %res
4454
}
55+
56+
define i8 @demand_one_byte0(i32 %x) {
57+
; CHECK-LABEL: demand_one_byte0:
58+
; CHECK: ; %bb.0:
59+
; CHECK-NEXT: rev w0, w0
60+
; CHECK-NEXT: ret
61+
%b = call i32 @llvm.bswap.i32(i32 %x)
62+
%r = trunc i32 %b to i8
63+
ret i8 %r
64+
}
65+
66+
define i32 @demand_one_byte1(i32 %x) {
67+
; CHECK-LABEL: demand_one_byte1:
68+
; CHECK: ; %bb.0:
69+
; CHECK-NEXT: rev w8, w0
70+
; CHECK-NEXT: and w0, w8, #0xff00
71+
; CHECK-NEXT: ret
72+
%b = call i32 @llvm.bswap.i32(i32 %x)
73+
%r = and i32 %b, 65280 ; 0x0000ff00
74+
ret i32 %r
75+
}
76+
77+
define i32 @demand_one_byte2(i32 %x) {
78+
; CHECK-LABEL: demand_one_byte2:
79+
; CHECK: ; %bb.0:
80+
; CHECK-NEXT: rev w8, w0
81+
; CHECK-NEXT: orr w0, w8, #0xff00ffff
82+
; CHECK-NEXT: ret
83+
%b = call i32 @llvm.bswap.i32(i32 %x)
84+
%r = or i32 %b, 4278255615 ; 0xff00ffff
85+
ret i32 %r
86+
}
87+
88+
define i64 @demand_one_byte3(i64 %x) {
89+
; CHECK-LABEL: demand_one_byte3:
90+
; CHECK: ; %bb.0:
91+
; CHECK-NEXT: rev x8, x0
92+
; CHECK-NEXT: lsr x0, x8, #56
93+
; CHECK-NEXT: ret
94+
%b = call i64 @llvm.bswap.i64(i64 %x)
95+
%r = lshr i64 %b, 56
96+
ret i64 %r
97+
}
98+
99+
define void @demand_one_loaded_byte(i64* %xp, i32* %yp) {
100+
; CHECK-LABEL: demand_one_loaded_byte:
101+
; CHECK: ; %bb.0:
102+
; CHECK-NEXT: ldr x8, [x0]
103+
; CHECK-NEXT: lsr x8, x8, #8
104+
; CHECK-NEXT: rev w8, w8
105+
; CHECK-NEXT: strb w8, [x1]
106+
; CHECK-NEXT: ret
107+
%x = load i64, i64* %xp, align 8
108+
%x_zzzz7654 = lshr i64 %x, 32
109+
%x_z7654zzz = shl nuw nsw i64 %x_zzzz7654, 24
110+
%x_4zzz = trunc i64 %x_z7654zzz to i32
111+
%y = load i32, i32* %yp, align 4
112+
%y_321z = and i32 %y, -256
113+
%x_zzz4 = call i32 @llvm.bswap.i32(i32 %x_4zzz)
114+
%r = or i32 %x_zzz4, %y_321z
115+
store i32 %r, i32* %yp, align 4
116+
ret void
117+
}

llvm/test/CodeGen/X86/combine-bswap.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,34 @@ define i32 @test_demandedbits_bswap(i32 %a0) nounwind {
5656
%d = and i32 %c, 4294901760
5757
ret i32 %d
5858
}
59+
60+
define void @demand_one_loaded_byte(i64* %xp, i32* %yp) {
61+
; X86-LABEL: demand_one_loaded_byte:
62+
; X86: # %bb.0:
63+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
64+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
65+
; X86-NEXT: movl (%ecx), %edx
66+
; X86-NEXT: movl 4(%ecx), %ecx
67+
; X86-NEXT: shldl $24, %edx, %ecx
68+
; X86-NEXT: bswapl %ecx
69+
; X86-NEXT: movb %cl, (%eax)
70+
; X86-NEXT: retl
71+
;
72+
; X64-LABEL: demand_one_loaded_byte:
73+
; X64: # %bb.0:
74+
; X64-NEXT: movq (%rdi), %rax
75+
; X64-NEXT: shrq $8, %rax
76+
; X64-NEXT: bswapl %eax
77+
; X64-NEXT: movb %al, (%rsi)
78+
; X64-NEXT: retq
79+
%x = load i64, i64* %xp, align 8
80+
%x_zzzz7654 = lshr i64 %x, 32
81+
%x_z7654zzz = shl nuw nsw i64 %x_zzzz7654, 24
82+
%x_4zzz = trunc i64 %x_z7654zzz to i32
83+
%y = load i32, i32* %yp, align 4
84+
%y_321z = and i32 %y, -256
85+
%x_zzz4 = call i32 @llvm.bswap.i32(i32 %x_4zzz)
86+
%r = or i32 %x_zzz4, %y_321z
87+
store i32 %r, i32* %yp, align 4
88+
ret void
89+
}

0 commit comments

Comments
 (0)