1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -instcombine | FileCheck %s
4 declare i8 @llvm.bitreverse.i8(i8)
5 declare i32 @llvm.bitreverse.i32(i32)
7 define i1 @test1(i32 %arg) {
9 ; CHECK-NEXT: ret i1 true
11 %a = or i32 %arg, 4294901760
12 %b = call i32 @llvm.bitreverse.i32(i32 %a)
13 %and = and i32 %b, 65535
14 %res = icmp eq i32 %and, 65535
18 define i1 @test2(i32 %arg) {
19 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: ret i1 true
23 %b = call i32 @llvm.bitreverse.i32(i32 %a)
24 %c = and i32 %b, 2147483648
25 %d = call i32 @llvm.bitreverse.i32(i32 %c)
26 %res = icmp eq i32 %d, 1
30 define i1 @test3(i32 %arg) {
31 ; CHECK-LABEL: @test3(
32 ; CHECK-NEXT: ret i1 false
34 %a = or i32 %arg, 65536
35 %b = call i32 @llvm.bitreverse.i32(i32 %a)
36 %and = and i32 %b, 32768
37 %res = icmp eq i32 %and, 0
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
45 ; or %reverse, 1111 0000
47 define i8 @add_bitreverse(i8 %a) {
48 ; CHECK-LABEL: @add_bitreverse(
49 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -4
50 ; CHECK-NEXT: [[REVERSE:%.*]] = call i8 @llvm.bitreverse.i8(i8 [[B]]), [[RNG0:!range !.*]]
51 ; CHECK-NEXT: [[C:%.*]] = or i8 [[REVERSE]], -16
52 ; CHECK-NEXT: ret i8 [[C]]
55 %reverse = call i8 @llvm.bitreverse.i8(i8 %b), !range !1
56 %c = add i8 %reverse, -16