@@ -1604,6 +1604,148 @@ func.func @func_execute_region_inline_multi_yield() {
16041604
16051605// -----
16061606
1607+ // Test case with single scf.yield op inside execute_region and its operand is defined outside the execute_region op.
1608+ // Make scf.execute_region not to return anything.
1609+
1610+ // CHECK: scf.execute_region no_inline {
1611+ // CHECK: func.call @foo() : () -> ()
1612+ // CHECK: scf.yield
1613+ // CHECK: }
1614+
1615+ module {
1616+ func.func private @foo ()->()
1617+ func.func private @execute_region_yeilding_external_value () -> memref <1 x60 xui8 > {
1618+ %alloc = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1619+ %1 = scf.execute_region -> memref <1 x60 xui8 > no_inline {
1620+ func.call @foo ():()->()
1621+ scf.yield %alloc: memref <1 x60 xui8 >
1622+ }
1623+ return %1 : memref <1 x60 xui8 >
1624+ }
1625+ }
1626+
1627+ // -----
1628+
1629+ // Test case with scf.yield op inside execute_region with multiple operands.
1630+ // One of operands is defined outside the execute_region op.
1631+ // Remove just this operand from the op results.
1632+
1633+ // CHECK: %[[VAL_1:.*]] = scf.execute_region -> memref<1x120xui8> no_inline {
1634+ // CHECK: %[[VAL_2:.*]] = memref.alloc() {alignment = 64 : i64} : memref<1x120xui8>
1635+ // CHECK: func.call @foo() : () -> ()
1636+ // CHECK: scf.yield %[[VAL_2]] : memref<1x120xui8>
1637+ // CHECK: }
1638+ module {
1639+ func.func private @foo ()->()
1640+ func.func private @execute_region_yeilding_external_and_local_values () -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) {
1641+ %alloc = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1642+ %1 , %2 = scf.execute_region -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) no_inline {
1643+ %alloc_1 = memref.alloc () {alignment = 64 : i64 } : memref <1 x120 xui8 >
1644+ func.call @foo ():()->()
1645+ scf.yield %alloc , %alloc_1: memref <1 x60 xui8 >, memref <1 x120 xui8 >
1646+ }
1647+ return %1 , %2 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1648+ }
1649+ }
1650+
1651+ // -----
1652+
1653+ // Test case with multiple scf.yield ops inside execute_region with same operands and those operands are defined outside the execute_region op..
1654+ // Make scf.execute_region not to return anything.
1655+ // scf.yield must remain, cause scf.execute_region can't be empty.
1656+
1657+ // CHECK: scf.execute_region no_inline {
1658+ // CHECK: %[[VAL_3:.*]] = "test.cmp"() : () -> i1
1659+ // CHECK: cf.cond_br %[[VAL_3]], ^bb1, ^bb2
1660+ // CHECK: ^bb1:
1661+ // CHECK: scf.yield
1662+ // CHECK: ^bb2:
1663+ // CHECK: scf.yield
1664+ // CHECK: }
1665+
1666+ module {
1667+ func.func private @foo ()->()
1668+ func.func private @execute_region_multiple_yields_same_operands () -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) {
1669+ %alloc = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1670+ %alloc_1 = memref.alloc () {alignment = 64 : i64 } : memref <1 x120 xui8 >
1671+ %1 , %2 = scf.execute_region -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) no_inline {
1672+ %c = " test.cmp" () : () -> i1
1673+ cf.cond_br %c , ^bb2 , ^bb3
1674+ ^bb2 :
1675+ func.call @foo ():()->()
1676+ scf.yield %alloc , %alloc_1 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1677+ ^bb3 :
1678+ func.call @foo ():()->()
1679+ scf.yield %alloc , %alloc_1 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1680+ }
1681+ return %1 , %2 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1682+ }
1683+ }
1684+
1685+ // -----
1686+
1687+ // Test case with multiple scf.yield ops with at least one different operand, then no change.
1688+
1689+ // CHECK: %[[VAL_3:.*]]:2 = scf.execute_region -> (memref<1x60xui8>, memref<1x120xui8>) no_inline {
1690+ // CHECK: ^bb1:
1691+ // CHECK: scf.yield %{{.*}}, %{{.*}} : memref<1x60xui8>, memref<1x120xui8>
1692+ // CHECK: ^bb2:
1693+ // CHECK: scf.yield %{{.*}}, %{{.*}} : memref<1x60xui8>, memref<1x120xui8>
1694+ // CHECK: }
1695+
1696+ module {
1697+ func.func private @foo ()->()
1698+ func.func private @execute_region_multiple_yields_different_operands () -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) {
1699+ %alloc = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1700+ %alloc_1 = memref.alloc () {alignment = 64 : i64 } : memref <1 x120 xui8 >
1701+ %alloc_2 = memref.alloc () {alignment = 64 : i64 } : memref <1 x120 xui8 >
1702+ %1 , %2 = scf.execute_region -> (memref <1 x60 xui8 >, memref <1 x120 xui8 >) no_inline {
1703+ %c = " test.cmp" () : () -> i1
1704+ cf.cond_br %c , ^bb2 , ^bb3
1705+ ^bb2 :
1706+ func.call @foo ():()->()
1707+ scf.yield %alloc , %alloc_1 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1708+ ^bb3 :
1709+ func.call @foo ():()->()
1710+ scf.yield %alloc , %alloc_2 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1711+ }
1712+ return %1 , %2 : memref <1 x60 xui8 >, memref <1 x120 xui8 >
1713+ }
1714+ }
1715+
1716+ // -----
1717+
1718+ // Test case with multiple scf.yield ops each has different operand.
1719+ // In this case scf.execute_region isn't changed.
1720+
1721+ // CHECK: %[[VAL_2:.*]] = scf.execute_region -> memref<1x60xui8> no_inline {
1722+ // CHECK: ^bb1:
1723+ // CHECK: scf.yield %{{.*}} : memref<1x60xui8>
1724+ // CHECK: ^bb2:
1725+ // CHECK: scf.yield %{{.*}} : memref<1x60xui8>
1726+ // CHECK: }
1727+
1728+ module {
1729+ func.func private @foo ()->()
1730+ func.func private @execute_region_multiple_yields_different_operands () -> (memref <1 x60 xui8 >) {
1731+ %alloc = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1732+ %alloc_1 = memref.alloc () {alignment = 64 : i64 } : memref <1 x60 xui8 >
1733+ %1 = scf.execute_region -> (memref <1 x60 xui8 >) no_inline {
1734+ %c = " test.cmp" () : () -> i1
1735+ cf.cond_br %c , ^bb2 , ^bb3
1736+ ^bb2 :
1737+ func.call @foo ():()->()
1738+ scf.yield %alloc : memref <1 x60 xui8 >
1739+ ^bb3 :
1740+ func.call @foo ():()->()
1741+ scf.yield %alloc_1 : memref <1 x60 xui8 >
1742+ }
1743+ return %1 : memref <1 x60 xui8 >
1744+ }
1745+ }
1746+
1747+ // -----
1748+
16071749// CHECK-LABEL: func @canonicalize_parallel_insert_slice_indices(
16081750// CHECK-SAME: %[[arg0:.*]]: tensor<1x5xf32>, %[[arg1:.*]]: tensor<?x?xf32>
16091751func.func @canonicalize_parallel_insert_slice_indices (
0 commit comments