@@ -101,7 +101,8 @@ static ManagedValue emitBuiltinLoadOrTake(SILGenFunction &SGF,
101
101
SGFContext C,
102
102
IsTake_t isTake,
103
103
bool isStrict,
104
- bool isInvariant) {
104
+ bool isInvariant,
105
+ llvm::MaybeAlign align) {
105
106
assert (substitutions.getReplacementTypes ().size () == 1 &&
106
107
" load should have single substitution" );
107
108
assert (args.size () == 1 && " load should have a single argument" );
@@ -113,9 +114,12 @@ static ManagedValue emitBuiltinLoadOrTake(SILGenFunction &SGF,
113
114
SILType loadedType = rvalueTL.getLoweredType ();
114
115
115
116
// Convert the pointer argument to a SIL address.
117
+ //
118
+ // Default to an unaligned pointer. This can be optimized in the presence of
119
+ // Builtin.assumeAlignment.
116
120
SILValue addr = SGF.B .createPointerToAddress (loc, args[0 ].getUnmanagedValue (),
117
121
loadedType.getAddressType (),
118
- isStrict, isInvariant);
122
+ isStrict, isInvariant, align );
119
123
// Perform the load.
120
124
return SGF.emitLoad (loc, addr, rvalueTL, C, isTake);
121
125
}
@@ -125,39 +129,47 @@ static ManagedValue emitBuiltinLoad(SILGenFunction &SGF,
125
129
SubstitutionMap substitutions,
126
130
ArrayRef<ManagedValue> args,
127
131
SGFContext C) {
132
+ // Regular loads assume natural alignment.
128
133
return emitBuiltinLoadOrTake (SGF, loc, substitutions, args,
129
134
C, IsNotTake,
130
- /* isStrict*/ true , /* isInvariant*/ false );
135
+ /* isStrict*/ true , /* isInvariant*/ false ,
136
+ llvm::MaybeAlign ());
131
137
}
132
138
133
139
static ManagedValue emitBuiltinLoadRaw (SILGenFunction &SGF,
134
140
SILLocation loc,
135
141
SubstitutionMap substitutions,
136
142
ArrayRef<ManagedValue> args,
137
143
SGFContext C) {
144
+ // Raw loads cannot assume alignment.
138
145
return emitBuiltinLoadOrTake (SGF, loc, substitutions, args,
139
146
C, IsNotTake,
140
- /* isStrict*/ false , /* isInvariant*/ false );
147
+ /* isStrict*/ false , /* isInvariant*/ false ,
148
+ llvm::MaybeAlign (1 ));
141
149
}
142
150
143
151
static ManagedValue emitBuiltinLoadInvariant (SILGenFunction &SGF,
144
152
SILLocation loc,
145
153
SubstitutionMap substitutions,
146
154
ArrayRef<ManagedValue> args,
147
155
SGFContext C) {
156
+ // Regular loads assume natural alignment.
148
157
return emitBuiltinLoadOrTake (SGF, loc, substitutions, args,
149
158
C, IsNotTake,
150
- /* isStrict*/ false , /* isInvariant*/ true );
159
+ /* isStrict*/ false , /* isInvariant*/ true ,
160
+ llvm::MaybeAlign ());
151
161
}
152
162
153
163
static ManagedValue emitBuiltinTake (SILGenFunction &SGF,
154
164
SILLocation loc,
155
165
SubstitutionMap substitutions,
156
166
ArrayRef<ManagedValue> args,
157
167
SGFContext C) {
168
+ // Regular loads assume natural alignment.
158
169
return emitBuiltinLoadOrTake (SGF, loc, substitutions, args,
159
170
C, IsTake,
160
- /* isStrict*/ true , /* isInvariant*/ false );
171
+ /* isStrict*/ true , /* isInvariant*/ false ,
172
+ llvm::MaybeAlign ());
161
173
}
162
174
163
175
// / Specialized emitter for Builtin.destroy.
0 commit comments