1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -S -instcombine | FileCheck %s 3 4declare i8 @llvm.bitreverse.i8(i8) 5declare i32 @llvm.bitreverse.i32(i32) 6 7define i1 @test1(i32 %arg) { 8; CHECK-LABEL: @test1( 9; CHECK-NEXT: ret i1 true 10; 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 15 ret i1 %res 16} 17 18define i1 @test2(i32 %arg) { 19; CHECK-LABEL: @test2( 20; CHECK-NEXT: ret i1 true 21; 22 %a = or i32 %arg, 1 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 27 ret i1 %res 28} 29 30define i1 @test3(i32 %arg) { 31; CHECK-LABEL: @test3( 32; CHECK-NEXT: ret i1 false 33; 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 38 ret i1 %res 39} 40 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 47define 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]] 53; 54 %b = and i8 %a, 252 55 %reverse = call i8 @llvm.bitreverse.i8(i8 %b), !range !1 56 %c = add i8 %reverse, -16 57 ret i8 %c 58} 59!1 = !{i8 0, i8 16} 60