@@ -1894,8 +1894,8 @@ static void allocateAndSetAll(StructLoweringState &pass,
18941894 }
18951895}
18961896
1897- static void castTupleInstr (SingleValueInstruction *instr, IRGenModule &Mod,
1898- LargeSILTypeMapper &Mapper) {
1897+ static void retypeTupleInstr (SingleValueInstruction *instr, IRGenModule &Mod,
1898+ LargeSILTypeMapper &Mapper) {
18991899 SILType currSILType = instr->getType ();
19001900 auto funcType = getInnerFunctionType (currSILType);
19011901 assert (funcType && " Expected a function Type" );
@@ -1910,25 +1910,31 @@ static void castTupleInstr(SingleValueInstruction *instr, IRGenModule &Mod,
19101910
19111911 auto II = instr->getIterator ();
19121912 ++II;
1913- SILBuilderWithScope castBuilder (II);
1914- SingleValueInstruction *castInstr = nullptr ;
1913+ SILBuilderWithScope Builder (II);
1914+ SingleValueInstruction *newInstr = nullptr ;
19151915 switch (instr->getKind ()) {
19161916 // Add cast to the new sil function type:
19171917 case SILInstructionKind::TupleExtractInst: {
1918- castInstr = castBuilder.createUncheckedReinterpretCast (
1919- instr->getLoc (), instr, newSILType.getObjectType ());
1918+ auto extractInst = cast<TupleExtractInst>(instr);
1919+ newInstr = Builder.createTupleExtract (
1920+ extractInst->getLoc (), extractInst->getOperand (),
1921+ extractInst->getFieldIndex (),
1922+ newSILType.getObjectType ());
19201923 break ;
19211924 }
19221925 case SILInstructionKind::TupleElementAddrInst: {
1923- castInstr = castBuilder.createUncheckedAddrCast (
1924- instr->getLoc (), instr, newSILType.getAddressType ());
1926+ auto elementAddrInst = cast<TupleElementAddrInst>(instr);
1927+ newInstr = Builder.createTupleElementAddr (
1928+ elementAddrInst->getLoc (), elementAddrInst->getOperand (),
1929+ elementAddrInst->getFieldIndex (),
1930+ newSILType.getAddressType ());
19251931 break ;
19261932 }
19271933 default :
19281934 llvm_unreachable (" Unexpected instruction inside tupleInstsToMod" );
19291935 }
1930- instr->replaceAllUsesWith (castInstr );
1931- castInstr-> setOperand ( 0 , instr );
1936+ instr->replaceAllUsesWith (newInstr );
1937+ instr-> eraseFromParent ( );
19321938}
19331939
19341940static SILValue createCopyOfEnum (StructLoweringState &pass,
@@ -2090,7 +2096,7 @@ static void rewriteFunction(StructLoweringState &pass,
20902096 }
20912097
20922098 for (SingleValueInstruction *instr : pass.tupleInstsToMod ) {
2093- castTupleInstr (instr, pass.Mod , pass.Mapper );
2099+ retypeTupleInstr (instr, pass.Mod , pass.Mapper );
20942100 }
20952101
20962102 while (!pass.allocStackInstsToMod .empty ()) {
0 commit comments