@@ -1687,35 +1687,29 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
1687
1687
//
1688
1688
IRInst* insertBeforeInst = parent->getFirstChild ();
1689
1689
1690
- // Hoistable instructions are always "ordinary"
1691
- // instructions, so they need to come after
1692
- // any parameters of the parent.
1693
- //
1694
- while (insertBeforeInst && insertBeforeInst->getOp () == kIROp_Param )
1695
- insertBeforeInst = insertBeforeInst->getNextInst ();
1696
-
1697
1690
if (inst->getOp () == kIROp_WitnessTable )
1698
1691
{
1699
1692
SLANG_ASSERT (getIROpInfo (kIROp_WitnessTable ).isHoistable ());
1700
1693
1701
- // WitnessTable can refer to IRSpecialize from its WitnessTableEntry children. In this case,
1702
- // specialize insts must be cloned before the WitnessTable. Similar an WitnessTables can
1703
- // have depdency to another WitnessTable.
1694
+ // Because IRWitnessTable is Hoistable, do not move when
1695
+ // it is already a child of the parent.
1704
1696
//
1705
- for (IRInst* iter = insertBeforeInst; iter;)
1706
- {
1707
- bool mayHaveDependency = false ;
1708
- switch (iter->getOp ())
1709
- {
1710
- case kIROp_Specialize :
1711
- case kIROp_WitnessTable :
1712
- mayHaveDependency = true ;
1713
- break ;
1714
- }
1697
+ if (parent == inst->parent )
1698
+ return ;
1715
1699
1716
- iter = iter->getNextInst ();
1717
- if (mayHaveDependency)
1718
- insertBeforeInst = iter;
1700
+ // For the rest of the cases, IRWitnessTable goes to the
1701
+ // end of the list.
1702
+ insertBeforeInst = nullptr ;
1703
+ }
1704
+ else
1705
+ {
1706
+ // Hoistable instructions are always "ordinary"
1707
+ // instructions, so they need to come after
1708
+ // any parameters of the parent.
1709
+ //
1710
+ while (insertBeforeInst && insertBeforeInst->getOp () == kIROp_Param )
1711
+ {
1712
+ insertBeforeInst = insertBeforeInst->getNextInst ();
1719
1713
}
1720
1714
}
1721
1715
@@ -4634,11 +4628,13 @@ void addGlobalValue(IRBuilder* builder, IRInst* value)
4634
4628
parent = builder->getModule ()->getModuleInst ();
4635
4629
}
4636
4630
4637
- // If the value is already in the parent, keep it as-is. Because WitnessTable is Hoistable, the
4638
- // parent can have only one instance of this WitnessTable. The order among siblings should
4639
- // remain because the later siblings may have dependency to the earlier siblings.
4631
+ // If the value is already in the parent, keep it as-is.
4632
+ // Because WitnessTable is Hoistable, the parent can have
4633
+ // only one instance of this WitnessTable. The order among
4634
+ // siblings should remain because the later siblings may
4635
+ // have dependency to the earlier siblings.
4640
4636
//
4641
- if (parent == value->parent )
4637
+ if (parent == value->parent && value-> getOp () == kIROp_WitnessTable )
4642
4638
{
4643
4639
SLANG_ASSERT (getIROpInfo (kIROp_WitnessTable ).isHoistable ());
4644
4640
return ;
0 commit comments