@@ -747,28 +747,36 @@ SILCombiner::visitRawPointerToRefInst(RawPointerToRefInst *rawToRef) {
747
747
return nullptr ;
748
748
}
749
749
750
- SILInstruction *
751
- SILCombiner::
752
- visitUncheckedTrivialBitCastInst (UncheckedTrivialBitCastInst *UTBCI) {
750
+ SILInstruction *SILCombiner::visitUncheckedTrivialBitCastInst (
751
+ UncheckedTrivialBitCastInst *utbci) {
753
752
// (unchecked_trivial_bit_cast Y->Z
754
753
// (unchecked_trivial_bit_cast X->Y x))
755
754
// ->
756
755
// (unchecked_trivial_bit_cast X->Z x)
757
- SILValue Op = UTBCI->getOperand ();
758
- if (auto *OtherUTBCI = dyn_cast<UncheckedTrivialBitCastInst>(Op)) {
759
- return Builder.createUncheckedTrivialBitCast (UTBCI->getLoc (),
760
- OtherUTBCI->getOperand (),
761
- UTBCI->getType ());
756
+ SILValue operand = utbci->getOperand ();
757
+ if (auto *otherUTBCI = dyn_cast<UncheckedTrivialBitCastInst>(operand)) {
758
+ return Builder.createUncheckedTrivialBitCast (
759
+ utbci->getLoc (), otherUTBCI->getOperand (), utbci->getType ());
762
760
}
763
761
764
- // (unchecked_trivial_bit_cast Y->Z
765
- // (unchecked_ref_cast X->Y x))
762
+ // %y = unchecked_ref_cast %x X->Y
763
+ // ...
764
+ // %z = unchecked_trivial_bit_cast %y Y->Z
765
+ //
766
766
// ->
767
- // (unchecked_trivial_bit_cast X->Z x)
768
- if (auto *URBCI = dyn_cast<UncheckedRefCastInst>(Op)) {
769
- return Builder.createUncheckedTrivialBitCast (UTBCI->getLoc (),
770
- URBCI->getOperand (),
771
- UTBCI->getType ());
767
+ //
768
+ // %z = unchecked_trivial_bit_cast %x X->Z
769
+ // %y = unchecked_ref_cast %x X->Y
770
+ // ...
771
+ if (auto *urbci = dyn_cast<UncheckedRefCastInst>(operand)) {
772
+ // We just move the unchecked_trivial_bit_cast to before the
773
+ // unchecked_ref_cast and then make its operand the unchecked_ref_cast
774
+ // operand. Then we return the cast so we reprocess given that we changed
775
+ // its operands.
776
+ utbci->moveBefore (urbci);
777
+ utbci->setDebugLocation (urbci->getDebugLocation ());
778
+ utbci->setOperand (urbci->getOperand ());
779
+ return utbci;
772
780
}
773
781
774
782
return nullptr ;
0 commit comments