Skip to content

Commit 4068d2c

Browse files
authored
Merge pull request #4885 from aschwaighofer/fix_abcopts_swift3
ABCOpts: Bail out if we don't know how-to hoist an array operation
2 parents 6f4e9a9 + 1aebe29 commit 4068d2c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,10 @@ static bool hoistChecksInLoop(DominanceInfo *DT, DominanceInfoNode *DTNode,
10101010
if (!ArrayIndex)
10111011
continue;
10121012

1013+
// Make sure we know how-to hoist the array call.
1014+
if (!ArrayCall.canHoist(Preheader->getTerminator(), DT))
1015+
continue;
1016+
10131017
// Invariant check.
10141018
if (blockAlwaysExecutes && dominates(DT, ArrayIndex, Preheader)) {
10151019
assert(ArrayCall.canHoist(Preheader->getTerminator(), DT) &&

test/SILOptimizer/abcopts.sil

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,3 +1176,50 @@ bb4:
11761176
%28 = builtin "cmp_eq_Int64"(%23 : $Builtin.Int64, %0 : $Builtin.Int64) : $Builtin.Int1
11771177
cond_br %28, bb2, bb3(%23 : $Builtin.Int64)
11781178
}
1179+
1180+
// Don't assert when we have an isNativeTypeChecked parameter that is not a
1181+
// constant or an array semantic call. It is valid for it to be a phi node.
1182+
sil @bb_arg_is_native2 : $@convention(thin) (Int32, @inout ArrayInt, Builtin.Int1) -> Int32 {
1183+
bb0(%0 : $Int32, %1 : $*ArrayInt, %2 : $Builtin.Int1):
1184+
cond_br %2, bb1, bb2
1185+
1186+
bb1:
1187+
%4 = integer_literal $Builtin.Int1, -1
1188+
%5 = struct $Bool (%4 : $Builtin.Int1)
1189+
br bb3(%5 : $Bool)
1190+
1191+
bb2:
1192+
%7 = integer_literal $Builtin.Int1, -1
1193+
%8 = struct $Bool (%7 : $Builtin.Int1)
1194+
br bb3(%8 : $Bool)
1195+
1196+
bb3(%10 : $Bool):
1197+
%11 = struct_extract %0 : $Int32, #Int32._value
1198+
%12 = integer_literal $Builtin.Int32, 0
1199+
%13 = builtin "cmp_eq_Int32"(%12 : $Builtin.Int32, %11 : $Builtin.Int32) : $Builtin.Int1
1200+
cond_br %13, bb6(%12 : $Builtin.Int32), bb4
1201+
1202+
bb4:
1203+
br bb5(%12 : $Builtin.Int32)
1204+
1205+
bb5(%16 : $Builtin.Int32):
1206+
%17 = struct $Int32 (%16 : $Builtin.Int32)
1207+
%18 = function_ref @checkbounds : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1208+
%19 = load %1 : $*ArrayInt
1209+
%20 = struct_extract %19 : $ArrayInt, #ArrayInt.buffer
1210+
%21 = struct_extract %20 : $ArrayIntBuffer, #ArrayIntBuffer.storage
1211+
retain_value %21 : $Builtin.NativeObject
1212+
%23 = apply %18(%17, %10, %19) : $@convention(method) (Int32, Bool, @owned ArrayInt) -> _DependenceToken
1213+
%24 = integer_literal $Builtin.Int32, 1
1214+
%25 = integer_literal $Builtin.Int1, -1
1215+
%26 = builtin "sadd_with_overflow_Int32"(%16 : $Builtin.Int32, %24 : $Builtin.Int32, %25 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
1216+
%27 = tuple_extract %26 : $(Builtin.Int32, Builtin.Int1), 0
1217+
%28 = tuple_extract %26 : $(Builtin.Int32, Builtin.Int1), 1
1218+
cond_fail %28 : $Builtin.Int1
1219+
%30 = builtin "cmp_eq_Int32"(%27 : $Builtin.Int32, %11 : $Builtin.Int32) : $Builtin.Int1
1220+
cond_br %30, bb6(%27 : $Builtin.Int32), bb5(%27 : $Builtin.Int32)
1221+
1222+
bb6(%32 : $Builtin.Int32):
1223+
%33 = struct $Int32 (%32 : $Builtin.Int32)
1224+
return %33 : $Int32
1225+
}

0 commit comments

Comments
 (0)