[PATCH] D101235: [InstCombine] ctpop(rot(X)) -> ctpop(X)
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 24 09:25:16 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde3fa35cdb6f: [InstCombine] ctpop(rot(X)) -> ctpop(X) (authored by xbolva00).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101235/new/
https://reviews.llvm.org/D101235
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/ctpop.ll
Index: llvm/test/Transforms/InstCombine/ctpop.ll
===================================================================
--- llvm/test/Transforms/InstCombine/ctpop.ll
+++ llvm/test/Transforms/InstCombine/ctpop.ll
@@ -203,11 +203,11 @@
define i32 @ctpop_add_no_common_bits(i32 %a, i32 %b) {
; CHECK-LABEL: @ctpop_add_no_common_bits(
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.fshl.i32(i32 [[B:%.*]], i32 [[B]], i32 16)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.fshl.i32(i32 [[A:%.*]], i32 [[B:%.*]], i32 16)
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.ctpop.i32(i32 [[TMP1]]), !range [[RNG1]]
; CHECK-NEXT: ret i32 [[TMP2]]
;
- %shl16 = shl i32 %b, 16
+ %shl16 = shl i32 %a, 16
%ctpop1 = tail call i32 @llvm.ctpop.i32(i32 %shl16)
%lshl16 = lshr i32 %b, 16
%ctpop2 = tail call i32 @llvm.ctpop.i32(i32 %lshl16)
@@ -266,3 +266,26 @@
%res = add <2 x i32> %ctpop1, %ctpop2
ret <2 x i32> %res
}
+
+define i8 @ctpop_rotate_left(i8 %a, i8 %amt) {
+; CHECK-LABEL: @ctpop_rotate_left(
+; CHECK-NEXT: [[CTPOP:%.*]] = tail call i8 @llvm.ctpop.i8(i8 [[A:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: ret i8 [[CTPOP]]
+;
+ %rotl = tail call i8 @llvm.fshl.i8(i8 %a, i8 %a, i8 %amt)
+ %ctpop = tail call i8 @llvm.ctpop.i8(i8 %rotl)
+ ret i8 %ctpop
+}
+
+define i8 @ctpop_rotate_right(i8 %a, i8 %amt) {
+; CHECK-LABEL: @ctpop_rotate_right(
+; CHECK-NEXT: [[CTPOP:%.*]] = tail call i8 @llvm.ctpop.i8(i8 [[A:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: ret i8 [[CTPOP]]
+;
+ %rotr = tail call i8 @llvm.fshr.i8(i8 %a, i8 %a, i8 %amt)
+ %ctpop = tail call i8 @llvm.ctpop.i8(i8 %rotr)
+ ret i8 %ctpop
+}
+
+declare i8 @llvm.fshl.i8(i8, i8, i8)
+declare i8 @llvm.fshr.i8(i8, i8, i8)
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -504,6 +504,11 @@
if (match(Op0, m_BitReverse(m_Value(X))) || match(Op0, m_BSwap(m_Value(X))))
return IC.replaceOperand(II, 0, X);
+ // ctpop(rot(x)) -> ctpop(x)
+ if (match(Op0, m_FShl(m_Value(X), m_Specific(X), m_Value())) ||
+ match(Op0, m_FShr(m_Value(X), m_Specific(X), m_Value())))
+ return IC.replaceOperand(II, 0, X);
+
// ctpop(x | -x) -> bitwidth - cttz(x, false)
if (Op0->hasOneUse() &&
match(Op0, m_c_Or(m_Value(X), m_Neg(m_Deferred(X))))) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101235.340291.patch
Type: text/x-patch
Size: 2436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210424/32de1b0e/attachment.bin>
More information about the llvm-commits
mailing list