From 1640e687280e653947811f4305f021be8f9472e5 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Sun, 19 Mar 2017 04:40:42 +0000 Subject: [PATCH] [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 --- llvm/lib/Analysis/ConstantFolding.cpp | 3 ++- .../test/Transforms/InstCombine/bitreverse-fold.ll | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 6d8d4a1c3e90..85ca622a25dc 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1768,7 +1768,8 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty, } if (isa(Operands[0])) { - if (IntrinsicID == Intrinsic::bswap) + if (IntrinsicID == Intrinsic::bswap || + IntrinsicID == Intrinsic::bitreverse) return Operands[0]; return nullptr; } diff --git a/llvm/test/Transforms/InstCombine/bitreverse-fold.ll b/llvm/test/Transforms/InstCombine/bitreverse-fold.ll index ecdfbc8cb5f9..b798ad33b3f0 100644 --- a/llvm/test/Transforms/InstCombine/bitreverse-fold.ll +++ b/llvm/test/Transforms/InstCombine/bitreverse-fold.ll @@ -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() {