Skip to content

Commit 393711d

Browse files
committed
SimplifyBuiltin: ignore debug_step and debug_value when checking for side-effects in the callee of a builtin.once
1 parent c567167 commit 393711d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private extension BuiltinInst {
8181
// because memory effects are not computed in the Onone pipeline, yet.
8282
// This is no problem because the callee (usually a global init function )is mostly very small,
8383
// or contains the side-effect instruction `alloc_global` right at the beginning.
84-
if callee.instructions.contains(where: { $0.mayReadOrWriteMemory || $0.hasUnspecifiedSideEffects }) {
84+
if callee.instructions.contains(where: hasSideEffectForBuiltinOnce) {
8585
return
8686
}
8787
context.erase(instruction: self)
@@ -133,6 +133,16 @@ private extension BuiltinInst {
133133
}
134134
}
135135

136+
private func hasSideEffectForBuiltinOnce(_ instruction: Instruction) -> Bool {
137+
switch instruction {
138+
case is DebugStepInst, is DebugValueInst:
139+
return false
140+
default:
141+
return instruction.mayReadOrWriteMemory ||
142+
instruction.hasUnspecifiedSideEffects
143+
}
144+
}
145+
136146
private func typesOfValuesAreEqual(_ lhs: Value, _ rhs: Value, in function: Function) -> Bool? {
137147
if lhs == rhs {
138148
return true

test/SILOptimizer/simplify_builtin.sil

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ bb0:
274274
%1 = global_addr @g : $*Int32
275275
%2 = integer_literal $Builtin.Int32, 10
276276
%3 = struct $Int32 (%2 : $Builtin.Int32)
277+
debug_step
278+
debug_value %1 : $*Int32
277279
%6 = tuple ()
278280
return %6 : $()
279281
}

0 commit comments

Comments
 (0)