1; RUN: opt -S -demanded-bits -analyze -enable-new-pm=0 < %s | FileCheck %s 2; RUN: opt -S -disable-output -passes="print<demanded-bits>" < %s 2>&1 | FileCheck %s 3 4; CHECK-DAG: DemandedBits: 0xff000000 for %1 = or i32 %x, 1 5; CHECK-DAG: DemandedBits: 0xff for %2 = call i32 @llvm.bitreverse.i32(i32 %1) 6; CHECK-DAG: DemandedBits: 0xff for %3 = trunc i32 %2 to i8 7define i8 @test_bswap(i32 %x) { 8 %1 = or i32 %x, 1 9 %2 = call i32 @llvm.bswap.i32(i32 %1) 10 %3 = trunc i32 %2 to i8 11 ret i8 %3 12} 13declare i32 @llvm.bswap.i32(i32) 14 15; CHECK-DAG: DemandedBits: 0xff000000 for %1 = or i32 %x, 1 16; CHECK-DAG: DemandedBits: 0xff for %2 = call i32 @llvm.bswap.i32(i32 %1) 17; CHECK-DAG: DemandedBits: 0xff for %3 = trunc i32 %2 to i8 18define i8 @test_bitreverse(i32 %x) { 19 %1 = or i32 %x, 1 20 %2 = call i32 @llvm.bitreverse.i32(i32 %1) 21 %3 = trunc i32 %2 to i8 22 ret i8 %3 23} 24declare i32 @llvm.bitreverse.i32(i32) 25 26; Funnel shifts 27declare i32 @llvm.fshl.i32(i32, i32, i32) 28declare i33 @llvm.fshr.i33(i33, i33, i33) 29 30; CHECK-DAG: DemandedBits: 0xff for %x2 = or i32 %x, 1 31; CHECK-DAG: DemandedBits: 0xff000000 for %y2 = or i32 %y, 1 32; CHECK-DAG: DemandedBits: 0xffff for %z = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 8) 33; CHECK-DAG: DemandedBits: 0xffffffff for %r = and i32 %z, 65535 34define i32 @test_fshl(i32 %x, i32 %y) { 35 %x2 = or i32 %x, 1 36 %y2 = or i32 %y, 1 37 %z = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 8) 38 %r = and i32 %z, 65535 39 ret i32 %r 40} 41 42; CHECK-DAG: DemandedBits: 0xff for %x2 = or i33 %x, 1 43; CHECK-DAG: DemandedBits: 0x1fe000000 for %y2 = or i33 %y, 1 44; CHECK-DAG: DemandedBits: 0xffff for %z = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 25) 45; CHECK-DAG: DemandedBits: 0x1ffffffff for %r = and i33 %z, 65535 46define i33 @test_fshr(i33 %x, i33 %y) { 47 %x2 = or i33 %x, 1 48 %y2 = or i33 %y, 1 49 %z = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 25) 50 %r = and i33 %z, 65535 51 ret i33 %r 52} 53 54; CHECK-DAG: DemandedBits: 0xffff for %x2 = or i32 %x, 1 55; CHECK-DAG: DemandedBits: 0x0 for %y2 = or i32 %y, 1 56; CHECK-DAG: DemandedBits: 0xffff for %z = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 0) 57; CHECK-DAG: DemandedBits: 0xffffffff for %r = and i32 %z, 65535 58define i32 @test_fshl_zero_shift(i32 %x, i32 %y) { 59 %x2 = or i32 %x, 1 60 %y2 = or i32 %y, 1 61 %z = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 0) 62 %r = and i32 %z, 65535 63 ret i32 %r 64} 65 66; CHECK-DAG: DemandedBits: 0x0 for %x2 = or i33 %x, 1 67; CHECK-DAG: DemandedBits: 0xffff for %y2 = or i33 %y, 1 68; CHECK-DAG: DemandedBits: 0xffff for %z = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 33) 69; CHECK-DAG: DemandedBits: 0x1ffffffff for %r = and i33 %z, 65535 70define i33 @test_fshr_full_shift(i33 %x, i33 %y) { 71 %x2 = or i33 %x, 1 72 %y2 = or i33 %y, 1 73 %z = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 33) 74 %r = and i33 %z, 65535 75 ret i33 %r 76} 77 78; CHECK-DAG: DemandedBits: 0xffffffff for %x2 = or i32 %x, 1 79; CHECK-DAG: DemandedBits: 0xffffffff for %y2 = or i32 %y, 1 80; CHECK-DAG: DemandedBits: 0x1f for %z2 = or i32 %z, 1 81; CHECK-DAG: DemandedBits: 0xffff for %f = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 %z2) 82; CHECK-DAG: DemandedBits: 0xffffffff for %r = and i32 %f, 65535 83define i32 @test_fshl_pow2_bitwidth(i32 %x, i32 %y, i32 %z) { 84 %x2 = or i32 %x, 1 85 %y2 = or i32 %y, 1 86 %z2 = or i32 %z, 1 87 %f = call i32 @llvm.fshl.i32(i32 %x2, i32 %y2, i32 %z2) 88 %r = and i32 %f, 65535 89 ret i32 %r 90} 91 92; CHECK-DAG: DemandedBits: 0x1ffffffff for %x2 = or i33 %x, 1 93; CHECK-DAG: DemandedBits: 0x1ffffffff for %y2 = or i33 %y, 1 94; CHECK-DAG: DemandedBits: 0x1ffffffff for %z2 = or i33 %z, 1 95; CHECK-DAG: DemandedBits: 0xffff for %f = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 %z2) 96; CHECK-DAG: DemandedBits: 0x1ffffffff for %r = and i33 %f, 65535 97define i33 @test_fshr_non_pow2_bitwidth(i33 %x, i33 %y, i33 %z) { 98 %x2 = or i33 %x, 1 99 %y2 = or i33 %y, 1 100 %z2 = or i33 %z, 1 101 %f = call i33 @llvm.fshr.i33(i33 %x2, i33 %y2, i33 %z2) 102 %r = and i33 %f, 65535 103 ret i33 %r 104} 105