Skip to content

[GlobalISel][ARM] Support missing case for G_CONSTANT #80555

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
Feb 7, 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
6 changes: 4 additions & 2 deletions llvm/lib/Target/ARM/ARMInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ def imm_neg_XFORM : SDNodeXForm<imm, [{
def imm_not_XFORM : SDNodeXForm<imm, [{
return CurDAG->getTargetConstant(~(int)N->getZExtValue(), SDLoc(N), MVT::i32);
}]>;
def gi_imm_not_XFORM : GICustomOperandRenderer<"renderInvertedImm">,
GISDNodeXFormEquiv<imm_not_XFORM>;

// asr_imm_XFORM - Returns a shift immediate with bit {5} set to 1
def asr_imm_XFORM : SDNodeXForm<imm, [{
Expand Down Expand Up @@ -830,8 +832,8 @@ def mod_imm : Operand<i32>, ImmLeaf<i32, [{
// instructions, which use mod_imm.

def ModImmNotAsmOperand : AsmOperandClass { let Name = "ModImmNot"; }
def mod_imm_not : Operand<i32>, PatLeaf<(imm), [{
return ARM_AM::getSOImmVal(~(uint32_t)N->getZExtValue()) != -1;
def mod_imm_not : Operand<i32>, ImmLeaf<i32, [{
return ARM_AM::getSOImmVal(~(uint32_t)Imm) != -1;
}], imm_not_XFORM> {
let ParserMatchClass = ModImmNotAsmOperand;
}
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/ARM/ARMInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class ARMInstructionSelector : public InstructionSelector {
int OpIdx = -1) const;
void renderVFPF64Imm(MachineInstrBuilder &New, const MachineInstr &Old,
int OpIdx = -1) const;
void renderInvertedImm(MachineInstrBuilder &MIB, const MachineInstr &MI,
int OpIdx = -1) const;

#define GET_GLOBALISEL_PREDICATES_DECL
#include "ARMGenGlobalISel.inc"
Expand Down Expand Up @@ -835,6 +837,15 @@ void ARMInstructionSelector::renderVFPF64Imm(
NewInstBuilder.addImm(FPImmEncoding);
}

void ARMInstructionSelector::renderInvertedImm(MachineInstrBuilder &MIB,
const MachineInstr &MI,
int OpIdx) const {
assert(MI.getOpcode() == TargetOpcode::G_CONSTANT && OpIdx == -1 &&
"Expected G_CONSTANT");
int64_t CVal = MI.getOperand(1).getCImm()->getSExtValue();
MIB.addImm(~CVal);
}

bool ARMInstructionSelector::select(MachineInstr &I) {
assert(I.getParent() && "Instruction should be in a basic block!");
assert(I.getParent()->getParent() && "Instruction should be in a function!");
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/CodeGen/ARM/GlobalISel/select-const.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
# RUN: llc -mtriple arm-- -mattr=+v6 -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s

---
name: get_inverted
legalized: true
regBankSelected: true
selected: false
tracksRegLiveness: true
registers:
- { id: 0, class: gprb }
body: |
bb.0:
liveins: $r0
; CHECK-LABEL: name: get_inverted
; CHECK: liveins: $r0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[MVNi:%[0-9]+]]:gpr = MVNi 0, 14 /* CC::al */, $noreg, $noreg
; CHECK-NEXT: $r0 = COPY [[MVNi]]
; CHECK-NEXT: MOVPCLR 14 /* CC::al */, $noreg, implicit $r0
%0:gprb(s32) = G_CONSTANT i32 -1
$r0 = COPY %0(s32)
MOVPCLR 14 /* CC::al */, $noreg, implicit $r0

...