Skip to content

Commit 46c05df

Browse files
authored
Apply the AdjustICmpImmAndPred optimization when it results in a one-instruction immediate materialization over a two-instruction materialization. (#83218)
#76460
1 parent 1fbf748 commit 46c05df

File tree

2 files changed

+704
-4
lines changed

2 files changed

+704
-4
lines changed

llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
///
2020
//===----------------------------------------------------------------------===//
2121

22+
#include "AArch64ExpandImm.h"
2223
#include "AArch64GlobalISelUtils.h"
2324
#include "AArch64PerfectShuffle.h"
2425
#include "AArch64Subtarget.h"
@@ -563,7 +564,8 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
563564
auto ValAndVReg = getIConstantVRegValWithLookThrough(RHS, MRI);
564565
if (!ValAndVReg)
565566
return std::nullopt;
566-
uint64_t C = ValAndVReg->Value.getZExtValue();
567+
uint64_t OriginalC = ValAndVReg->Value.getZExtValue();
568+
uint64_t C = OriginalC;
567569
if (isLegalArithImmed(C))
568570
return std::nullopt;
569571

@@ -633,9 +635,20 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P,
633635
// predicate if it is.
634636
if (Size == 32)
635637
C = static_cast<uint32_t>(C);
636-
if (!isLegalArithImmed(C))
637-
return std::nullopt;
638-
return {{C, P}};
638+
if (isLegalArithImmed(C))
639+
return {{C, P}};
640+
641+
auto IsMaterializableInSingleInstruction = [=](uint64_t Imm) {
642+
SmallVector<AArch64_IMM::ImmInsnModel> Insn;
643+
AArch64_IMM::expandMOVImm(Imm, 32, Insn);
644+
return Insn.size() == 1;
645+
};
646+
647+
if (!IsMaterializableInSingleInstruction(OriginalC) &&
648+
IsMaterializableInSingleInstruction(C))
649+
return {{C, P}};
650+
651+
return std::nullopt;
639652
}
640653

641654
/// Determine whether or not it is possible to update the RHS and predicate of

0 commit comments

Comments
 (0)