Skip to content

Commit 7c37406

Browse files
committed
Remove the strideof_nonzero builtin.
Because now the stride of all types is at least one, anyway.
1 parent c710b04 commit 7c37406

File tree

9 files changed

+11
-54
lines changed

9 files changed

+11
-54
lines changed

include/swift/AST/Builtins.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,6 @@ BUILTIN_MISC_OPERATION(IsPOD, "ispod", "n", Special)
358358
/// Alignof has type T.Type -> Int
359359
BUILTIN_MISC_OPERATION(Alignof, "alignof", "n", Special)
360360

361-
/// Strideof has type T.Type -> Int.
362-
/// Note that this version will never return 0. It instead always returns
363-
/// at least 1
364-
BUILTIN_MISC_OPERATION(StrideofNonZero, "strideof_nonzero", "n", Special)
365-
366361
/// AllocRaw has type (Int, Int) -> Builtin.RawPointer
367362
BUILTIN_MISC_OPERATION(AllocRaw, "allocRaw", "", Special)
368363

lib/AST/Builtins.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,6 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
15591559
case BuiltinValueKind::Sizeof:
15601560
case BuiltinValueKind::Strideof:
15611561
case BuiltinValueKind::Alignof:
1562-
case BuiltinValueKind::StrideofNonZero:
15631562
return getSizeOrAlignOfOperation(Context, Id);
15641563

15651564
case BuiltinValueKind::IsPOD:

lib/IRGen/GenBuiltin.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,6 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, Identifier FnId,
171171
return;
172172
}
173173

174-
if (Builtin.ID == BuiltinValueKind::StrideofNonZero) {
175-
// Note this case must never return 0.
176-
// It is implemented as max(strideof, 1)
177-
args.claimAll();
178-
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
179-
substitutions[0].getReplacement());
180-
// Strideof should never return 0, so return 1 if the type has a 0 stride.
181-
llvm::Value *StrideOf = valueTy.second.getStride(IGF, valueTy.first);
182-
llvm::IntegerType *IntTy = cast<llvm::IntegerType>(StrideOf->getType());
183-
auto *Zero = llvm::ConstantInt::get(IntTy, 0);
184-
auto *One = llvm::ConstantInt::get(IntTy, 1);
185-
llvm::Value *Cmp = IGF.Builder.CreateICmpEQ(StrideOf, Zero);
186-
out.add(IGF.Builder.CreateSelect(Cmp, One, StrideOf));
187-
return;
188-
}
189-
190174
if (Builtin.ID == BuiltinValueKind::IsPOD) {
191175
args.claimAll();
192176
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,

lib/SILOptimizer/Analysis/ValueTracking.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ Optional<bool> swift::computeSignBit(SILValue V) {
141141
// Strideof always returns non-negative results.
142142
case BuiltinValueKind::Strideof:
143143
return false;
144-
// StrideofNonZero always returns positive results.
145-
case BuiltinValueKind::StrideofNonZero:
146-
return false;
147144
// Alignof always returns non-negative results.
148145
case BuiltinValueKind::Alignof:
149146
return false;

lib/SILOptimizer/SILCombiner/SILCombinerBuiltinVisitors.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ matchSizeOfMultiplication(SILValue I, MetatypeInst *RequiredType,
184184
m_ApplyInst(
185185
BuiltinValueKind::SMulOver, m_SILValue(Dist),
186186
m_ApplyInst(BuiltinValueKind::ZExtOrBitCast,
187-
m_ApplyInst(BuiltinValueKind::StrideofNonZero,
187+
m_ApplyInst(BuiltinValueKind::Strideof,
188188
m_MetatypeInst(StrideType)))),
189189
0))) ||
190190
match(
@@ -195,7 +195,7 @@ matchSizeOfMultiplication(SILValue I, MetatypeInst *RequiredType,
195195
m_ApplyInst(
196196
BuiltinValueKind::SMulOver,
197197
m_ApplyInst(BuiltinValueKind::ZExtOrBitCast,
198-
m_ApplyInst(BuiltinValueKind::StrideofNonZero,
198+
m_ApplyInst(BuiltinValueKind::Strideof,
199199
m_MetatypeInst(StrideType))),
200200
m_SILValue(Dist)),
201201
0)))) {
@@ -464,9 +464,6 @@ SILInstruction *SILCombiner::visitBuiltinInst(BuiltinInst *I) {
464464

465465
if (match(I, m_ApplyInst(BuiltinValueKind::SMulOver,
466466
m_ApplyInst(BuiltinValueKind::Strideof),
467-
m_ValueBase(), m_IntegerLiteralInst())) ||
468-
match(I, m_ApplyInst(BuiltinValueKind::SMulOver,
469-
m_ApplyInst(BuiltinValueKind::StrideofNonZero),
470467
m_ValueBase(), m_IntegerLiteralInst()))) {
471468
I->swapOperands(0, 1);
472469
return I;

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
9090
// Turn this also into an index_addr. We generate this pattern after switching
9191
// the Word type to an explicit Int32 or Int64 in the stdlib.
9292
//
93-
// %101 = builtin "strideof_nonzero"<Int>(%84 : $@thick Int.Type) :
93+
// %101 = builtin "strideof"<Int>(%84 : $@thick Int.Type) :
9494
// $Builtin.Word
9595
// %102 = builtin "zextOrBitCast_Word_Int64"(%101 : $Builtin.Word) :
9696
// $Builtin.Int64
@@ -119,13 +119,13 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
119119
m_ApplyInst(
120120
BuiltinValueKind::SMulOver, m_SILValue(Distance),
121121
m_ApplyInst(BuiltinValueKind::ZExtOrBitCast,
122-
m_ApplyInst(BuiltinValueKind::StrideofNonZero,
122+
m_ApplyInst(BuiltinValueKind::Strideof,
123123
m_MetatypeInst(Metatype))))) ||
124124
match(StrideMul,
125125
m_ApplyInst(
126126
BuiltinValueKind::SMulOver,
127127
m_ApplyInst(BuiltinValueKind::ZExtOrBitCast,
128-
m_ApplyInst(BuiltinValueKind::StrideofNonZero,
128+
m_ApplyInst(BuiltinValueKind::Strideof,
129129
m_MetatypeInst(Metatype))),
130130
m_SILValue(Distance)))) {
131131
SILType InstanceType =
@@ -167,10 +167,6 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
167167
if (match(Bytes, m_ApplyInst(BuiltinValueKind::SMulOver, m_ValueBase(),
168168
m_ApplyInst(BuiltinValueKind::Strideof,
169169
m_MetatypeInst(Metatype)),
170-
m_ValueBase())) ||
171-
match(Bytes, m_ApplyInst(BuiltinValueKind::SMulOver, m_ValueBase(),
172-
m_ApplyInst(BuiltinValueKind::StrideofNonZero,
173-
m_MetatypeInst(Metatype)),
174170
m_ValueBase()))) {
175171
SILType InstanceType =
176172
Metatype->getType().getMetatypeInstanceType(PTAI->getModule());

stdlib/public/core/MemoryLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public enum MemoryLayout<T> {
3030
/// performance for space efficiency. The result is always positive.
3131
@_transparent
3232
public static var stride: Int {
33-
return Int(Builtin.strideof_nonzero(T.self))
33+
return Int(Builtin.strideof(T.self))
3434
}
3535

3636
/// The default memory alignment of `T`.

test/IRGen/builtins.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,6 @@ func generic_strideof_test<T>(_: T) {
245245
var s = Builtin.strideof(T.self)
246246
}
247247

248-
// CHECK: define hidden void @_TF8builtins29generic_strideof_nonzero_testurFxT_(
249-
func generic_strideof_nonzero_test<T>(_: T) {
250-
// CHECK: [[T0:%.*]] = getelementptr inbounds i8*, i8** [[T:%.*]], i32 19
251-
// CHECK-NEXT: [[T1:%.*]] = load i8*, i8** [[T0]]
252-
// CHECK-NEXT: [[STRIDE:%.*]] = ptrtoint i8* [[T1]] to i64
253-
// CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[STRIDE]], 0
254-
// CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i64 1, i64 [[STRIDE]]
255-
// CHECK-NEXT: store i64 [[SELECT]], i64* [[S:%.*]]
256-
var s = Builtin.strideof_nonzero(T.self)
257-
}
258-
259248
class X {}
260249

261250
class Y {}

test/SILOptimizer/sil_combine.sil

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,16 +1258,16 @@ bb0(%0 : $Builtin.RawPointer, %1 : $Builtin.Word):
12581258
return %11 : $Int8
12591259
}
12601260

1261-
// CHECK-LABEL: sil @indexrawpointer_to_indexaddr_strideof_nonzero : $@convention(thin) (Builtin.RawPointer, Builtin.Word) -> Int8 {
1261+
// CHECK-LABEL: sil @indexrawpointer_to_indexaddr_strideof : $@convention(thin) (Builtin.RawPointer, Builtin.Word) -> Int8 {
12621262
// CHECK: bb0
12631263
// CHECK-NEXT: pointer_to_address
12641264
// CHECK-NEXT: index_addr
12651265
// CHECK-NEXT: load
12661266
// CHECK-NEXT: return
1267-
sil @indexrawpointer_to_indexaddr_strideof_nonzero : $@convention(thin) (Builtin.RawPointer, Builtin.Word) -> Int8 {
1267+
sil @indexrawpointer_to_indexaddr_strideof : $@convention(thin) (Builtin.RawPointer, Builtin.Word) -> Int8 {
12681268
bb0(%0 : $Builtin.RawPointer, %1 : $Builtin.Word):
12691269
%3 = metatype $@thick Int8.Type
1270-
%4 = builtin "strideof_nonzero"<Int8>(%3 : $@thick Int8.Type) : $Builtin.Word
1270+
%4 = builtin "strideof"<Int8>(%3 : $@thick Int8.Type) : $Builtin.Word
12711271
%6 = integer_literal $Builtin.Int1, -1
12721272
%7 = builtin "smul_with_overflow_Word"(%4 : $Builtin.Word, %1 : $Builtin.Word, %6 : $Builtin.Int1) : $(Builtin.Word, Builtin.Int1)
12731273
%8 = tuple_extract %7 : $(Builtin.Word, Builtin.Int1), 0
@@ -1303,7 +1303,7 @@ sil @indexrawpointer_to_indexaddr_with_casts : $@convention(thin) (Builtin.RawPo
13031303
bb0(%0 : $Builtin.RawPointer, %1: $Builtin.Int64):
13041304
%2 = integer_literal $Builtin.Int1, -1
13051305
%3 = metatype $@thick Int32.Type
1306-
%4 = builtin "strideof_nonzero"<Int32>(%3 : $@thick Int32.Type) : $Builtin.Word
1306+
%4 = builtin "strideof"<Int32>(%3 : $@thick Int32.Type) : $Builtin.Word
13071307
%5 = builtin "zextOrBitCast_Word_Int64"(%4 : $Builtin.Word) : $Builtin.Int64
13081308
%6 = builtin "smul_with_overflow_Int64"(%1 : $Builtin.Int64, %5 : $Builtin.Int64, %2 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
13091309
%7 = tuple_extract %6 : $(Builtin.Int64, Builtin.Int1), 0
@@ -2143,7 +2143,7 @@ bb0(%0 : $Builtin.Int64, %1 : $Builtin.RawPointer, %2 : $Builtin.RawPointer):
21432143
%4 = metatype $@thick Int32.Type
21442144
%5 = integer_literal $Builtin.Word, 1
21452145
%6 = integer_literal $Builtin.Int1, 0
2146-
%7 = builtin "strideof_nonzero"<Int32>(%4 : $@thick Int32.Type) : $Builtin.Word
2146+
%7 = builtin "strideof"<Int32>(%4 : $@thick Int32.Type) : $Builtin.Word
21472147
%14 = builtin "zextOrBitCast_Word_Int64"(%7 : $Builtin.Word) : $Builtin.Int64
21482148
%8 = builtin "smul_with_overflow_Word"(%14 : $Builtin.Int64, %0 : $Builtin.Int64, %6 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
21492149
%9 = tuple_extract %8 : $(Builtin.Int64, Builtin.Int1), 0

0 commit comments

Comments
 (0)