Skip to content

Apply the AdjustICmpImmAndPred optimization when it results in a one-instruction immediate materialization over a two-instruction materialization. #83218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
///
//===----------------------------------------------------------------------===//

#include "AArch64ExpandImm.h"
#include "AArch64GlobalISelUtils.h"
#include "AArch64PerfectShuffle.h"
#include "AArch64Subtarget.h"
Expand Down Expand Up @@ -563,7 +564,8 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
auto ValAndVReg = getIConstantVRegValWithLookThrough(RHS, MRI);
if (!ValAndVReg)
return std::nullopt;
uint64_t C = ValAndVReg->Value.getZExtValue();
uint64_t OriginalC = ValAndVReg->Value.getZExtValue();
uint64_t C = OriginalC;
if (isLegalArithImmed(C))
return std::nullopt;

Expand Down Expand Up @@ -633,9 +635,20 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
// predicate if it is.
if (Size == 32)
C = static_cast<uint32_t>(C);
if (!isLegalArithImmed(C))
return std::nullopt;
return {{C, P}};
if (isLegalArithImmed(C))
return {{C, P}};

auto IsMaterializableInSingleInstruction = [=](uint64_t Imm) {
SmallVector<AArch64_IMM::ImmInsnModel> Insn;
AArch64_IMM::expandMOVImm(Imm, 32, Insn);
return Insn.size() == 1;
};

if (!IsMaterializableInSingleInstruction(OriginalC) &&
IsMaterializableInSingleInstruction(C))
return {{C, P}};

return std::nullopt;
}

/// Determine whether or not it is possible to update the RHS and predicate of
Expand Down
Loading
Loading