Skip to content

Commit f3ffee6

Browse files
authored
[GISel][AArch64] Allow PatLeafs to be imported in GISel which were previously causing warnings (#140935)
Previously PatLeafs could not be imported, causing the following warnings to be emitted when running tblgen with `-warn-on-skipped-patterns:` ``` /work/clean/llvm/lib/Target/AArch64/AArch64InstrInfo.td:2631:1: warning: Skipped pattern: Src pattern child has unsupported predicate def : Pat<(i64 (mul top32Zero:$Rn, top32Zero:$Rm)), ^ ``` These changes allow the patterns to now be imported successfully.
1 parent 2f15637 commit f3ffee6

19 files changed

+465
-480
lines changed

llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ enum {
161161
/// - Pred(2) - The predicate to test
162162
GIM_CheckImmOperandPredicate,
163163

164+
/// Check a leaf predicate on the specified instruction.
165+
/// - InsnID(ULEB128) - Instruction ID
166+
/// - OpIdx(ULEB128) - Operand index
167+
/// - Pred(2) - The predicate to test
168+
GIM_CheckLeafOperandPredicate,
169+
164170
/// Check a memory operation has the specified atomic ordering.
165171
/// - InsnID(ULEB128) - Instruction ID
166172
/// - Ordering(ULEB128) - The AtomicOrdering value
@@ -707,6 +713,12 @@ class GIMatchTableExecutor {
707713
"Subclasses must override this with a tablegen-erated function");
708714
}
709715

716+
virtual bool testMOPredicate_MO(unsigned, const MachineOperand &,
717+
const MatcherState &State) const {
718+
llvm_unreachable(
719+
"Subclasses must override this with a tablegen-erated function");
720+
}
721+
710722
virtual bool testSimplePredicate(unsigned) const {
711723
llvm_unreachable("Subclass does not implement testSimplePredicate!");
712724
}

llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,26 @@ bool GIMatchTableExecutor::executeMatchTable(
410410
return false;
411411
break;
412412
}
413+
case GIM_CheckLeafOperandPredicate: {
414+
uint64_t InsnID = readULEB();
415+
uint64_t OpIdx = readULEB();
416+
uint16_t Predicate = readU16();
417+
DEBUG_WITH_TYPE(TgtExecutor::getName(),
418+
dbgs() << CurrentIdx
419+
<< ": GIM_CheckLeafOperandPredicate(MIs[" << InsnID
420+
<< "]->getOperand(" << OpIdx
421+
<< "), Predicate=" << Predicate << ")\n");
422+
assert(State.MIs[InsnID] != nullptr && "Used insn before defined");
423+
assert(State.MIs[InsnID]->getOperand(OpIdx).isReg() &&
424+
"Expected register operand");
425+
assert(Predicate > GICXXPred_Invalid && "Expected a valid predicate");
426+
MachineOperand &MO = State.MIs[InsnID]->getOperand(OpIdx);
427+
428+
if (!testMOPredicate_MO(Predicate, MO, State))
429+
if (handleReject() == RejectAndGiveUp)
430+
return false;
431+
break;
432+
}
413433
case GIM_CheckIsBuildVectorAllOnes:
414434
case GIM_CheckIsBuildVectorAllZeros: {
415435
uint64_t InsnID = readULEB();

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,9 @@ class OutPatFrag<dag ops, dag frag>
10611061
// PatLeaf's are pattern fragments that have no operands. This is just a helper
10621062
// to define immediates and other common things concisely.
10631063
class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
1064-
: PatFrag<(ops), frag, pred, xform>;
1064+
: PatFrag<(ops), frag, pred, xform> {
1065+
code GISelLeafPredicateCode = ?;
1066+
}
10651067

10661068

10671069
// ImmLeaf is a pattern fragment with a constraint on the immediate. The

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,23 +685,35 @@ defm trunc_masked_scatter_i32 : masked_gather_scatter<trunc_masked_scatter_i32>;
685685
def top16Zero: PatLeaf<(i32 GPR32:$src), [{
686686
return Op.getValueType() == MVT::i32 &&
687687
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(32, 16));
688-
}]>;
688+
}]> {
689+
let GISelLeafPredicateCode = [{
690+
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(32, 16)); }];
691+
}
689692

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

696702
// topbitsallzero - Return true if all bits except the lowest bit are known zero
697703
def topbitsallzero32: PatLeaf<(i32 GPR32:$src), [{
698704
return Op.getValueType() == MVT::i32 &&
699705
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(32, 31));
700-
}]>;
706+
}]> {
707+
let GISelLeafPredicateCode = [{
708+
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(32, 31)); }];
709+
}
701710
def topbitsallzero64: PatLeaf<(i64 GPR64:$src), [{
702711
return Op.getValueType() == MVT::i64 &&
703712
CurDAG->MaskedValueIsZero(Op, APInt::getHighBitsSet(64, 63));
704-
}]>;
713+
}]> {
714+
let GISelLeafPredicateCode = [{
715+
return VT && VT->maskedValueIsZero(Reg, APInt::getHighBitsSet(64, 63)); }];
716+
}
705717

706718
// Node definitions.
707719
// Compare-and-branch

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "MCTargetDesc/AArch64MCTargetDesc.h"
2323
#include "llvm/BinaryFormat/Dwarf.h"
2424
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
25+
#include "llvm/CodeGen/GlobalISel/GISelValueTracking.h"
2526
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
2627
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
2728
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"

0 commit comments

Comments
 (0)