[llvm] 532f3be - [InstCombine] collectBitParts - add bitreverse intrinsic support.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 07:36:51 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-26T14:36:36Z
New Revision: 532f3bec3e019a3e6089edf6bd21e9b9b540542b
URL: https://github.com/llvm/llvm-project/commit/532f3bec3e019a3e6089edf6bd21e9b9b540542b
DIFF: https://github.com/llvm/llvm-project/commit/532f3bec3e019a3e6089edf6bd21e9b9b540542b.diff
LOG: [InstCombine] collectBitParts - add bitreverse intrinsic support.
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/bswap.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 9303ea5cdf73..afbba4c83964 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2947,6 +2947,20 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
return Result;
}
+ // BITREVERSE - most likely due to us previous matching a partial
+ // bitreverse.
+ if (match(V, m_BitReverse(m_Value(X)))) {
+ const auto &Res =
+ collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
+ if (!Res)
+ return Result;
+
+ Result = BitPart(Res->Provider, BitWidth);
+ for (unsigned BitIdx = 0; BitIdx < BitWidth; ++BitIdx)
+ Result->Provenance[(BitWidth - 1) - BitIdx] = Res->Provenance[BitIdx];
+ return Result;
+ }
+
// BSWAP - most likely due to us previous matching a partial bswap.
if (match(V, m_BSwap(m_Value(X)))) {
const auto &Res =
diff --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll
index ff1e329ba925..936ed12cacad 100644
--- a/llvm/test/Transforms/InstCombine/bswap.ll
+++ b/llvm/test/Transforms/InstCombine/bswap.ll
@@ -537,12 +537,7 @@ declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>)
define i16 @partial_bitreverse(i16 %x) {
; CHECK-LABEL: @partial_bitreverse(
-; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[X:%.*]])
-; CHECK-NEXT: [[LO:%.*]] = and i16 [[REV]], 255
-; CHECK-NEXT: [[HI:%.*]] = and i16 [[REV]], -256
-; CHECK-NEXT: [[REVLO:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[LO]])
-; CHECK-NEXT: [[REVHI:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[HI]])
-; CHECK-NEXT: [[OR:%.*]] = call i16 @llvm.fshl.i16(i16 [[REVHI]], i16 [[REVLO]], i16 8)
+; CHECK-NEXT: [[OR:%.*]] = call i16 @llvm.bswap.i16(i16 [[X:%.*]])
; CHECK-NEXT: ret i16 [[OR]]
;
%rev= call i16 @llvm.bitreverse.i16(i16 %x)
More information about the llvm-commits
mailing list