Skip to content

Commit

Permalink
[InstCombine] recognizeBSwapOrBitReverseIdiom - merge the regular/tru…
Browse files Browse the repository at this point in the history
…nc+zext paths. NFCI.

There doesn't seem to be any good reason for having a separate path for when we bswap/bitreverse at a smaller size than the destination size - so merge these to make the instruction generation a lot clearer.
  • Loading branch information
RKSimon committed Sep 30, 2020
1 parent 7fcad55 commit c722b32
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions llvm/lib/Transforms/Utils/Local.cpp
Expand Up @@ -3056,25 +3056,26 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
else
return false;

if (ITy != DemandedTy) {
Function *F = Intrinsic::getDeclaration(I->getModule(), Intrin, DemandedTy);
Value *Provider = Res->Provider;
// We may need to truncate the provider.
if (DemandedTy != Provider->getType()) {
auto *Trunc = CastInst::Create(Instruction::Trunc, Provider, DemandedTy,
"trunc", I);
InsertedInsts.push_back(Trunc);
Provider = Trunc;
}
auto *CI = CallInst::Create(F, Provider, "rev", I);
InsertedInsts.push_back(CI);
Function *F = Intrinsic::getDeclaration(I->getModule(), Intrin, DemandedTy);
Value *Provider = Res->Provider;

// We may need to truncate the provider.
if (DemandedTy != Provider->getType()) {
auto *Trunc =
CastInst::Create(Instruction::Trunc, Provider, DemandedTy, "trunc", I);
InsertedInsts.push_back(Trunc);
Provider = Trunc;
}

auto *CI = CallInst::Create(F, Provider, "rev", I);
InsertedInsts.push_back(CI);

// We may need to zeroextend back to the result type.
if (ITy != CI->getType()) {
auto *ExtInst = CastInst::Create(Instruction::ZExt, CI, ITy, "zext", I);
InsertedInsts.push_back(ExtInst);
return true;
}

Function *F = Intrinsic::getDeclaration(I->getModule(), Intrin, ITy);
InsertedInsts.push_back(CallInst::Create(F, Res->Provider, "rev", I));
return true;
}

Expand Down

0 comments on commit c722b32

Please sign in to comment.