[ValueTracking] Make sure we keep range metadata information when calculating known bits for calls to bitreverse intrinsic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298488 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2017-03-22 07:22:49 +00:00
parent 5b64d78c22
commit f448321cdd
2 changed files with 19 additions and 2 deletions

View File

@ -1414,8 +1414,8 @@ static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero,
default: break;
case Intrinsic::bitreverse:
computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, Depth + 1, Q);
KnownZero = KnownZero2.reverseBits();
KnownOne = KnownOne2.reverseBits();
KnownZero |= KnownZero2.reverseBits();
KnownOne |= KnownOne2.reverseBits();
break;
case Intrinsic::bswap:
computeKnownBits(I->getOperand(0), KnownZero2, KnownOne2, Depth + 1, Q);

View File

@ -1,5 +1,6 @@
; RUN: opt < %s -S -instcombine | FileCheck %s
declare i8 @llvm.bitreverse.i8(i8)
declare i32 @llvm.bitreverse.i32(i32)
; CHECK-LABEL: @test1
@ -32,3 +33,19 @@ define i1 @test3(i32 %arg) {
%res = icmp eq i32 %and, 0
ret i1 %res
}
; CHECK-LABEL: @add_bitreverse
; Make sure we process range metadata on bitreverse
define i8 @add_bitreverse(i8 %a) {
%b = and i8 %a, 252
; known bits for the bitreverse will say the result is in the range [0, 64)
; but the metadata says [0, 16). So make sure the range metadata wins.
; add %reverse, 1111 0000
; should become
; or %reverse, 1111 0000
%reverse = call i8 @llvm.bitreverse.i8(i8 %b), !range !1
%c = add i8 %reverse, -16
; CHECK: or i8 %reverse, -16
ret i8 %c
}
!1 = !{i8 0, i8 16}