@@ -1517,7 +1517,7 @@ static bool ir_may_promote_f2d(ir_ctx *ctx, ir_ref ref)
1517
1517
return 0 ;
1518
1518
}
1519
1519
1520
- static ir_ref ir_promote_d2f (ir_ctx * ctx , ir_ref ref , ir_ref use )
1520
+ static ir_ref ir_promote_d2f (ir_ctx * ctx , ir_ref ref , ir_ref use , ir_bitqueue * worklist )
1521
1521
{
1522
1522
ir_insn * insn = & ctx -> ir_base [ref ];
1523
1523
uint32_t count ;
@@ -1526,6 +1526,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
1526
1526
if (IR_IS_CONST_REF (ref )) {
1527
1527
return ir_const_float (ctx , (float )insn -> val .d );
1528
1528
} else {
1529
+ ir_bitqueue_add (worklist , ref );
1529
1530
switch (insn -> op ) {
1530
1531
case IR_FP2FP :
1531
1532
count = ctx -> use_lists [ref ].count ;
@@ -1555,7 +1556,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
1555
1556
// return ref;
1556
1557
case IR_NEG :
1557
1558
case IR_ABS :
1558
- insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref );
1559
+ insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref , worklist );
1559
1560
insn -> type = IR_FLOAT ;
1560
1561
return ref ;
1561
1562
case IR_ADD :
@@ -1565,10 +1566,10 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
1565
1566
case IR_MIN :
1566
1567
case IR_MAX :
1567
1568
if (insn -> op1 == insn -> op2 ) {
1568
- insn -> op2 = insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref );
1569
+ insn -> op2 = insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref , worklist );
1569
1570
} else {
1570
- insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref );
1571
- insn -> op2 = ir_promote_d2f (ctx , insn -> op2 , ref );
1571
+ insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , ref , worklist );
1572
+ insn -> op2 = ir_promote_d2f (ctx , insn -> op2 , ref , worklist );
1572
1573
}
1573
1574
insn -> type = IR_FLOAT ;
1574
1575
return ref ;
@@ -1580,7 +1581,7 @@ static ir_ref ir_promote_d2f(ir_ctx *ctx, ir_ref ref, ir_ref use)
1580
1581
return ref ;
1581
1582
}
1582
1583
1583
- static ir_ref ir_promote_f2d (ir_ctx * ctx , ir_ref ref , ir_ref use )
1584
+ static ir_ref ir_promote_f2d (ir_ctx * ctx , ir_ref ref , ir_ref use , ir_bitqueue * worklist )
1584
1585
{
1585
1586
ir_insn * insn = & ctx -> ir_base [ref ];
1586
1587
uint32_t count ;
@@ -1590,6 +1591,7 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
1590
1591
if (IR_IS_CONST_REF (ref )) {
1591
1592
return ir_const_double (ctx , (double )insn -> val .f );
1592
1593
} else {
1594
+ ir_bitqueue_add (worklist , ref );
1593
1595
switch (insn -> op ) {
1594
1596
case IR_FP2FP :
1595
1597
count = ctx -> use_lists [ref ].count ;
@@ -1628,7 +1630,7 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
1628
1630
return ref ;
1629
1631
case IR_NEG :
1630
1632
case IR_ABS :
1631
- insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref );
1633
+ insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref , worklist );
1632
1634
insn -> type = IR_DOUBLE ;
1633
1635
return ref ;
1634
1636
case IR_ADD :
@@ -1638,10 +1640,10 @@ static ir_ref ir_promote_f2d(ir_ctx *ctx, ir_ref ref, ir_ref use)
1638
1640
case IR_MIN :
1639
1641
case IR_MAX :
1640
1642
if (insn -> op1 == insn -> op2 ) {
1641
- insn -> op2 = insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref );
1643
+ insn -> op2 = insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref , worklist );
1642
1644
} else {
1643
- insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref );
1644
- insn -> op2 = ir_promote_f2d (ctx , insn -> op2 , ref );
1645
+ insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , ref , worklist );
1646
+ insn -> op2 = ir_promote_f2d (ctx , insn -> op2 , ref , worklist );
1645
1647
}
1646
1648
insn -> type = IR_DOUBLE ;
1647
1649
return ref ;
@@ -1707,7 +1709,7 @@ static bool ir_may_promote_trunc(ir_ctx *ctx, ir_type type, ir_ref ref)
1707
1709
}
1708
1710
}
1709
1711
}
1710
- for (p = insn -> ops + 1 , n = insn -> inputs_count - 1 ; n > 0 ; p ++ , n -- ) {
1712
+ for (p = insn -> ops + 2 , n = insn -> inputs_count - 1 ; n > 0 ; p ++ , n -- ) {
1711
1713
input = * p ;
1712
1714
if (input != ref ) {
1713
1715
if (!ir_may_promote_trunc (ctx , type , input )) {
@@ -1723,7 +1725,7 @@ static bool ir_may_promote_trunc(ir_ctx *ctx, ir_type type, ir_ref ref)
1723
1725
return 0 ;
1724
1726
}
1725
1727
1726
- static ir_ref ir_promote_i2i (ir_ctx * ctx , ir_type type , ir_ref ref , ir_ref use )
1728
+ static ir_ref ir_promote_i2i (ir_ctx * ctx , ir_type type , ir_ref ref , ir_ref use , ir_bitqueue * worklist )
1727
1729
{
1728
1730
ir_insn * insn = & ctx -> ir_base [ref ];
1729
1731
uint32_t count ;
@@ -1732,6 +1734,7 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
1732
1734
if (IR_IS_CONST_REF (ref )) {
1733
1735
return ir_const (ctx , insn -> val , type );
1734
1736
} else {
1737
+ ir_bitqueue_add (worklist , ref );
1735
1738
switch (insn -> op ) {
1736
1739
case IR_ZEXT :
1737
1740
case IR_SEXT :
@@ -1776,7 +1779,7 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
1776
1779
case IR_NEG :
1777
1780
case IR_ABS :
1778
1781
case IR_NOT :
1779
- insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref );
1782
+ insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref , worklist );
1780
1783
insn -> type = type ;
1781
1784
return ref ;
1782
1785
case IR_ADD :
@@ -1789,10 +1792,10 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
1789
1792
case IR_XOR :
1790
1793
case IR_SHL :
1791
1794
if (insn -> op1 == insn -> op2 ) {
1792
- insn -> op2 = insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref );
1795
+ insn -> op2 = insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref , worklist );
1793
1796
} else {
1794
- insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref );
1795
- insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref );
1797
+ insn -> op1 = ir_promote_i2i (ctx , type , insn -> op1 , ref , worklist );
1798
+ insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref , worklist );
1796
1799
}
1797
1800
insn -> type = type ;
1798
1801
return ref ;
@@ -1804,18 +1807,18 @@ static ir_ref ir_promote_i2i(ir_ctx *ctx, ir_type type, ir_ref ref, ir_ref use)
1804
1807
// TODO: ???
1805
1808
case IR_COND :
1806
1809
if (insn -> op2 == insn -> op3 ) {
1807
- insn -> op3 = insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref );
1810
+ insn -> op3 = insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref , worklist );
1808
1811
} else {
1809
- insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref );
1810
- insn -> op3 = ir_promote_i2i (ctx , type , insn -> op3 , ref );
1812
+ insn -> op2 = ir_promote_i2i (ctx , type , insn -> op2 , ref , worklist );
1813
+ insn -> op3 = ir_promote_i2i (ctx , type , insn -> op3 , ref , worklist );
1811
1814
}
1812
1815
insn -> type = type ;
1813
1816
return ref ;
1814
1817
case IR_PHI :
1815
- for (p = insn -> ops + 1 , n = insn -> inputs_count - 1 ; n > 0 ; p ++ , n -- ) {
1818
+ for (p = insn -> ops + 2 , n = insn -> inputs_count - 1 ; n > 0 ; p ++ , n -- ) {
1816
1819
input = * p ;
1817
1820
if (input != ref ) {
1818
- * p = ir_promote_i2i (ctx , type , input , ref );
1821
+ * p = ir_promote_i2i (ctx , type , input , ref , worklist );
1819
1822
}
1820
1823
}
1821
1824
insn -> type = type ;
@@ -1906,7 +1909,7 @@ static uint32_t _ir_estimated_control(ir_ctx *ctx, ir_ref val)
1906
1909
}
1907
1910
1908
1911
IR_ASSERT (ir_op_flags [insn -> op ] & IR_OP_FLAG_DATA );
1909
- if (IR_OPND_KIND (ir_op_flags [insn -> op ], 1 ) & IR_OPND_CONTROL_DEP ) {
1912
+ if (IR_OPND_KIND (ir_op_flags [insn -> op ], 1 ) == IR_OPND_CONTROL_DEP ) {
1910
1913
return insn -> op1 ;
1911
1914
}
1912
1915
@@ -3479,14 +3482,14 @@ void ir_iter_opt(ir_ctx *ctx, ir_bitqueue *worklist)
3479
3482
case IR_FP2FP :
3480
3483
if (insn -> type == IR_FLOAT ) {
3481
3484
if (ir_may_promote_d2f (ctx , insn -> op1 )) {
3482
- ir_ref ref = ir_promote_d2f (ctx , insn -> op1 , i );
3485
+ ir_ref ref = ir_promote_d2f (ctx , insn -> op1 , i , worklist );
3483
3486
insn -> op1 = ref ;
3484
3487
ir_iter_replace_insn (ctx , i , ref , worklist );
3485
3488
break ;
3486
3489
}
3487
3490
} else {
3488
3491
if (ir_may_promote_f2d (ctx , insn -> op1 )) {
3489
- ir_ref ref = ir_promote_f2d (ctx , insn -> op1 , i );
3492
+ ir_ref ref = ir_promote_f2d (ctx , insn -> op1 , i , worklist );
3490
3493
insn -> op1 = ref ;
3491
3494
ir_iter_replace_insn (ctx , i , ref , worklist );
3492
3495
break ;
@@ -3496,17 +3499,17 @@ void ir_iter_opt(ir_ctx *ctx, ir_bitqueue *worklist)
3496
3499
case IR_FP2INT :
3497
3500
if (ctx -> ir_base [insn -> op1 ].type == IR_DOUBLE ) {
3498
3501
if (ir_may_promote_d2f (ctx , insn -> op1 )) {
3499
- insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , i );
3502
+ insn -> op1 = ir_promote_d2f (ctx , insn -> op1 , i , worklist );
3500
3503
}
3501
3504
} else {
3502
3505
if (ir_may_promote_f2d (ctx , insn -> op1 )) {
3503
- insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , i );
3506
+ insn -> op1 = ir_promote_f2d (ctx , insn -> op1 , i , worklist );
3504
3507
}
3505
3508
}
3506
3509
goto folding ;
3507
3510
case IR_TRUNC :
3508
3511
if (ir_may_promote_trunc (ctx , insn -> type , insn -> op1 )) {
3509
- ir_ref ref = ir_promote_i2i (ctx , insn -> type , insn -> op1 , i );
3512
+ ir_ref ref = ir_promote_i2i (ctx , insn -> type , insn -> op1 , i , worklist );
3510
3513
insn -> op1 = ref ;
3511
3514
ir_iter_replace_insn (ctx , i , ref , worklist );
3512
3515
break ;
0 commit comments