[llvm] 0905bd5 - [InstCombine] collectBitParts - add trunc support.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 06:20:41 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-27T13:14:54Z
New Revision: 0905bd5c2fa42bd4c0e6e0aaa08b966f165b9dfa
URL: https://github.com/llvm/llvm-project/commit/0905bd5c2fa42bd4c0e6e0aaa08b966f165b9dfa
DIFF: https://github.com/llvm/llvm-project/commit/0905bd5c2fa42bd4c0e6e0aaa08b966f165b9dfa.diff
LOG: [InstCombine] collectBitParts - add trunc support.
This should allow us to remove the rather limited matchOrConcat fold and just use recognizeBSwapOrBitReverseIdiom.
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 c5700359e219..420602d9e132 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2928,7 +2928,7 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
return Result;
}
- // If this is a zext instruction zero extend the result.
+ // If this is a zext instruction, zero extend the result.
if (match(V, m_ZExt(m_Value(X)))) {
const auto &Res =
collectBitParts(X, MatchBSwaps, MatchBitReversals, BPS, Depth + 1);
@@ -2944,6 +2944,19 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
return Result;
}
+ // If this is a trunc instruction, take the lower bits.
+ if (match(V, m_Trunc(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[BitIdx] = Res->Provenance[BitIdx];
+ return Result;
+ }
+
// BITREVERSE - most likely due to us previous matching a partial
// bitreverse.
if (match(V, m_BitReverse(m_Value(X)))) {
diff --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll
index 65e2a3607d89..8d0adcf15eec 100644
--- a/llvm/test/Transforms/InstCombine/bswap.ll
+++ b/llvm/test/Transforms/InstCombine/bswap.ll
@@ -596,19 +596,7 @@ define i64 @bswap_and_mask_2(i64 %0) {
define i64 @bswap_trunc(i64 %x01234567) {
; CHECK-LABEL: @bswap_trunc(
-; CHECK-NEXT: [[X7ZZZZZZZ:%.*]] = shl i64 [[X01234567:%.*]], 56
-; CHECK-NEXT: [[XZ0123456:%.*]] = lshr i64 [[X01234567]], 8
-; CHECK-NEXT: [[XZZZZZ012:%.*]] = lshr i64 [[X01234567]], 40
-; CHECK-NEXT: [[X3456:%.*]] = trunc i64 [[XZ0123456]] to i32
-; CHECK-NEXT: [[XZ012:%.*]] = trunc i64 [[XZZZZZ012]] to i32
-; CHECK-NEXT: [[X6543:%.*]] = call i32 @llvm.bswap.i32(i32 [[X3456]])
-; CHECK-NEXT: [[X210Z:%.*]] = call i32 @llvm.bswap.i32(i32 [[XZ012]])
-; CHECK-NEXT: [[XZ210:%.*]] = lshr exact i32 [[X210Z]], 8
-; CHECK-NEXT: [[XZZZZ6543:%.*]] = zext i32 [[X6543]] to i64
-; CHECK-NEXT: [[XZZZZZ210:%.*]] = zext i32 [[XZ210]] to i64
-; CHECK-NEXT: [[XZ6543ZZZ:%.*]] = shl nuw nsw i64 [[XZZZZ6543]], 24
-; CHECK-NEXT: [[XZ6543210:%.*]] = or i64 [[XZ6543ZZZ]], [[XZZZZZ210]]
-; CHECK-NEXT: [[X76543210:%.*]] = or i64 [[XZ6543210]], [[X7ZZZZZZZ]]
+; CHECK-NEXT: [[X76543210:%.*]] = call i64 @llvm.bswap.i64(i64 [[X01234567:%.*]])
; CHECK-NEXT: ret i64 [[X76543210]]
;
%x7zzzzzzz = shl i64 %x01234567, 56
More information about the llvm-commits
mailing list