Skip to content

Commit 650ace4

Browse files
author
Mingsheng Hong
authored
Fixed a bug in const folding, where an inst that's not of type (#18272)
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, 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> // users: %1581, %100, %98, %97, %99, %103, %106, %111, %113, %118, %755 ```
1 parent 7731c0e commit 650ace4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,10 @@ ConstantFolder::processWorkList() {
16671667
UserV->replaceAllUsesWith(C);
16681668

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

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

0 commit comments

Comments
 (0)