Skip to content

Commit 934e11a

Browse files
committed
Add a sil-opt test for cond_fail merging through -mergeable-traps
1 parent afac821 commit 934e11a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/DriverTool/sil_opt_main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ struct SILOptOptions {
596596
llvm::cl::opt<bool> EnableAddressDependencies = llvm::cl::opt<bool>(
597597
"enable-address-dependencies",
598598
llvm::cl::desc("Enable enforcement of lifetime dependencies on addressable values."));
599+
600+
llvm::cl::opt<bool> MergeableTraps = llvm::cl::opt<bool>(
601+
"mergeable-traps",
602+
llvm::cl::desc("Enable cond_fail merging."));
599603
};
600604

601605
/// Regular expression corresponding to the value given in one of the
@@ -914,6 +918,7 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
914918
options.EnablePackMetadataStackPromotion;
915919

916920
SILOpts.EnableAddressDependencies = options.EnableAddressDependencies;
921+
SILOpts.MergeableTraps = options.MergeableTraps;
917922

918923
if (options.OptModeFlag == OptimizationMode::NotSet) {
919924
if (options.OptimizationGroup == OptGroup::Diagnostics)

test/SILOptimizer/merge_cond_fail.sil

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -merge-cond_fails | %FileCheck %s
2+
// RUN: %target-sil-opt -enable-sil-verify-all %s -merge-cond_fails -mergeable-traps | %FileCheck %s --check-prefix CHECK-FORCE-MERGE
23

34
// REQUIRES: swift_in_compiler
45

@@ -36,3 +37,46 @@ bb0 (%0 : $Builtin.Int1, %1 : $Builtin.Int1, %2 : $Builtin.Int1, %3: $Builtin.In
3637
cond_fail %10 : $Builtin.Int1
3738
return %9 : $Builtin.Int64
3839
}
40+
41+
// CHECK-LABEL: sil @nonmergeable_cond_fail
42+
// CHECK: bb0([[ARG1:%.*]] : $Builtin.Int1, [[ARG2:%.*]] : $Builtin.Int1, [[ARG3:%.*]] : $Builtin.Int1, [[ARG4:%.*]] : $Builtin.Int1, [[ARG5:%.*]] : $*Builtin.Int64):
43+
// CHECK: {{ cond_fail}}
44+
// CHECK: {{ cond_fail}}
45+
// CHECK: [[LD:%.*]] = load [[ARG5]]
46+
// CHECK: {{ cond_fail}}
47+
// CHECK: {{ cond_fail}}
48+
// CHECK: [[TUPLE:%.*]] = builtin "sadd_with_overflow_Int64"
49+
// CHECK: [[RES:%.*]] = tuple_extract [[TUPLE]]{{.*}}, 0
50+
// CHECK: [[OVERFLOW:%.*]] = tuple_extract [[TUPLE]]{{.*}}, 1
51+
// CHECK: {{ cond_fail}}
52+
// CHECK: return [[RES]]
53+
54+
// CHECK-FORCE-MERGE-LABEL: sil @nonmergeable_cond_fail
55+
// CHECK-FORCE-MERGE: bb0([[ARG1:%.*]] : $Builtin.Int1, [[ARG2:%.*]] : $Builtin.Int1, [[ARG3:%.*]] : $Builtin.Int1, [[ARG4:%.*]] : $Builtin.Int1, [[ARG5:%.*]] : $*Builtin.Int64):
56+
// CHECK-FORCE-MERGE: [[COND1:%.*]] = builtin "or_Int1"([[ARG1]]{{.*}}, [[ARG2]]
57+
// CHECK-FORCE-MERGE: {{ cond_fail}} [[COND1]]
58+
// CHECK-FORCE-MERGE-NOT: {{ cond_fail}}
59+
// CHECK-FORCE-MERGE: [[LD:%.*]] = load [[ARG5]]
60+
// CHECK-FORCE-MERGE: [[COND2:%.*]] = builtin "or_Int1"([[ARG3]]{{.*}}, [[ARG4]]
61+
// CHECK-FORCE-MERGE: {{ cond_fail}} [[COND2]]
62+
// CHECK-FORCE-MERGE: [[TUPLE:%.*]] = builtin "sadd_with_overflow_Int64"
63+
// CHECK-FORCE-MERGE: [[RES:%.*]] = tuple_extract [[TUPLE]]{{.*}}, 0
64+
// CHECK-FORCE-MERGE: [[OVERFLOW:%.*]] = tuple_extract [[TUPLE]]{{.*}}, 1
65+
// CHECK-FORCE-MERGE: {{ cond_fail}} [[OVERFLOW]]
66+
// CHECK-FORCE-MERGE: return [[RES]]
67+
68+
sil @nonmergeable_cond_fail : $@convention(thin) (Builtin.Int1, Builtin.Int1, Builtin.Int1, Builtin.Int1, @inout Builtin.Int64) -> Builtin.Int64 {
69+
bb0 (%0 : $Builtin.Int1, %1 : $Builtin.Int1, %2 : $Builtin.Int1, %3: $Builtin.Int1, %4 : $*Builtin.Int64):
70+
cond_fail %0 : $Builtin.Int1, "message1"
71+
cond_fail %1 : $Builtin.Int1, "message2"
72+
%5 = load %4 : $*Builtin.Int64
73+
cond_fail %2 : $Builtin.Int1, "message3"
74+
cond_fail %3 : $Builtin.Int1, "message4"
75+
%6 = integer_literal $Builtin.Int1, -1
76+
%7 = integer_literal $Builtin.Int64, 1
77+
%8 = builtin "sadd_with_overflow_Int64"(%5 : $Builtin.Int64, %7 : $Builtin.Int64, %6 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
78+
%9 = tuple_extract %8 : $(Builtin.Int64, Builtin.Int1), 0
79+
%10 = tuple_extract %8 : $(Builtin.Int64, Builtin.Int1), 1
80+
cond_fail %10 : $Builtin.Int1, "message5"
81+
return %9 : $Builtin.Int64
82+
}

0 commit comments

Comments
 (0)