1; RUN: opt < %s -S -instcombine | FileCheck %s
2
3declare i8 @llvm.bitreverse.i8(i8)
4declare i32 @llvm.bitreverse.i32(i32)
5
6; CHECK-LABEL: @test1
7; CHECK: ret i1 true
8define i1 @test1(i32 %arg) {
9  %a = or i32 %arg, 4294901760
10  %b = call i32 @llvm.bitreverse.i32(i32 %a)
11  %and = and i32 %b, 65535
12  %res = icmp eq i32 %and, 65535
13  ret i1 %res
14}
15
16; CHECK-LABEL: @test2
17; CHECK: ret i1 true
18define i1 @test2(i32 %arg) {
19  %a = or i32 %arg, 1
20  %b = call i32 @llvm.bitreverse.i32(i32 %a)
21  %c = and i32 %b, 2147483648
22  %d = call i32 @llvm.bitreverse.i32(i32 %c)
23  %res = icmp eq i32 %d, 1
24  ret i1 %res
25}
26
27; CHECK-LABEL: @test3
28; CHECK: ret i1 false
29define i1 @test3(i32 %arg) {
30  %a = or i32 %arg, 65536
31  %b = call i32 @llvm.bitreverse.i32(i32 %a)
32  %and = and i32 %b, 32768
33  %res = icmp eq i32 %and, 0
34  ret i1 %res
35}
36
37; CHECK-LABEL: @add_bitreverse
38; Make sure we process range metadata on bitreverse
39define i8 @add_bitreverse(i8 %a) {
40  %b = and i8 %a, 252
41  ; known bits for the bitreverse will say the result is in the range [0, 64)
42  ; but the metadata says [0, 16). So make sure the range metadata wins.
43  ;    add %reverse, 1111 0000
44  ; should become
45  ;    or  %reverse, 1111 0000
46  %reverse = call i8 @llvm.bitreverse.i8(i8 %b), !range !1
47  %c = add i8 %reverse, -16
48; CHECK: or i8 %reverse, -16
49  ret i8 %c
50}
51!1 = !{i8 0, i8 16}
52