[Analysis] bitreverse(undef) returns undef

Summary:
The reverse of an artbitrary bitpattern is also an arbitrary
bitpattern.

Reviewers: trentxintong, arsenm, majnemer

Reviewed By: majnemer

Subscribers: majnemer, wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D31118

llvm-svn: 298201
This commit is contained in:
Brian Gesiak 2017-03-19 04:40:42 +00:00
parent 662c9b1e81
commit 1640e68728
2 changed files with 16 additions and 1 deletions

View File

@ -1768,7 +1768,8 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty,
}
if (isa<UndefValue>(Operands[0])) {
if (IntrinsicID == Intrinsic::bswap)
if (IntrinsicID == Intrinsic::bswap ||
IntrinsicID == Intrinsic::bitreverse)
return Operands[0];
return nullptr;
}

View File

@ -37,6 +37,13 @@ define i32 @reverse_neg1_i32() {
ret i32 %x
}
; CHECK-LABEL: @reverse_undef_i32(
; CHECK-NEXT: ret i32 undef
define i32 @reverse_undef_i32() {
%x = call i32 @llvm.bitreverse.i32(i32 undef)
ret i32 %x
}
; CHECK-LABEL: @reverse_false_i1(
; CHECK-NEXT: ret i1 false
define i1 @reverse_false_i1() {
@ -51,6 +58,13 @@ define i1 @reverse_true_i1() {
ret i1 %x
}
; CHECK-LABEL: @reverse_undef_i1(
; CHECK-NEXT: ret i1 undef
define i1 @reverse_undef_i1() {
%x = call i1 @llvm.bitreverse.i1(i1 undef)
ret i1 %x
}
; CHECK-LABEL: @reverse_false_v2i1(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
define <2 x i1> @reverse_false_v2i1() {