[AArch64, X86] Guard against both instrs being wild cards

If both instrs are wild cards, the result can be a crash.

llvm-svn: 295776
This commit is contained in:
Evandro Menezes 2017-02-21 22:16:11 +00:00
parent bc9a13db0e
commit b9b7f4b8d3
2 changed files with 12 additions and 10 deletions

View File

@ -34,12 +34,13 @@ static bool shouldScheduleAdjacent(const AArch64InstrInfo &TII,
const AArch64Subtarget &ST,
const MachineInstr *First,
const MachineInstr *Second) {
assert((First || Second) && "At least one instr must be specified");
unsigned FirstOpcode =
First ? First->getOpcode()
: static_cast<unsigned>(AArch64::INSTRUCTION_LIST_END);
First ? First->getOpcode()
: static_cast<unsigned>(AArch64::INSTRUCTION_LIST_END);
unsigned SecondOpcode =
Second ? Second->getOpcode()
: static_cast<unsigned>(AArch64::INSTRUCTION_LIST_END);
Second ? Second->getOpcode()
: static_cast<unsigned>(AArch64::INSTRUCTION_LIST_END);
if (ST.hasArithmeticBccFusion())
// Fuse CMN, CMP, TST followed by Bcc.

View File

@ -44,12 +44,13 @@ static bool shouldScheduleAdjacent(const X86Subtarget &ST,
FuseInc
} FuseKind;
assert((First || Second) && "At least one instr must be specified");
unsigned FirstOpcode = First
? First->getOpcode()
: static_cast<unsigned>(X86::INSTRUCTION_LIST_END);
unsigned SecondOpcode =
Second ? Second->getOpcode()
: static_cast<unsigned>(X86::INSTRUCTION_LIST_END);
? First->getOpcode()
: static_cast<unsigned>(X86::INSTRUCTION_LIST_END);
unsigned SecondOpcode = Second
? Second->getOpcode()
: static_cast<unsigned>(X86::INSTRUCTION_LIST_END);
switch (SecondOpcode) {
default:
@ -215,7 +216,7 @@ void X86MacroFusion::apply(ScheduleDAGInstrs *DAGInstrs) {
// For now, assume targets can only fuse with the branch.
SUnit &ExitSU = DAG->ExitSU;
MachineInstr *Branch = ExitSU.getInstr();
if (!shouldScheduleAdjacent(ST, nullptr, Branch))
if (!Branch || !shouldScheduleAdjacent(ST, nullptr, Branch))
return;
for (SDep &PredDep : ExitSU.Preds) {