swift
9474b9d1 - Optimizer: add simplifications for checked_cast_br and unchecked_ref_cast

Commit
2 years ago
Optimizer: add simplifications for checked_cast_br and unchecked_ref_cast Look through `upcast` and `init_existential_ref` instructions and replace the operand of this cast instruction with the original value. For example: ``` %2 = upcast %1 : $Derived to $Base %3 = init_existential_ref %2 : $Base : $Base, $AnyObject checked_cast_br %3 : $AnyObject to Derived, bb1, bb2 ``` This makes it more likely that the cast can be constant folded because the source operand's type is more accurate. In the example above, the cast reduces to ``` checked_cast_br %1 : $Derived to Derived, bb1, bb2 ``` which can be trivially folded to always-succeeds. Found while looking at `_SwiftDeferredNSDictionary.bridgeValues()`
Author
Committer
Parents
  • SwiftCompilerSources/Sources
    • Optimizer/InstructionSimplification
      • File
        CMakeLists.txt
      • File
        SimplifyRefCasts.swift
    • SIL
      • File
        Builder.swift
      • File
        Instruction.swift
  • include/swift/SIL
    • File
      SILBridging.h
  • test/SILOptimizer
    • File
      definite_init_failable_initializers_objc.swift
    • simplify_checked_cast_br.sil
    • simplify_unchecked_ref_cast.sil
Loading