Skip to content

Commit 75d9540

Browse files
author
Mingsheng Hong
committed
Fixed a bug in const folding, where an inst that's not of type
SingleValueInstruction gets added to the worklist, causing cast assert at https://github.com/apple/swift/blame/master/lib/SILOptimizer/Utils/ConstantFolding.cpp#L1585. One such example inst is the following (in the tensorflow branch), which produces a SILValue of type MultipleValueInstructionResult, so ValueBase::getDefiningInstruction() still returns a valid inst for it, even though that graph_op inst is not a SingleValueInstruction. ``` %94 = graph_op "Fill,i,i"(%73 : $TensorHandle<Int32>, %85 : $TensorHandle<Float>) {T: $Float, index_type: $Int32, __device: "/device:CPU:0"} : $TensorHandle<Float> ``` The same fix has been merged into the tensorflow branch: #18272
1 parent 4483276 commit 75d9540

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,8 @@ ConstantFolder::processWorkList() {
16681668

16691669
// The new constant could be further folded now, add it to the worklist.
16701670
if (auto *Inst = C->getDefiningInstruction())
1671-
WorkList.insert(Inst);
1671+
if (isa<SingleValueInstruction>(Inst))
1672+
WorkList.insert(Inst);
16721673
}
16731674

16741675
// Eagerly DCE. We do this after visiting all users to ensure we don't

0 commit comments

Comments
 (0)