Skip to content

[GISel][AArch64] Allow PatLeafs to be imported in GISel which were previously causing warnings #140935

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ enum {
/// - Pred(2) - The predicate to test
GIM_CheckImmOperandPredicate,

/// Check a leaf predicate on the specified instruction.
/// - InsnID(ULEB128) - Instruction ID
/// - OpIdx(ULEB128) - Operand index
/// - Pred(2) - The predicate to test
GIM_CheckLeafOperandPredicate,

/// Check a memory operation has the specified atomic ordering.
/// - InsnID(ULEB128) - Instruction ID
/// - Ordering(ULEB128) - The AtomicOrdering value
Expand Down Expand Up @@ -707,6 +713,12 @@ class GIMatchTableExecutor {
"Subclasses must override this with a tablegen-erated function");
}

virtual bool testMOPredicate_MO(unsigned, const MachineOperand &,
const MatcherState &State) const {
llvm_unreachable(
"Subclasses must override this with a tablegen-erated function");
}

virtual bool testSimplePredicate(unsigned) const {
llvm_unreachable("Subclass does not implement testSimplePredicate!");
}
Expand Down
20 changes: 20 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@ bool GIMatchTableExecutor::executeMatchTable(
return false;
break;
}
case GIM_CheckLeafOperandPredicate: {
uint64_t InsnID = readULEB();
uint64_t OpIdx = readULEB();
uint16_t Predicate = readU16();
DEBUG_WITH_TYPE(TgtExecutor::getName(),
dbgs() << CurrentIdx
<< ": GIM_CheckLeafOperandPredicate(MIs[" << InsnID
<< "]->getOperand(" << OpIdx
<< "), Predicate=" << Predicate << ")\n");
assert(State.MIs[InsnID] != nullptr && "Used insn before defined");
assert(State.MIs[InsnID]->getOperand(OpIdx).isReg() &&
"Expected register operand");
assert(Predicate > GICXXPred_Invalid && "Expected a valid predicate");
MachineOperand &MO = State.MIs[InsnID]->getOperand(OpIdx);

if (!testMOPredicate_MO(Predicate, MO, State))
if (handleReject() == RejectAndGiveUp)
return false;
break;
}
case GIM_CheckIsBuildVectorAllOnes:
case GIM_CheckIsBuildVectorAllZeros: {
uint64_t InsnID = readULEB();
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Target/TargetSelectionDAG.td
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,9 @@ class OutPatFrag<dag ops, dag frag>
// PatLeaf's are pattern fragments that have no operands. This is just a helper
// to define immediates and other common things concisely.
class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
: PatFrag<(ops), frag, pred, xform>;
: PatFrag<(ops), frag, pred, xform> {
code GISelLeafPredicateCode = ?;
}


// ImmLeaf is a pattern fragment with a constraint on the immediate. The
Expand Down
20 changes: 16 additions & 4 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -685,23 +685,35 @@ defm trunc_masked_scatter_i32 : masked_gather_scatter<trunc_masked_scatter_i32>;
def top16Zero: PatLeaf<(i32 GPR32:$src), [{
return Op.getValueType() == MVT::i32 &&
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(32, 16));
}]>;
}]> {
let GISelLeafPredicateCode = [{
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(32, 16)); }];
}

// top32Zero - answer true if the upper 32 bits of $src are 0, false otherwise
def top32Zero: PatLeaf<(i64 GPR64:$src), [{
return Op.getValueType() == MVT::i64 &&
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(64, 32));
}]>;
}]> {
let GISelLeafPredicateCode = [{
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(64, 32)); }];
}

// topbitsallzero - Return true if all bits except the lowest bit are known zero
def topbitsallzero32: PatLeaf<(i32 GPR32:$src), [{
return Op.getValueType() == MVT::i32 &&
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(32, 31));
}]>;
}]> {
let GISelLeafPredicateCode = [{
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(32, 31)); }];
}
def topbitsallzero64: PatLeaf<(i64 GPR64:$src), [{
return Op.getValueType() == MVT::i64 &&
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(64, 63));
}]>;
}]> {
let GISelLeafPredicateCode = [{
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(64, 63)); }];
}

// Node definitions.
// Compare-and-branch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "MCTargetDesc/AArch64MCTargetDesc.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
#include "llvm/CodeGen/GlobalISel/GISelValueTracking.h"
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
Expand Down
Loading
Loading