@@ -103,22 +103,25 @@ func private @side_effect()
103
103
func @one_unused (%cond: i1 ) -> (index ) {
104
104
%c0 = constant 0 : index
105
105
%c1 = constant 1 : index
106
+ %c2 = constant 2 : index
107
+ %c3 = constant 3 : index
106
108
%0 , %1 = scf.if %cond -> (index , index ) {
107
109
call @side_effect () : () -> ()
108
110
scf.yield %c0 , %c1 : index , index
109
111
} else {
110
- scf.yield %c0 , %c1 : index , index
112
+ scf.yield %c2 , %c3 : index , index
111
113
}
112
114
return %1 : index
113
115
}
114
116
115
117
// CHECK-LABEL: func @one_unused
116
118
// CHECK: [[C0:%.*]] = constant 1 : index
119
+ // CHECK: [[C3:%.*]] = constant 3 : index
117
120
// CHECK: [[V0:%.*]] = scf.if %{{.*}} -> (index) {
118
121
// CHECK: call @side_effect() : () -> ()
119
122
// CHECK: scf.yield [[C0]] : index
120
123
// CHECK: } else
121
- // CHECK: scf.yield [[C0 ]] : index
124
+ // CHECK: scf.yield [[C3 ]] : index
122
125
// CHECK: }
123
126
// CHECK: return [[V0]] : index
124
127
@@ -128,12 +131,14 @@ func private @side_effect()
128
131
func @nested_unused (%cond1: i1 , %cond2: i1 ) -> (index ) {
129
132
%c0 = constant 0 : index
130
133
%c1 = constant 1 : index
134
+ %c2 = constant 2 : index
135
+ %c3 = constant 3 : index
131
136
%0 , %1 = scf.if %cond1 -> (index , index ) {
132
137
%2 , %3 = scf.if %cond2 -> (index , index ) {
133
138
call @side_effect () : () -> ()
134
139
scf.yield %c0 , %c1 : index , index
135
140
} else {
136
- scf.yield %c0 , %c1 : index , index
141
+ scf.yield %c2 , %c3 : index , index
137
142
}
138
143
scf.yield %2 , %3 : index , index
139
144
} else {
@@ -144,12 +149,13 @@ func @nested_unused(%cond1: i1, %cond2: i1) -> (index) {
144
149
145
150
// CHECK-LABEL: func @nested_unused
146
151
// CHECK: [[C0:%.*]] = constant 1 : index
152
+ // CHECK: [[C3:%.*]] = constant 3 : index
147
153
// CHECK: [[V0:%.*]] = scf.if {{.*}} -> (index) {
148
154
// CHECK: [[V1:%.*]] = scf.if {{.*}} -> (index) {
149
155
// CHECK: call @side_effect() : () -> ()
150
156
// CHECK: scf.yield [[C0]] : index
151
157
// CHECK: } else
152
- // CHECK: scf.yield [[C0 ]] : index
158
+ // CHECK: scf.yield [[C3 ]] : index
153
159
// CHECK: }
154
160
// CHECK: scf.yield [[V1]] : index
155
161
// CHECK: } else
@@ -610,3 +616,111 @@ func @matmul_on_tensors(%t0: tensor<32x1024xf32>, %t1: tensor<1024x1024xf32>) ->
610
616
%res = subtensor_insert %2 into %t1 [0 , 0 ] [32 , 1024 ] [1 , 1 ] : tensor <32 x1024 xf32 > into tensor <1024 x1024 xf32 >
611
617
return %res : tensor <1024 x1024 xf32 >
612
618
}
619
+
620
+
621
+
622
+ // CHECK-LABEL: @cond_prop
623
+ func @cond_prop (%arg0 : i1 ) -> index {
624
+ %c1 = constant 1 : index
625
+ %c2 = constant 2 : index
626
+ %c3 = constant 3 : index
627
+ %c4 = constant 4 : index
628
+ %res = scf.if %arg0 -> index {
629
+ %res1 = scf.if %arg0 -> index {
630
+ %v1 = " test.get_some_value" () : () -> i32
631
+ scf.yield %c1 : index
632
+ } else {
633
+ %v2 = " test.get_some_value" () : () -> i32
634
+ scf.yield %c2 : index
635
+ }
636
+ scf.yield %res1 : index
637
+ } else {
638
+ %res2 = scf.if %arg0 -> index {
639
+ %v3 = " test.get_some_value" () : () -> i32
640
+ scf.yield %c3 : index
641
+ } else {
642
+ %v4 = " test.get_some_value" () : () -> i32
643
+ scf.yield %c4 : index
644
+ }
645
+ scf.yield %res2 : index
646
+ }
647
+ return %res : index
648
+ }
649
+ // CHECK-DAG: %[[c1:.+]] = constant 1 : index
650
+ // CHECK-DAG: %[[c4:.+]] = constant 4 : index
651
+ // CHECK-NEXT: %[[if:.+]] = scf.if %arg0 -> (index) {
652
+ // CHECK-NEXT: %{{.+}} = "test.get_some_value"() : () -> i32
653
+ // CHECK-NEXT: scf.yield %[[c1]] : index
654
+ // CHECK-NEXT: } else {
655
+ // CHECK-NEXT: %{{.+}} = "test.get_some_value"() : () -> i32
656
+ // CHECK-NEXT: scf.yield %[[c4]] : index
657
+ // CHECK-NEXT: }
658
+ // CHECK-NEXT: return %[[if]] : index
659
+ // CHECK-NEXT:}
660
+
661
+ // CHECK-LABEL: @replace_if_with_cond1
662
+ func @replace_if_with_cond1 (%arg0 : i1 ) -> (i32 , i1 ) {
663
+ %true = constant true
664
+ %false = constant false
665
+ %res:2 = scf.if %arg0 -> (i32 , i1 ) {
666
+ %v = " test.get_some_value" () : () -> i32
667
+ scf.yield %v , %true : i32 , i1
668
+ } else {
669
+ %v2 = " test.get_some_value" () : () -> i32
670
+ scf.yield %v2 , %false : i32 , i1
671
+ }
672
+ return %res#0 , %res#1 : i32 , i1
673
+ }
674
+ // CHECK-NEXT: %[[if:.+]] = scf.if %arg0 -> (i32) {
675
+ // CHECK-NEXT: %[[sv1:.+]] = "test.get_some_value"() : () -> i32
676
+ // CHECK-NEXT: scf.yield %[[sv1]] : i32
677
+ // CHECK-NEXT: } else {
678
+ // CHECK-NEXT: %[[sv2:.+]] = "test.get_some_value"() : () -> i32
679
+ // CHECK-NEXT: scf.yield %[[sv2]] : i32
680
+ // CHECK-NEXT: }
681
+ // CHECK-NEXT: return %[[if]], %arg0 : i32, i1
682
+
683
+ // CHECK-LABEL: @replace_if_with_cond2
684
+ func @replace_if_with_cond2 (%arg0 : i1 ) -> (i32 , i1 ) {
685
+ %true = constant true
686
+ %false = constant false
687
+ %res:2 = scf.if %arg0 -> (i32 , i1 ) {
688
+ %v = " test.get_some_value" () : () -> i32
689
+ scf.yield %v , %false : i32 , i1
690
+ } else {
691
+ %v2 = " test.get_some_value" () : () -> i32
692
+ scf.yield %v2 , %true : i32 , i1
693
+ }
694
+ return %res#0 , %res#1 : i32 , i1
695
+ }
696
+ // CHECK-NEXT: %true = constant true
697
+ // CHECK-NEXT: %[[toret:.+]] = xor %arg0, %true : i1
698
+ // CHECK-NEXT: %[[if:.+]] = scf.if %arg0 -> (i32) {
699
+ // CHECK-NEXT: %[[sv1:.+]] = "test.get_some_value"() : () -> i32
700
+ // CHECK-NEXT: scf.yield %[[sv1]] : i32
701
+ // CHECK-NEXT: } else {
702
+ // CHECK-NEXT: %[[sv2:.+]] = "test.get_some_value"() : () -> i32
703
+ // CHECK-NEXT: scf.yield %[[sv2]] : i32
704
+ // CHECK-NEXT: }
705
+ // CHECK-NEXT: return %[[if]], %[[toret]] : i32, i1
706
+
707
+
708
+ // CHECK-LABEL: @replace_if_with_cond3
709
+ func @replace_if_with_cond3 (%arg0 : i1 , %arg2: i64 ) -> (i32 , i64 ) {
710
+ %res:2 = scf.if %arg0 -> (i32 , i64 ) {
711
+ %v = " test.get_some_value" () : () -> i32
712
+ scf.yield %v , %arg2 : i32 , i64
713
+ } else {
714
+ %v2 = " test.get_some_value" () : () -> i32
715
+ scf.yield %v2 , %arg2 : i32 , i64
716
+ }
717
+ return %res#0 , %res#1 : i32 , i64
718
+ }
719
+ // CHECK-NEXT: %[[if:.+]] = scf.if %arg0 -> (i32) {
720
+ // CHECK-NEXT: %[[sv1:.+]] = "test.get_some_value"() : () -> i32
721
+ // CHECK-NEXT: scf.yield %[[sv1]] : i32
722
+ // CHECK-NEXT: } else {
723
+ // CHECK-NEXT: %[[sv2:.+]] = "test.get_some_value"() : () -> i32
724
+ // CHECK-NEXT: scf.yield %[[sv2]] : i32
725
+ // CHECK-NEXT: }
726
+ // CHECK-NEXT: return %[[if]], %arg1 : i32, i64
0 commit comments