Skip to content

Commit

Permalink
[InstCombine] recognizeBSwapOrBitReverseIdiom - cleanup bswap/bitreve…
Browse files Browse the repository at this point in the history
…rse detection loop. NFCI.

Early out if both pattern matches have failed (or we don't want them). Fix case of bit index iterator (and avoid Wshadow issue).
  • Loading branch information
RKSimon committed Sep 30, 2020
1 parent 3f88c10 commit 621c6c8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions llvm/lib/Transforms/Utils/Local.cpp
Expand Up @@ -3038,18 +3038,20 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
// Now, is the bit permutation correct for a bswap or a bitreverse? We can
// only byteswap values with an even number of bytes.
unsigned DemandedBW = DemandedTy->getBitWidth();
bool OKForBSwap = DemandedBW % 16 == 0, OKForBitReverse = true;
for (unsigned i = 0; i < DemandedBW; ++i) {
OKForBSwap &=
bitTransformIsCorrectForBSwap(BitProvenance[i], i, DemandedBW);
OKForBitReverse &=
bitTransformIsCorrectForBitReverse(BitProvenance[i], i, DemandedBW);
bool OKForBSwap = MatchBSwaps && (DemandedBW % 16) == 0;
bool OKForBitReverse = MatchBitReversals;
for (unsigned BitIdx = 0;
(BitIdx < DemandedBW) && (OKForBSwap || OKForBitReverse); ++BitIdx) {
OKForBSwap &= bitTransformIsCorrectForBSwap(BitProvenance[BitIdx], BitIdx,
DemandedBW);
OKForBitReverse &= bitTransformIsCorrectForBitReverse(BitProvenance[BitIdx],
BitIdx, DemandedBW);
}

Intrinsic::ID Intrin;
if (OKForBSwap && MatchBSwaps)
if (OKForBSwap)
Intrin = Intrinsic::bswap;
else if (OKForBitReverse && MatchBitReversals)
else if (OKForBitReverse)
Intrin = Intrinsic::bitreverse;
else
return false;
Expand Down

0 comments on commit 621c6c8

Please sign in to comment.