-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[GlobalISel] Introduce G_POISON
#127825
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
base: main
Are you sure you want to change the base?
[GlobalISel] Introduce G_POISON
#127825
Changes from 7 commits
0d07595
a8569f2
59a800d
a8cc507
c6b0e4e
b62284a
2af2004
386e424
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,6 +330,7 @@ bool CombinerHelper::matchCombineConcatVectors( | |
for (const MachineOperand &BuildVecMO : Def->uses()) | ||
Ops.push_back(BuildVecMO.getReg()); | ||
break; | ||
case TargetOpcode::G_POISON: | ||
case TargetOpcode::G_IMPLICIT_DEF: { | ||
LLT OpType = MRI.getType(Reg); | ||
// Keep one undef value for all the undef operands. | ||
|
@@ -454,7 +455,8 @@ bool CombinerHelper::matchCombineShuffleConcat( | |
return false; | ||
} | ||
if (!isLegalOrBeforeLegalizer( | ||
{TargetOpcode::G_IMPLICIT_DEF, {ConcatSrcTy}})) | ||
{TargetOpcode::G_IMPLICIT_DEF, {ConcatSrcTy}}) || | ||
!isLegalOrBeforeLegalizer({TargetOpcode::G_POISON, {ConcatSrcTy}})) | ||
return false; | ||
Ops.push_back(0); | ||
} else if (Mask[i] % ConcatSrcNumElt == 0) { | ||
|
@@ -2732,14 +2734,29 @@ void CombinerHelper::applyCombineTruncOfShift( | |
bool CombinerHelper::matchAnyExplicitUseIsUndef(MachineInstr &MI) const { | ||
return any_of(MI.explicit_uses(), [this](const MachineOperand &MO) { | ||
return MO.isReg() && | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI); | ||
(getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI) || | ||
getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI)); | ||
Comment on lines
+2739
to
+2740
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a fixme? We shouldn't look up copy chains twice just to check 2 opcodes. We should delete getOpcodeDef as a helper, it's not good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! In the next patch I can come up with some helpers where |
||
}); | ||
} | ||
|
||
bool CombinerHelper::matchAnyExplicitUseIsPoison(MachineInstr &MI) const { | ||
return any_of(MI.explicit_uses(), [this](const MachineOperand &MO) { | ||
return MO.isReg() && getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI); | ||
}); | ||
} | ||
|
||
bool CombinerHelper::matchAllExplicitUsesAreUndef(MachineInstr &MI) const { | ||
return all_of(MI.explicit_uses(), [this](const MachineOperand &MO) { | ||
return !MO.isReg() || | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI); | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI) || | ||
getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI); | ||
}); | ||
} | ||
|
||
bool CombinerHelper::matchAllExplicitUsesArePoison(MachineInstr &MI) const { | ||
return all_of(MI.explicit_uses(), [this](const MachineOperand &MO) { | ||
return !MO.isReg() || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't need to check if the operand is a register, but this is consistent with the other cases |
||
getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI); | ||
}); | ||
} | ||
|
||
|
@@ -2752,12 +2769,21 @@ bool CombinerHelper::matchUndefShuffleVectorMask(MachineInstr &MI) const { | |
bool CombinerHelper::matchUndefStore(MachineInstr &MI) const { | ||
assert(MI.getOpcode() == TargetOpcode::G_STORE); | ||
return getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MI.getOperand(0).getReg(), | ||
MRI) || | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MI.getOperand(0).getReg(), | ||
MRI); | ||
} | ||
|
||
bool CombinerHelper::matchPoisonStore(MachineInstr &MI) const { | ||
assert(MI.getOpcode() == TargetOpcode::G_STORE); | ||
return getOpcodeDef(TargetOpcode::G_POISON, MI.getOperand(0).getReg(), MRI); | ||
} | ||
|
||
bool CombinerHelper::matchUndefSelectCmp(MachineInstr &MI) const { | ||
assert(MI.getOpcode() == TargetOpcode::G_SELECT); | ||
return getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MI.getOperand(1).getReg(), | ||
MRI) || | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MI.getOperand(1).getReg(), | ||
MRI); | ||
} | ||
|
||
|
@@ -2991,7 +3017,14 @@ bool CombinerHelper::matchOperandIsUndef(MachineInstr &MI, | |
unsigned OpIdx) const { | ||
MachineOperand &MO = MI.getOperand(OpIdx); | ||
return MO.isReg() && | ||
getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI); | ||
(getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MO.getReg(), MRI) || | ||
getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI)); | ||
} | ||
|
||
bool CombinerHelper::matchOperandIsPoison(MachineInstr &MI, | ||
unsigned OpIdx) const { | ||
MachineOperand &MO = MI.getOperand(OpIdx); | ||
return MO.isReg() && getOpcodeDef(TargetOpcode::G_POISON, MO.getReg(), MRI); | ||
} | ||
|
||
bool CombinerHelper::matchOperandIsKnownToBeAPowerOfTwo(MachineInstr &MI, | ||
|
@@ -3033,6 +3066,12 @@ void CombinerHelper::replaceInstWithUndef(MachineInstr &MI) const { | |
MI.eraseFromParent(); | ||
} | ||
|
||
void CombinerHelper::replaceInstWithPoison(MachineInstr &MI) const { | ||
assert(MI.getNumDefs() == 1 && "Expected only one def?"); | ||
Builder.buildPoison(MI.getOperand(0)); | ||
MI.eraseFromParent(); | ||
} | ||
|
||
bool CombinerHelper::matchSimplifyAddToSub( | ||
MachineInstr &MI, std::tuple<Register, Register> &MatchInfo) const { | ||
Register LHS = MI.getOperand(1).getReg(); | ||
|
@@ -3097,6 +3136,7 @@ bool CombinerHelper::matchCombineInsertVecElts( | |
// If we didn't end in a G_IMPLICIT_DEF and the source is not fully | ||
// overwritten, bail out. | ||
return TmpInst->getOpcode() == TargetOpcode::G_IMPLICIT_DEF || | ||
TmpInst->getOpcode() == TargetOpcode::G_POISON || | ||
all_of(MatchInfo, [](Register Reg) { return !!Reg; }); | ||
} | ||
|
||
|
@@ -3467,12 +3507,13 @@ bool CombinerHelper::matchUseVectorTruncate(MachineInstr &MI, | |
if (I < 2) | ||
return false; | ||
|
||
// Check the remaining source elements are only G_IMPLICIT_DEF | ||
// Check the remaining source elements are only G_IMPLICIT_DEF or G_POISON | ||
for (; I < NumOperands; ++I) { | ||
auto SrcMI = MRI.getVRegDef(BuildMI->getSourceReg(I)); | ||
auto SrcMIOpc = SrcMI->getOpcode(); | ||
|
||
if (SrcMIOpc != TargetOpcode::G_IMPLICIT_DEF) | ||
if (SrcMIOpc != TargetOpcode::G_IMPLICIT_DEF && | ||
SrcMIOpc != TargetOpcode::G_POISON) | ||
return false; | ||
} | ||
|
||
|
@@ -7927,10 +7968,12 @@ bool CombinerHelper::matchShuffleDisjointMask(MachineInstr &MI, | |
auto &Shuffle = cast<GShuffleVector>(MI); | ||
// If any of the two inputs is already undef, don't check the mask again to | ||
// prevent infinite loop | ||
if (getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Shuffle.getSrc1Reg(), MRI)) | ||
if (getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Shuffle.getSrc1Reg(), MRI) || | ||
getOpcodeDef(TargetOpcode::G_POISON, Shuffle.getSrc1Reg(), MRI)) | ||
return false; | ||
|
||
if (getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Shuffle.getSrc2Reg(), MRI)) | ||
if (getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Shuffle.getSrc2Reg(), MRI) || | ||
getOpcodeDef(TargetOpcode::G_POISON, Shuffle.getSrc2Reg(), MRI)) | ||
return false; | ||
|
||
const LLT DstTy = MRI.getType(Shuffle.getReg(0)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond the scope of this patch, but we probably should stop CSEing G_IMPLICIT_DEF, and only do it for G_POISON