[llvm] e2165e0 - [InstCombine] remove trunc user restriction for match of bswap
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 5 10:04:18 PST 2022
Author: Sanjay Patel
Date: 2022-01-05T13:04:11-05:00
New Revision: e2165e096869ef5bd5150c150a1cbfc25f693a0f
URL: https://github.com/llvm/llvm-project/commit/e2165e096869ef5bd5150c150a1cbfc25f693a0f
DIFF: https://github.com/llvm/llvm-project/commit/e2165e096869ef5bd5150c150a1cbfc25f693a0f.diff
LOG: [InstCombine] remove trunc user restriction for match of bswap
This does not appear to cause any problems, and it
fixes #50910
Extra tests with a trunc user were added with:
3a239379
...but they don't match either way, so there's an
opportunity to improve the matching further.
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 ecad79b68185c..efc53968b1e94 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3147,11 +3147,6 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
if (!ITy->isIntOrIntVectorTy() || ITy->getScalarSizeInBits() > 128)
return false; // Can't do integer/elements > 128 bits.
- Type *DemandedTy = ITy;
- if (I->hasOneUse())
- if (auto *Trunc = dyn_cast<TruncInst>(I->user_back()))
- DemandedTy = Trunc->getType();
-
// Try to find all the pieces corresponding to the bswap.
bool FoundRoot = false;
std::map<Value *, Optional<BitPart>> BPS;
@@ -3165,6 +3160,7 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
"Illegal bit provenance index");
// If the upper bits are zero, then attempt to perform as a truncated op.
+ Type *DemandedTy = ITy;
if (BitProvenance.back() == BitPart::Unset) {
while (!BitProvenance.empty() && BitProvenance.back() == BitPart::Unset)
BitProvenance = BitProvenance.drop_back();
diff --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll
index 7777e4fa3ad0f..86d8718073d54 100644
--- a/llvm/test/Transforms/InstCombine/bswap.ll
+++ b/llvm/test/Transforms/InstCombine/bswap.ll
@@ -919,10 +919,7 @@ declare i64 @llvm.bswap.i64(i64)
define i32 @PR50910(i64 %t0) {
; CHECK-LABEL: @PR50910(
-; CHECK-NEXT: [[T2:%.*]] = and i64 [[T0:%.*]], 72057594037927935
-; CHECK-NEXT: [[T3:%.*]] = call i64 @llvm.bswap.i64(i64 [[T2]])
-; CHECK-NEXT: [[T4:%.*]] = lshr i64 [[T0]], 56
-; CHECK-NEXT: [[T5:%.*]] = or i64 [[T3]], [[T4]]
+; CHECK-NEXT: [[T5:%.*]] = call i64 @llvm.bswap.i64(i64 [[T0:%.*]])
; CHECK-NEXT: [[T6:%.*]] = trunc i64 [[T5]] to i32
; CHECK-NEXT: ret i32 [[T6]]
;
More information about the llvm-commits
mailing list