@@ -1096,6 +1096,132 @@ bb4(%31 : $Builtin.Int32):
1096
1096
return %32 : $Int32
1097
1097
}
1098
1098
1099
+ // SIL pattern for :
1100
+ // func hoist_new_ind_pattern1(_ a : [Int]) {
1101
+ // for i in 0...4 {
1102
+ // ...a[i]...
1103
+ // }
1104
+ // }
1105
+ // Bounds check for the array should be hoisted out of the loop
1106
+ //
1107
+ // RANGECHECK-LABEL: sil @hoist_new_ind_pattern1 :
1108
+ // RANGECHECK: [[CB:%.*]] = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1109
+ // RANGECHECK: bb1
1110
+ // RANGECHECK-NOT: apply [[CB]]
1111
+ // RANGECHECK-LABEL: } // end sil function 'hoist_new_ind_pattern1'
1112
+ sil @hoist_new_ind_pattern1 : $@convention(thin) (@owned ArrayInt) -> () {
1113
+ bb0(%0 : $ArrayInt):
1114
+ %minus1 = integer_literal $Builtin.Int1, -1
1115
+ %true = struct $Bool(%minus1 : $Builtin.Int1)
1116
+ %zero = integer_literal $Builtin.Int32, 0
1117
+ %int0 = struct $Int32 (%zero : $Builtin.Int32)
1118
+ %one = integer_literal $Builtin.Int32, 1
1119
+ %four = integer_literal $Builtin.Int32, 4
1120
+ %intfour = struct $Int32 (%four : $Builtin.Int32)
1121
+ %cb = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1122
+ apply %cb(%int0, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1123
+ br bb1(%zero : $Builtin.Int32)
1124
+
1125
+ bb1(%4 : $Builtin.Int32):
1126
+ %5 = builtin "sadd_with_overflow_Int32"(%4 : $Builtin.Int32, %one : $Builtin.Int32, %minus1 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
1127
+ %6 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 0
1128
+ %7 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 1
1129
+ %8 = struct $Int32 (%6 : $Builtin.Int32)
1130
+ %9 = builtin "cmp_eq_Int32"(%6 : $Builtin.Int32, %four : $Builtin.Int32) : $Builtin.Int1
1131
+ apply %cb(%8, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1132
+ cond_br %9, bb3, bb2
1133
+
1134
+ bb2:
1135
+ br bb1(%6 : $Builtin.Int32)
1136
+
1137
+ bb3:
1138
+ %t = tuple ()
1139
+ return %t : $()
1140
+ }
1141
+
1142
+ // Currently this is not optimized because the induction var increment is 2
1143
+ // Support for this can be added by updating induction variable analysis
1144
+ // RANGECHECK-LABEL: sil @hoist_new_ind_pattern2 :
1145
+ // RANGECHECK: [[CB:%.*]] = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1146
+ // RANGECHECK: bb1
1147
+ // RANGECHECK: apply [[CB]]
1148
+ // RANGECHECK-LABEL: } // end sil function 'hoist_new_ind_pattern2'
1149
+ sil @hoist_new_ind_pattern2 : $@convention(thin) (@owned ArrayInt) -> () {
1150
+ bb0(%0 : $ArrayInt):
1151
+ %minus1 = integer_literal $Builtin.Int1, -1
1152
+ %true = struct $Bool(%minus1 : $Builtin.Int1)
1153
+ %zero = integer_literal $Builtin.Int32, 0
1154
+ %int0 = struct $Int32 (%zero : $Builtin.Int32)
1155
+ %two = integer_literal $Builtin.Int32, 2
1156
+ %four = integer_literal $Builtin.Int32, 4
1157
+ %intfour = struct $Int32 (%four : $Builtin.Int32)
1158
+ %cb = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1159
+ apply %cb(%int0, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1160
+ br bb1(%zero : $Builtin.Int32)
1161
+
1162
+ bb1(%4 : $Builtin.Int32):
1163
+ %5 = builtin "sadd_with_overflow_Int32"(%4 : $Builtin.Int32, %two : $Builtin.Int32, %minus1 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
1164
+ %6 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 0
1165
+ %7 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 1
1166
+ %8 = struct $Int32 (%6 : $Builtin.Int32)
1167
+ %9 = builtin "cmp_eq_Int32"(%6 : $Builtin.Int32, %four : $Builtin.Int32) : $Builtin.Int1
1168
+ apply %cb(%8, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1169
+ cond_br %9, bb3, bb2
1170
+
1171
+ bb2:
1172
+ br bb1(%6 : $Builtin.Int32)
1173
+
1174
+ bb3:
1175
+ %t = tuple ()
1176
+ return %t : $()
1177
+ }
1178
+
1179
+ // This is currently not optimized because access function is not recognized
1180
+ // SIL pattern for :
1181
+ // for var index in 0...24
1182
+ // {
1183
+ // ...a[index + index]...
1184
+ // }
1185
+ //
1186
+ // RANGECHECK-LABEL: sil @hoist_new_ind_pattern3 :
1187
+ // RANGECHECK: [[CB:%.*]] = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1188
+ // RANGECHECK: bb1
1189
+ // RANGECHECK: apply [[CB]]
1190
+ // RANGECHECK-LABEL: } // end sil function 'hoist_new_ind_pattern3'
1191
+ sil @hoist_new_ind_pattern3 : $@convention(thin) (@owned ArrayInt) -> () {
1192
+ bb0(%0 : $ArrayInt):
1193
+ %minus1 = integer_literal $Builtin.Int1, -1
1194
+ %true = struct $Bool(%minus1 : $Builtin.Int1)
1195
+ %zero = integer_literal $Builtin.Int32, 0
1196
+ %int0 = struct $Int32 (%zero : $Builtin.Int32)
1197
+ %one = integer_literal $Builtin.Int32, 1
1198
+ %four = integer_literal $Builtin.Int32, 4
1199
+ %intfour = struct $Int32 (%four : $Builtin.Int32)
1200
+ %cb = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1201
+ apply %cb(%int0, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1202
+ br bb1(%zero : $Builtin.Int32)
1203
+
1204
+ bb1(%4 : $Builtin.Int32):
1205
+ %5 = builtin "sadd_with_overflow_Int32"(%4 : $Builtin.Int32, %one : $Builtin.Int32, %minus1 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
1206
+ %6 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 0
1207
+ %7 = tuple_extract %5 : $(Builtin.Int32, Builtin.Int1), 1
1208
+ %8 = struct $Int32 (%6 : $Builtin.Int32)
1209
+ %9 = builtin "cmp_eq_Int32"(%6 : $Builtin.Int32, %four : $Builtin.Int32) : $Builtin.Int1
1210
+ %10 = builtin "sadd_with_overflow_Int32"(%6 : $Builtin.Int32, %6 : $Builtin.Int32, %minus1 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
1211
+ %11 = tuple_extract %10 : $(Builtin.Int32, Builtin.Int1), 0
1212
+ %12 = tuple_extract %10 : $(Builtin.Int32, Builtin.Int1), 1
1213
+ %13 = struct $Int32 (%11 : $Builtin.Int32)
1214
+ apply %cb(%13, %true, %0) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1215
+ cond_br %9, bb3, bb2
1216
+
1217
+ bb2:
1218
+ br bb1(%6 : $Builtin.Int32)
1219
+
1220
+ bb3:
1221
+ %t = tuple ()
1222
+ return %t : $()
1223
+ }
1224
+
1099
1225
sil public_external [_semantics "array.check_subscript"] @checkbounds_no_meth : $@convention(thin) (Int32, Bool, @owned ArrayInt) -> _DependenceToken {
1100
1226
bb0(%0: $Int32, %1: $Bool, %2: $ArrayInt):
1101
1227
unreachable
0 commit comments