Skip to content

Commit c722b32

Browse files
committed
[InstCombine] recognizeBSwapOrBitReverseIdiom - merge the regular/trunc+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.
1 parent 7fcad55 commit c722b32

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,25 +3056,26 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
30563056
else
30573057
return false;
30583058

3059-
if (ITy != DemandedTy) {
3060-
Function *F = Intrinsic::getDeclaration(I->getModule(), Intrin, DemandedTy);
3061-
Value *Provider = Res->Provider;
3062-
// We may need to truncate the provider.
3063-
if (DemandedTy != Provider->getType()) {
3064-
auto *Trunc = CastInst::Create(Instruction::Trunc, Provider, DemandedTy,
3065-
"trunc", I);
3066-
InsertedInsts.push_back(Trunc);
3067-
Provider = Trunc;
3068-
}
3069-
auto *CI = CallInst::Create(F, Provider, "rev", I);
3070-
InsertedInsts.push_back(CI);
3059+
Function *F = Intrinsic::getDeclaration(I->getModule(), Intrin, DemandedTy);
3060+
Value *Provider = Res->Provider;
3061+
3062+
// We may need to truncate the provider.
3063+
if (DemandedTy != Provider->getType()) {
3064+
auto *Trunc =
3065+
CastInst::Create(Instruction::Trunc, Provider, DemandedTy, "trunc", I);
3066+
InsertedInsts.push_back(Trunc);
3067+
Provider = Trunc;
3068+
}
3069+
3070+
auto *CI = CallInst::Create(F, Provider, "rev", I);
3071+
InsertedInsts.push_back(CI);
3072+
3073+
// We may need to zeroextend back to the result type.
3074+
if (ITy != CI->getType()) {
30713075
auto *ExtInst = CastInst::Create(Instruction::ZExt, CI, ITy, "zext", I);
30723076
InsertedInsts.push_back(ExtInst);
3073-
return true;
30743077
}
30753078

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

0 commit comments

Comments
 (0)