Revert "[Stdlib performance] Make integer conversion operations transparent"

This commit is contained in:
Artem Chikin
2025-04-09 10:10:26 -07:00
committed by GitHub
parent b2d1adcc13
commit 41b09e3d7f
6 changed files with 18 additions and 44 deletions

View File

@@ -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
@@ -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);

View File

@@ -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 {
@@ -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) {
@@ -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 {
@@ -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 {

View File

@@ -1,26 +0,0 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64 || CPU=arm64
// https://github.com/swiftlang/swift/issues/78501
public struct PcgRandom {
private var state: UInt64 = 0;
// CHECK-LABEL: define{{.*}}swiftcc i32 @"$s18integer_conversion9PcgRandomV6next32s6UInt32VyF"
public mutating func next32() -> UInt32 {
// CHECK-NOT: sSUss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufC
// CHECK-NOT: sSZss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufC
// CHECK: ret i32
let oldstate : UInt64 = state
state = oldstate &* 6364136223846793005 &+ 1;
let shifted = oldstate >> 18
let xor = shifted ^ oldstate
let xorshifted64 = xor >> 27
let xorshifted = UInt32((xorshifted64 << 32) >> 32)
let rot : UInt32 = UInt32(oldstate >> 59)
let nrot : UInt32 = UInt32(bitPattern: -Int32(rot))
return (xorshifted >> rot) | (xorshifted << (nrot & 31))
}
init() {}
}

View File

@@ -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'

View File

@@ -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")
@@ -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")

View File

@@ -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")