Skip to content

Commit b914464

Browse files
carlos4242stephentyrone
authored andcommitted
Remove apparently obsolete builtin functions (swiftlang#20947)
* Remove apparently obsolete builtin functions. - Remove s_to_u_checked_conversion and u_to_s_checked_conversion functions from builtin AST parsing, SIL/IR generation and from SIL optimisations. * Remove apparently obsolete builtin functions - unit tests. - Remove unit tests for SIL transformations relating to s_to_u_checked_conversion and u_to_s_checked_conversion builtin functions.
1 parent e4d1841 commit b914464

File tree

13 files changed

+39
-535
lines changed

13 files changed

+39
-535
lines changed

include/swift/AST/Builtins.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,6 @@ BUILTIN_MISC_OPERATION(SToSCheckedTrunc, "s_to_s_checked_trunc", "n", Special)
478478
BUILTIN_MISC_OPERATION(SToUCheckedTrunc, "s_to_u_checked_trunc", "n", Special)
479479
BUILTIN_MISC_OPERATION(UToUCheckedTrunc, "u_to_u_checked_trunc", "n", Special)
480480

481-
/// Checked conversions for signed <-> unsigned integers of the same size.
482-
/// Returns a tuple containing the conversion result as well as
483-
/// the sign error / overflow bit.
484-
BUILTIN_MISC_OPERATION(SUCheckedConversion,
485-
"s_to_u_checked_conversion", "n", Special)
486-
BUILTIN_MISC_OPERATION(USCheckedConversion,
487-
"u_to_s_checked_conversion", "n", Special)
488-
489481
/// IntToFPWithOverflow has type (Integer) -> Float
490482
BUILTIN_MISC_OPERATION(IntToFPWithOverflow, "itofp_with_overflow", "n", Special)
491483

include/swift/SIL/PatternMatch.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,6 @@ using BuiltinApplyTy = typename Apply_match<BuiltinValueKind, Tys...>::Ty;
715715
// if any of the sub-matchers succeed.
716716
//
717717

718-
/// Matcher for any of the builtin checked conversions.
719-
template <typename T0>
720-
inline typename OneOf_match<BuiltinApplyTy<T0>, BuiltinApplyTy<T0>>::Ty
721-
m_CheckedConversion(const T0 &Op0) {
722-
return m_USCheckedConversion(Op0) || m_SUCheckedConversion(Op0);
723-
}
724-
725718
/// Matcher for any of the builtin ExtOrBitCast instructions.
726719
template <typename T0>
727720
inline typename OneOf_match<BuiltinApplyTy<T0>, BuiltinApplyTy<T0>>::Ty

lib/AST/Builtins.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,19 +1106,6 @@ static ValueDecl *getCheckedTruncOperation(ASTContext &Context, Identifier Id,
11061106
return getBuiltinFunction(Id, { InTy }, ResultTy);
11071107
}
11081108

1109-
static ValueDecl *getCheckedConversionOperation(ASTContext &Context,
1110-
Identifier Id,
1111-
Type Ty) {
1112-
Type BuiltinTy = Ty->getAs<BuiltinIntegerType>();
1113-
if (!BuiltinTy)
1114-
return nullptr;
1115-
1116-
Type SignErrorBitTy = BuiltinIntegerType::get(1, Context);
1117-
TupleTypeElt ResultElts[] = { BuiltinTy, SignErrorBitTy };
1118-
Type ResultTy = TupleType::get(ResultElts, Context);
1119-
return getBuiltinFunction(Id, { BuiltinTy }, ResultTy);
1120-
}
1121-
11221109
static ValueDecl *getIntToFPWithOverflowOperation(ASTContext &Context,
11231110
Identifier Id, Type InputTy,
11241111
Type OutputTy) {
@@ -1853,11 +1840,6 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
18531840
if (Types.size() != 2) return nullptr;
18541841
return getCheckedTruncOperation(Context, Id, Types[0], Types[1], false);
18551842

1856-
case BuiltinValueKind::SUCheckedConversion:
1857-
case BuiltinValueKind::USCheckedConversion:
1858-
if (Types.size() != 1) return nullptr;
1859-
return getCheckedConversionOperation(Context, Id, Types[0]);
1860-
18611843
case BuiltinValueKind::ClassifyBridgeObject:
18621844
if (!Types.empty()) return nullptr;
18631845
return getClassifyBridgeObject(Context, Id);

lib/IRGen/GenBuiltin.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -758,22 +758,6 @@ if (Builtin.ID == BuiltinValueKind::id) { \
758758
return out.add(OverflowFlag);
759759
}
760760

761-
if (Builtin.ID == BuiltinValueKind::SUCheckedConversion ||
762-
Builtin.ID == BuiltinValueKind::USCheckedConversion) {
763-
auto Ty =
764-
IGF.IGM.getStorageTypeForLowered(Builtin.Types[0]->getCanonicalType());
765-
766-
// Report a sign error if the input parameter is a negative number, when
767-
// interpreted as signed.
768-
llvm::Value *Arg = args.claimNext();
769-
llvm::Value *Zero = llvm::ConstantInt::get(Ty, 0);
770-
llvm::Value *OverflowFlag = IGF.Builder.CreateICmpSLT(Arg, Zero);
771-
772-
// Return the tuple: (the result (same as input), the overflow flag).
773-
out.add(Arg);
774-
return out.add(OverflowFlag);
775-
}
776-
777761
// We are currently emitting code for '_convertFromBuiltinIntegerLiteral',
778762
// which will call the builtin and pass it a non-compile-time-const parameter.
779763
if (Builtin.ID == BuiltinValueKind::IntToFPWithOverflow) {

lib/SIL/OperandOwnership.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, SRem)
11221122
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, SSubOver)
11231123
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, SToSCheckedTrunc)
11241124
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, SToUCheckedTrunc)
1125-
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, SUCheckedConversion)
11261125
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, Shl)
11271126
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, Sizeof)
11281127
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, StaticReport)
@@ -1140,7 +1139,6 @@ CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, UDiv)
11401139
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, UIToFP)
11411140
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, UMulOver)
11421141
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, URem)
1143-
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, USCheckedConversion)
11441142
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, USubOver)
11451143
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, UToSCheckedTrunc)
11461144
CONSTANT_OWNERSHIP_BUILTIN(Trivial, MustBeLive, UToUCheckedTrunc)

lib/SIL/ValueOwnership.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,6 @@ CONSTANT_OWNERSHIP_BUILTIN(Trivial, UToSCheckedTrunc)
479479
CONSTANT_OWNERSHIP_BUILTIN(Trivial, SToSCheckedTrunc)
480480
CONSTANT_OWNERSHIP_BUILTIN(Trivial, SToUCheckedTrunc)
481481
CONSTANT_OWNERSHIP_BUILTIN(Trivial, UToUCheckedTrunc)
482-
CONSTANT_OWNERSHIP_BUILTIN(Trivial, SUCheckedConversion)
483-
CONSTANT_OWNERSHIP_BUILTIN(Trivial, USCheckedConversion)
484482
CONSTANT_OWNERSHIP_BUILTIN(Trivial, IntToFPWithOverflow)
485483

486484
// This is surprising, Builtin.unreachable returns a "Never" value which is

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -492,18 +492,6 @@ static SILValue simplifyBuiltin(BuiltinInst *BI) {
492492
return Result;
493493
}
494494

495-
// trunc(tuple_extract(conversion(extOrBitCast(x))))) -> x
496-
if (match(Op, m_TupleExtractInst(
497-
m_CheckedConversion(
498-
m_ExtOrBitCast(m_SILValue(Result))), 0))) {
499-
// If the top bit of Result is known to be 0, then
500-
// it is safe to replace the whole pattern by original bits of x
501-
if (Result->getType() == BI->getType()) {
502-
if (auto signBit = computeSignBit(Result))
503-
if (!signBit.getValue())
504-
return Result;
505-
}
506-
}
507495
return SILValue();
508496
}
509497

@@ -639,23 +627,6 @@ SILValue InstSimplifier::simplifyOverflowBuiltin(BuiltinInst *BI) {
639627
switch (Builtin.ID) {
640628
default: break;
641629

642-
case BuiltinValueKind::SUCheckedConversion:
643-
case BuiltinValueKind::USCheckedConversion: {
644-
OperandValueArrayRef Args = BI->getArguments();
645-
const SILValue &Op = Args[0];
646-
if (auto signBit = computeSignBit(Op))
647-
if (!signBit.getValue())
648-
return Op;
649-
SILValue Result;
650-
// CheckedConversion(ExtOrBitCast(x)) -> x
651-
if (match(BI, m_CheckedConversion(m_ExtOrBitCast(m_SILValue(Result)))))
652-
if (Result->getType() == BI->getType().getTupleElementType(0)) {
653-
assert (!computeSignBit(Result).getValue() && "Sign bit should be 0");
654-
return Result;
655-
}
656-
}
657-
break;
658-
659630
case BuiltinValueKind::UToSCheckedTrunc:
660631
case BuiltinValueKind::UToUCheckedTrunc:
661632
case BuiltinValueKind::SToUCheckedTrunc:

lib/SILOptimizer/Analysis/ValueTracking.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,6 @@ Optional<bool> swift::computeSignBit(SILValue V) {
296296
continue;
297297
}
298298

299-
// Source and target type sizes are the same.
300-
// S->U conversion can only succeed if
301-
// the sign bit of its operand is 0, i.e. it is >= 0.
302-
// The sign bit of a result is 0 only if the sign
303-
// bit of a source operand is 0.
304-
case BuiltinValueKind::SUCheckedConversion:
305-
Value = BI->getArguments()[0];
306-
continue;
307-
308-
// Source and target type sizes are the same.
309-
// U->S conversion can only succeed if
310-
// the top bit of its operand is 0, i.e.
311-
// it is representable as a signed integer >=0.
312-
// The sign bit of a result is 0 only if the sign
313-
// bit of a source operand is 0.
314-
case BuiltinValueKind::USCheckedConversion:
315-
Value = BI->getArguments()[0];
316-
continue;
317-
318299
// Sign bit of the operand is promoted.
319300
case BuiltinValueKind::SExt:
320301
Value = BI->getArguments()[0];

lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ static bool isBarrier(SILInstruction *inst) {
122122
case BuiltinValueKind::SToUCheckedTrunc:
123123
case BuiltinValueKind::SToSCheckedTrunc:
124124
case BuiltinValueKind::UToUCheckedTrunc:
125-
case BuiltinValueKind::SUCheckedConversion:
126-
case BuiltinValueKind::USCheckedConversion:
127125
case BuiltinValueKind::IntToFPWithOverflow:
128126
case BuiltinValueKind::ZeroInitializer:
129127
case BuiltinValueKind::Once:

lib/SILOptimizer/Utils/ConstExpr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ ConstExprFunctionState::computeConstantValueBuiltin(BuiltinInst *inst) {
210210
if (!operand.isConstant())
211211
return operand;
212212

213-
// TODO: SUCheckedConversion/USCheckedConversion
214-
215213
// Implement support for s_to_s_checked_trunc_Int2048_Int64 and other
216214
// checking integer truncates. These produce a tuple of the result value
217215
// and an overflow bit.

0 commit comments

Comments
 (0)