Index: llvm/include/llvm/Target/GlobalISel/Combine.td =================================================================== --- llvm/include/llvm/Target/GlobalISel/Combine.td +++ llvm/include/llvm/Target/GlobalISel/Combine.td @@ -416,10 +416,11 @@ // Fold ptr2int(int2ptr(x)) -> x def i2p_to_p2i: GICombineRule< - (defs root:$root, register_matchinfo:$info), - (match (wip_match_opcode G_PTRTOINT):$root, - [{ return Helper.matchCombineP2IToI2P(*${root}, ${info}); }]), - (apply [{ Helper.applyCombineP2IToI2P(*${root}, ${info}); }]) + (defs root:$dst, register_matchinfo:$info), + (match (G_INTTOPTR $t, $ptr), + (G_PTRTOINT $dst, $t):$mi, + [{ ${info} = ${ptr}.getReg(); }]), + (apply [{ Helper.applyCombineP2IToI2P(*${mi}, ${info}); }]) >; // Fold add ptrtoint(x), y -> ptrtoint (ptr_add x), y @@ -529,10 +530,11 @@ // Fold (fneg (fneg x)) -> x. def fneg_fneg_fold: GICombineRule < - (defs root:$root, register_matchinfo:$matchinfo), - (match (wip_match_opcode G_FNEG):$root, - [{ return Helper.matchCombineFNegOfFNeg(*${root}, ${matchinfo}); }]), - (apply [{ return Helper.replaceSingleDefInstWithReg(*${root}, ${matchinfo}); }]) + (defs root:$dst, register_matchinfo:$matchinfo), + (match (G_FNEG $t, $src), + (G_FNEG $dst, $t):$mi, + [{ ${matchinfo} = ${src}.getReg(); }]), + (apply [{ return Helper.replaceSingleDefInstWithReg(*${mi}, ${matchinfo}); }]) >; // Fold (unmerge(merge x, y, z)) -> z, y, z. @@ -554,10 +556,11 @@ // Fold (fabs (fabs x)) -> (fabs x). def fabs_fabs_fold: GICombineRule< - (defs root:$root, register_matchinfo:$matchinfo), - (match (wip_match_opcode G_FABS):$root, - [{ return Helper.matchCombineFAbsOfFAbs(*${root}, ${matchinfo}); }]), - (apply [{ return Helper.replaceSingleDefInstWithReg(*${root}, ${matchinfo}); }]) + (defs root:$dst, register_matchinfo:$matchinfo), + (match (G_FABS $abs, $src), + (G_FABS $dst, $abs):$mi, + [{ ${matchinfo} = ${abs}.getReg(); }]), + (apply [{ return Helper.replaceSingleDefInstWithReg(*${mi}, ${matchinfo}); }]) >; // Fold (fabs (fneg x)) -> (fabs x). Index: llvm/utils/TableGen/GlobalISel/CodeExpansions.h =================================================================== --- llvm/utils/TableGen/GlobalISel/CodeExpansions.h +++ llvm/utils/TableGen/GlobalISel/CodeExpansions.h @@ -24,9 +24,9 @@ public: void declare(StringRef Name, StringRef Expansion) { - bool Inserted = Expansions.try_emplace(Name, Expansion).second; - assert(Inserted && "Declared variable twice"); - (void)Inserted; + // Duplicates are not inserted. The expansion refers to different operands + // but to the same virtual register. + Expansions.try_emplace(Name, Expansion); } std::string lookup(StringRef Variable) const { Index: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp =================================================================== --- llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp +++ llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp @@ -762,17 +762,18 @@ void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode( raw_ostream &OS, StringRef Indent) const { - OS << Indent << "Partition = -1\n" - << Indent << "if (MIs.size() <= NewInstrID) MIs.resize(NewInstrID + 1);\n" + OS << Indent << "Partition = -1;\n" + << Indent << "if (MIs.size() <= " << NewInstrID << ") MIs.resize(" + << (NewInstrID + 1) << ");\n" << Indent << "MIs[" << NewInstrID << "] = nullptr;\n" - << Indent << "if (MIs[" << InstrID << "].getOperand(" << OpIdx - << ").isReg()))\n" + << Indent << "if (MIs[" << InstrID << "]->getOperand(" << OpIdx + << ").isReg())\n" << Indent << " MIs[" << NewInstrID << "] = MRI.getVRegDef(MIs[" << InstrID - << "].getOperand(" << OpIdx << ").getReg()));\n"; + << "]->getOperand(" << OpIdx << ").getReg());\n"; for (const auto &Pair : ResultToPartition) OS << Indent << "if (MIs[" << NewInstrID << "] " - << (Pair.first ? "==" : "!=") + << (Pair.first ? "!=" : "==") << " nullptr) Partition = " << Pair.second << ";\n"; OS << Indent << "if (Partition == -1) return false;\n";