Skip to content

[6.2] Revert #79707 #80768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/SILOptimizer/Mandatory/OSLogOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,16 +938,6 @@ static void substituteConstants(FoldState &foldState) {
for (SILValue constantSILValue : foldState.getConstantSILValues()) {
SymbolicValue constantSymbolicVal =
evaluator.lookupConstValue(constantSILValue).value();
CanType instType = constantSILValue->getType().getASTType();

// If the SymbolicValue is a string but the instruction that is folded is
// not String typed, we are tracking a StaticString which is represented as
// a raw pointer. Skip folding StaticString as they are already efficiently
// represented.
if (constantSymbolicVal.getKind() == SymbolicValue::String &&
!instType->isString())
continue;

// Make sure that the symbolic value tracked in the foldState is a constant.
// In the case of ArraySymbolicValue, the array storage could be a non-constant
// if some instruction in the array initialization sequence was not evaluated
Expand Down Expand Up @@ -986,6 +976,7 @@ static void substituteConstants(FoldState &foldState) {

SILBuilderWithScope builder(insertionPoint);
SILLocation loc = insertionPoint->getLoc();
CanType instType = constantSILValue->getType().getASTType();
SILValue foldedSILVal = emitCodeForSymbolicValue(
constantSymbolicVal, instType, builder, loc, foldState.stringInfo);

Expand Down
12 changes: 8 additions & 4 deletions stdlib/public/core/Integers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,8 @@ extension UnsignedInteger where Self: FixedWidthInteger {
/// - Parameter source: A value to convert to this type of integer. The value
/// passed as `source` must be representable in this type.
@_semantics("optimize.sil.specialize.generic.partial.never")
@_transparent
@inlinable // FIXME(inline-always)
@inline(__always)
public init<T: BinaryInteger>(_ source: T) {
// This check is potentially removable by the optimizer
if T.isSigned {
Expand All @@ -3056,7 +3057,8 @@ extension UnsignedInteger where Self: FixedWidthInteger {
}

@_semantics("optimize.sil.specialize.generic.partial.never")
@_transparent
@inlinable // FIXME(inline-always)
@inline(__always)
public init?<T: BinaryInteger>(exactly source: T) {
// This check is potentially removable by the optimizer
if T.isSigned && source < (0 as T) {
Expand Down Expand Up @@ -3254,7 +3256,8 @@ extension SignedInteger where Self: FixedWidthInteger {
/// - Parameter source: A value to convert to this type of integer. The value
/// passed as `source` must be representable in this type.
@_semantics("optimize.sil.specialize.generic.partial.never")
@_transparent
@inlinable // FIXME(inline-always)
@inline(__always)
public init<T: BinaryInteger>(_ source: T) {
// This check is potentially removable by the optimizer
if T.isSigned && source.bitWidth > Self.bitWidth {
Expand All @@ -3271,7 +3274,8 @@ extension SignedInteger where Self: FixedWidthInteger {
}

@_semantics("optimize.sil.specialize.generic.partial.never")
@_transparent
@inlinable // FIXME(inline-always)
@inline(__always)
public init?<T: BinaryInteger>(exactly source: T) {
// This check is potentially removable by the optimizer
if T.isSigned && source.bitWidth > Self.bitWidth && source < Self.min {
Expand Down
26 changes: 0 additions & 26 deletions test/IRGen/integer_conversion.swift

This file was deleted.

4 changes: 3 additions & 1 deletion test/Interop/Cxx/templates/function-template-silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import FunctionTemplates
// CHECK: [[ADD_TWO_FN:%.*]] = function_ref @{{_Z18addMixedTypeParamsIiiET_S0_T0_|\?\?\$addMixedTypeParams@HH@@YAHHH@Z}} : $@convention(c) (Int32, Int32) -> Int32
// CHECK: [[C:%.*]] = apply [[ADD_TWO_FN]]([[A]], [[B]]) : $@convention(c) (Int32, Int32) -> Int32

// CHECK: [[C_32_ADDR:%.*]] = alloc_stack $Int32
// CHECK: [[C_32:%.*]] = load [[C_32_ADDR]] : $*Int32
// CHECK: [[ADD_FN:%.*]] = function_ref @{{_Z17addSameTypeParamsIiET_S0_S0_|\?\?\$addSameTypeParams@H@@YAHHH@Z}} : $@convention(c) (Int32, Int32) -> Int32
// CHECK: [[OUT:%.*]] = apply [[ADD_FN]]([[B]], [[C_32:%.*]]) : $@convention(c) (Int32, Int32) -> Int32
// CHECK: [[OUT:%.*]] = apply [[ADD_FN]]([[B]], [[C_32]]) : $@convention(c) (Int32, Int32) -> Int32
// CHECK: return [[OUT]] : $Int32

// CHECK-LABEL: end sil function '$s4main4test1xs5Int32VAE_tF'
Expand Down
6 changes: 4 additions & 2 deletions test/SILOptimizer/Inputs/constant_evaluable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ internal func interpretIntTruncations() -> Int8 {
internal func testInvalidIntTruncations(a: Int32) -> Int8 {
return Int8(a)
// CHECK: note: {{.*}}: Not enough bits to represent the passed value
// CHECK: note: operation traps
// CHECK: note: operation performed during this call traps
// CHECK: function_ref @$sSZss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufC
}

@_semantics("test_driver")
Expand Down Expand Up @@ -219,7 +220,8 @@ internal func interpretSingedUnsignedConversions() -> UInt32 {
internal func testInvalidSingedUnsignedConversions(a: Int64) -> UInt64 {
return UInt64(a)
// CHECK: note: {{.*}}: Negative value is not representable
// CHECK: note: operation traps
// CHECK: note: operation performed during this call traps
// CHECK: function_ref @$sSUss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufC
}

@_semantics("test_driver")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ internal func interpretIntTruncations() -> Int16 {
internal func testInvalidIntTruncations(a: Int64) -> Int8 {
return Int8(a)
// CHECK: note: {{.*}} Not enough bits to represent the passed value
// CHECK: note: operation traps
// CHECK: note: operation performed during this call traps
// CHECK: function_ref @$sSZss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufC
}

@_semantics("test_driver")
Expand Down