Skip to content

Commit 386b622

Browse files
authored
Merge pull request swiftlang#31077 from apple/revert-30429-optimize/remove-dead-in-mand-combine
Revert "[opt] remove trivially dead instructions in mandatory combine"
2 parents 274f62d + 8d392b4 commit 386b622

37 files changed

+50
-123
lines changed

lib/SILOptimizer/Mandatory/MandatoryCombine.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void MandatoryCombiner::addReachableCodeToWorklist(SILFunction &function) {
156156
++iterator;
157157

158158
if (isInstructionTriviallyDead(instruction)) {
159-
instModCallbacks.deleteInst(instruction);
160159
continue;
161160
}
162161

test/AutoDiff/SIL/differentiability_witness_function_inst.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// IRGen test.
1515

16-
// RUN: %target-swift-frontend -emit-ir -Xllvm -sil-disable-pass=MandatoryCombine %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
16+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
1717
// NOTE: `%target-cpu`-specific FileCheck lines exist because lowered function types in LLVM IR differ between architectures.
1818

1919
// NOTE(SR-12090): `shell` is required only to run `sed` as a SR-12090 workaround.

test/ClangImporter/macro_literals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-print-debuginfo -Xllvm -sil-disable-pass=MandatoryCombine -emit-sil %s | %FileCheck %s
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-print-debuginfo -emit-sil %s | %FileCheck %s
22

33
import macros
44

test/Constraints/keypath_dynamic_member_lookup.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,17 @@ var bottomRight = Point(x: 10, y: 10)
3939
var lens = Lens(Rectangle(topLeft: topLeft,
4040
bottomRight: bottomRight))
4141

42-
// A dummy user of variables.
43-
func user<T>(_ _: T) {}
44-
4542
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
4643
// CHECK-NEXT: apply %45<Rectangle, Point>({{.*}})
4744
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
4845
// CHECK-NEXT: apply %54<Point, Int>({{.*}})
49-
user(lens.topLeft.x)
46+
_ = lens.topLeft.x
5047

51-
// CHECK: [[LOOKUP_REF1:%.*]] = function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
52-
// CHECK-NEXT: apply [[LOOKUP_REF1]]<Rectangle, Point>({{.*}})
53-
// CHECK: [[LOOKUP_REF2:%.*]] = function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
54-
// CHECK-NEXT: apply [[LOOKUP_REF2]]<Point, Int>({{.*}})
55-
user(lens.topLeft.y)
48+
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
49+
// CHECK-NEXT: apply %69<Rectangle, Point>({{.*}})
50+
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
51+
// CHECK-NEXT: apply %76<Point, Int>({{.*}})
52+
_ = lens.topLeft.y
5653

5754
lens.topLeft = Lens(Point(x: 1, y: 2)) // Ok
5855
lens.bottomRight.y = Lens(12) // Ok
@@ -241,7 +238,7 @@ func test_recursive_dynamic_lookup(_ lens: Lens<Lens<Point>>) {
241238
// CHECK: [[FIRST_OBJ:%.*]] = struct_extract {{.*}} : $Lens<Lens<Point>>, #Lens.obj
242239
// CHECK-NEXT: [[SECOND_OBJ:%.*]] = struct_extract [[FIRST_OBJ]] : $Lens<Point>, #Lens.obj
243240
// CHECK-NEXT: struct_extract [[SECOND_OBJ]] : $Point, #Point.y
244-
user(lens.obj.obj.y)
241+
_ = lens.obj.obj.y
245242
// CHECK: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
246243
// CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})
247244
// CHECK-NEXT: keypath $KeyPath<Lens<Lens<Point>>, Lens<Lens<Int>>>, (root $Lens<Lens<Point>>; gettable_property $Lens<Lens<Int>>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})

test/IRGen/access_markers.sil

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ bb0(%0 : $A):
3333
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, %Ts5Int64V* [[PROPERTY]], i32 0, i32 0
3434
// CHECK-NEXT: load i64, i64*
3535
%4 = load %3 : $*Int64
36-
// Use %4 so it's not optimized away.
37-
// CHECK-NEXT: store
38-
store %4 to undef : $*Int64
3936

4037
// CHECK-NEXT: call void @swift_endAccess([[BUFFER]]* [[SCRATCH1]])
4138
// CHECK-NEXT: [[T0:%.*]] = bitcast [[BUFFER]]* [[SCRATCH1]] to i8*
@@ -51,9 +48,6 @@ bb0(%0 : $A):
5148
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, %Ts5Int64V* [[PROPERTY]], i32 0, i32 0
5249
// CHECK-NEXT: load i64, i64*
5350
%7 = load %6 : $*Int64
54-
// Use %7 so it's not optimized away.
55-
// CHECK-NEXT: store
56-
store %7 to undef : $*Int64
5751

5852
// CHECK-NEXT: call void @swift_endAccess([[BUFFER]]* [[SCRATCH2]])
5953
// CHECK-NEXT: [[T0:%.*]] = bitcast [[BUFFER]]* [[SCRATCH2]] to i8*

test/IRGen/dynamic_self.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=MandatoryCombine -emit-ir %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
22

33
// REQUIRES: CPU=i386 || CPU=x86_64
44

test/IRGen/enum.sil

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ entry(%u : $*Singleton):
254254
switch_enum_addr %u : $*Singleton, case #Singleton.value!enumelt: dest
255255
dest:
256256
%u2 = unchecked_take_enum_data_addr %u : $*Singleton, #Singleton.value!enumelt
257-
// Use u2 so it's not optimized away.
258-
copy_addr %u2 to undef : $*(Builtin.Int64, Builtin.Int64)
259257
%x = tuple ()
260258
return %x : $()
261259
}
@@ -981,7 +979,6 @@ entry(%u : $*SinglePayloadSpareBit):
981979
// CHECK-64: [[DATA_ADDR:%.*]] = bitcast %T4enum21SinglePayloadSpareBitO* %0 to i63*
982980
x_dest:
983981
%u2 = unchecked_take_enum_data_addr %u : $*SinglePayloadSpareBit, #SinglePayloadSpareBit.x!enumelt
984-
copy_addr %u2 to undef : $*Builtin.Int63
985982
%a = function_ref @a : $@convention(thin) () -> ()
986983
apply %a() : $@convention(thin) () -> ()
987984
br end
@@ -1492,20 +1489,14 @@ entry(%u : $*MultiPayloadNoSpareBits):
14921489

14931490
x_dest:
14941491
%x = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.x!enumelt
1495-
// Dummy use of %x so it's not optimized away.
1496-
copy_addr %x to undef : $*Builtin.Int64
14971492
br end
14981493

14991494
y_dest:
15001495
%y = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.y!enumelt
1501-
// Dummy use of %y so it's not optimized away.
1502-
copy_addr %y to undef : $*Builtin.Int32
15031496
br end
15041497

15051498
z_dest:
15061499
%z = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.z!enumelt
1507-
// Dummy use of %z so it's not optimized away.
1508-
copy_addr %z to undef : $*Builtin.Int63
15091500
br end
15101501

15111502
a_dest:
@@ -1751,20 +1742,14 @@ entry(%u : $*MultiPayloadOneSpareBit):
17511742

17521743
x_dest:
17531744
%x = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.x!enumelt
1754-
// Dummy use of %x so it's not optimized away.
1755-
copy_addr %x to undef : $*Builtin.Int62
17561745
br end
17571746

17581747
y_dest:
17591748
%y = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.y!enumelt
1760-
// Dummy use of %y so it's not optimized away.
1761-
copy_addr %y to undef : $*Builtin.Int63
17621749
br end
17631750

17641751
z_dest:
17651752
%z = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.z!enumelt
1766-
// Dummy use of %z so it's not optimized away.
1767-
copy_addr %z to undef : $*Builtin.Int61
17681753
br end
17691754

17701755
a_dest:
@@ -2456,8 +2441,6 @@ entry(%0 : $*DynamicSingleton<T>):
24562441

24572442
dest:
24582443
%1 = unchecked_take_enum_data_addr %0 : $*DynamicSingleton<T>, #DynamicSingleton.value!enumelt
2459-
// Dummy use of %1 so it's not optimized away.
2460-
copy_addr %1 to undef : $*T
24612444
%v = tuple ()
24622445
return %v : $()
24632446
}
@@ -2538,8 +2521,6 @@ entry(%x : $Int32):
25382521
// CHECK-64: [[INT_SHR:%.*]] = lshr i64 [[INT_SHL]], 32
25392522
// CHECK-64: [[INT:%.*]] = trunc i64 [[INT_SHR]] to i32
25402523
%e = unchecked_enum_data %d : $Optional<(Optional<()>, Int32)>, #Optional.some!enumelt
2541-
// Use %e so it's not optimized away.
2542-
store %e to undef : $*(Optional<()>, Int32)
25432524
return %d : $Optional<(Optional<()>, Int32)>
25442525
}
25452526

test/IRGen/enum_dynamic_multi_payload.sil

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,8 @@ sil @dynamic_project : $@convention(thin) <T> () -> @out EitherOr<T, Builtin.Int
285285
entry(%e : $*EitherOr<T, Builtin.Int64>):
286286
// CHECK: bitcast [[EITHER_OR]]* %0 to %swift.opaque*
287287
%l = unchecked_take_enum_data_addr %e : $*EitherOr<T, Builtin.Int64>, #EitherOr.Left!enumelt
288-
// Dummy use of %l so that it's not optimized away.
289-
copy_addr %l to undef : $*T
290288
// CHECK: bitcast [[EITHER_OR]]* %0 to i64*
291289
%r = unchecked_take_enum_data_addr %e : $*EitherOr<T, Builtin.Int64>, #EitherOr.Right!enumelt
292-
// Dummy use of %r so that it's not optimized away.
293-
copy_addr %r to undef : $*Builtin.Int64
294290

295291
return undef : $()
296292
}

test/IRGen/enum_future.sil

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ entry(%u : $*Singleton):
258258
switch_enum_addr %u : $*Singleton, case #Singleton.value!enumelt: dest
259259
dest:
260260
%u2 = unchecked_take_enum_data_addr %u : $*Singleton, #Singleton.value!enumelt
261-
copy_addr %u2 to undef : $*(Builtin.Int64, Builtin.Int64)
262261
%x = tuple ()
263262
return %x : $()
264263
}
@@ -984,7 +983,6 @@ entry(%u : $*SinglePayloadSpareBit):
984983
// CHECK-64: [[DATA_ADDR:%.*]] = bitcast %T11enum_future21SinglePayloadSpareBitO* %0 to i63*
985984
x_dest:
986985
%u2 = unchecked_take_enum_data_addr %u : $*SinglePayloadSpareBit, #SinglePayloadSpareBit.x!enumelt
987-
copy_addr %u2 to undef : $*Builtin.Int63
988986
%a = function_ref @a : $@convention(thin) () -> ()
989987
apply %a() : $@convention(thin) () -> ()
990988
br end
@@ -1495,20 +1493,14 @@ entry(%u : $*MultiPayloadNoSpareBits):
14951493

14961494
x_dest:
14971495
%x = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.x!enumelt
1498-
// Use %x so it's not optimized away.
1499-
copy_addr %x to undef : $*Builtin.Int64
15001496
br end
15011497

15021498
y_dest:
15031499
%y = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.y!enumelt
1504-
// Use %y so it's not optimized away.
1505-
copy_addr %y to undef : $*Builtin.Int32
15061500
br end
15071501

15081502
z_dest:
15091503
%z = unchecked_take_enum_data_addr %u : $*MultiPayloadNoSpareBits, #MultiPayloadNoSpareBits.z!enumelt
1510-
// Use %z so it's not optimized away.
1511-
copy_addr %z to undef : $*Builtin.Int63
15121504
br end
15131505

15141506
a_dest:
@@ -1754,20 +1746,14 @@ entry(%u : $*MultiPayloadOneSpareBit):
17541746

17551747
x_dest:
17561748
%x = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.x!enumelt
1757-
// Use %x so it's not optimized away.
1758-
copy_addr %x to undef : $*Builtin.Int62
17591749
br end
17601750

17611751
y_dest:
17621752
%y = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.y!enumelt
1763-
// Use %y so it's not optimized away.
1764-
copy_addr %y to undef : $*Builtin.Int63
17651753
br end
17661754

17671755
z_dest:
17681756
%z = unchecked_take_enum_data_addr %u : $*MultiPayloadOneSpareBit, #MultiPayloadOneSpareBit.z!enumelt
1769-
// Use %z so it's not optimized away.
1770-
copy_addr %z to undef : $*Builtin.Int61
17711757
br end
17721758

17731759
a_dest:
@@ -2459,8 +2445,6 @@ entry(%0 : $*DynamicSingleton<T>):
24592445

24602446
dest:
24612447
%1 = unchecked_take_enum_data_addr %0 : $*DynamicSingleton<T>, #DynamicSingleton.value!enumelt
2462-
// Use %1 so it's not optimized away.
2463-
copy_addr %1 to undef : $*T
24642448
%v = tuple ()
24652449
return %v : $()
24662450
}
@@ -2541,8 +2525,6 @@ entry(%x : $Int32):
25412525
// CHECK-64: [[INT_SHR:%.*]] = lshr i64 [[INT_SHL]], 32
25422526
// CHECK-64: [[INT:%.*]] = trunc i64 [[INT_SHR]] to i32
25432527
%e = unchecked_enum_data %d : $Optional<(Optional<()>, Int32)>, #Optional.some!enumelt
2544-
// Use %e so it's not optimized away.
2545-
store %e to undef : $*(Optional<()>, Int32)
25462528
return %d : $Optional<(Optional<()>, Int32)>
25472529
}
25482530

test/IRGen/existentials.sil

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,12 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
7373
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
7474
// CHECK: [[DEST_WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]]
7575
%b = load_weak [take] %w : $*@sil_weak CP?
76-
// Use %b so it isn't removed.
77-
store_weak %b to undef : $*@sil_weak CP?
7876

7977
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
8078
// CHECK: [[DEST_REF:%.*]] = call %swift.refcounted* @swift_weakLoadStrong(%swift.weak* [[SRC_REF_ADDR]])
8179
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
8280
// CHECK: [[DEST_WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]]
8381
%c = load_weak %w : $*@sil_weak CP?
84-
// Use %c so it isn't removed.
85-
store_weak %c to undef : $*@sil_weak CP?
8682

8783
// CHECK: call { %swift.weak, i8** }* @"$s12existentials2CP_pSgXwWOb"({ %swift.weak, i8** }* %0, { %swift.weak, i8** }* [[V]])
8884
copy_addr [take] %w to [initialization] %v : $*@sil_weak CP?

0 commit comments

Comments
 (0)