[llvm] r357564 - [InstCombine] Simplify ctpop with bitreverse/bswap
David Bolvansky via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 3 01:08:45 PDT 2019
Author: xbolva00
Date: Wed Apr 3 01:08:44 2019
New Revision: 357564
URL: http://llvm.org/viewvc/llvm-project?rev=357564&view=rev
Log:
[InstCombine] Simplify ctpop with bitreverse/bswap
Summary: Fixes PR41337
Reviewers: spatel
Reviewed By: spatel
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60148
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/ctpop-bswap-bitreverse.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=357564&r1=357563&r2=357564&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Apr 3 01:08:44 2019
@@ -1383,6 +1383,14 @@ static Instruction *foldCtpop(IntrinsicI
assert(II.getIntrinsicID() == Intrinsic::ctpop &&
"Expected ctpop intrinsic");
Value *Op0 = II.getArgOperand(0);
+ Value *X;
+ // ctpop(bitreverse(x)) -> ctpop(x)
+ // ctpop(bswap(x)) -> ctpop(x)
+ if (match(Op0, m_BitReverse(m_Value(X))) || match(Op0, m_BSwap(m_Value(X)))) {
+ II.setOperand(0, X);
+ return ⅈ
+ }
+
// FIXME: Try to simplify vectors of integers.
auto *IT = dyn_cast<IntegerType>(Op0->getType());
if (!IT)
Modified: llvm/trunk/test/Transforms/InstCombine/ctpop-bswap-bitreverse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/ctpop-bswap-bitreverse.ll?rev=357564&r1=357563&r2=357564&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/ctpop-bswap-bitreverse.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/ctpop-bswap-bitreverse.ll Wed Apr 3 01:08:44 2019
@@ -3,8 +3,7 @@
define i32 @ctpop_bitreverse(i32 %x) {
; CHECK-LABEL: @ctpop_bitreverse(
-; CHECK-NEXT: [[A:%.*]] = tail call i32 @llvm.bitreverse.i32(i32 [[X:%.*]])
-; CHECK-NEXT: [[B:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[A]]), !range !0
+; CHECK-NEXT: [[B:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
; CHECK-NEXT: ret i32 [[B]]
;
%a = tail call i32 @llvm.bitreverse.i32(i32 %x)
@@ -14,8 +13,7 @@ define i32 @ctpop_bitreverse(i32 %x) {
define <2 x i64> @ctpop_bitreverse_vec(<2 x i64> %x) {
; CHECK-LABEL: @ctpop_bitreverse_vec(
-; CHECK-NEXT: [[A:%.*]] = tail call <2 x i64> @llvm.bitreverse.v2i64(<2 x i64> [[X:%.*]])
-; CHECK-NEXT: [[B:%.*]] = tail call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> [[A]])
+; CHECK-NEXT: [[B:%.*]] = tail call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> [[X:%.*]])
; CHECK-NEXT: ret <2 x i64> [[B]]
;
%a = tail call <2 x i64> @llvm.bitreverse.v2i64(<2 x i64> %x)
@@ -25,8 +23,7 @@ define <2 x i64> @ctpop_bitreverse_vec(<
define i32 @ctpop_bswap(i32 %x) {
; CHECK-LABEL: @ctpop_bswap(
-; CHECK-NEXT: [[A:%.*]] = tail call i32 @llvm.bswap.i32(i32 [[X:%.*]])
-; CHECK-NEXT: [[B:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[A]]), !range !0
+; CHECK-NEXT: [[B:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
; CHECK-NEXT: ret i32 [[B]]
;
%a = tail call i32 @llvm.bswap.i32(i32 %x)
@@ -36,8 +33,7 @@ define i32 @ctpop_bswap(i32 %x) {
define <2 x i64> @ctpop_bswap_vec(<2 x i64> %x) {
; CHECK-LABEL: @ctpop_bswap_vec(
-; CHECK-NEXT: [[A:%.*]] = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> [[X:%.*]])
-; CHECK-NEXT: [[B:%.*]] = tail call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> [[A]])
+; CHECK-NEXT: [[B:%.*]] = tail call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> [[X:%.*]])
; CHECK-NEXT: ret <2 x i64> [[B]]
;
%a = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %x)
More information about the llvm-commits
mailing list