@@ -211,6 +211,8 @@ bool AtomicExpandImpl::processAtomicInstr(Instruction *I) {
211
211
auto *RMWI = dyn_cast<AtomicRMWInst>(I);
212
212
auto *CASI = dyn_cast<AtomicCmpXchgInst>(I);
213
213
214
+ bool MadeChange = false ;
215
+
214
216
// If the Size/Alignment is not supported, replace with a libcall.
215
217
if (LI) {
216
218
if (!LI->isAtomic ())
@@ -220,6 +222,12 @@ bool AtomicExpandImpl::processAtomicInstr(Instruction *I) {
220
222
expandAtomicLoadToLibcall (LI);
221
223
return true ;
222
224
}
225
+
226
+ if (TLI->shouldCastAtomicLoadInIR (LI) ==
227
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
228
+ I = LI = convertAtomicLoadToIntegerType (LI);
229
+ MadeChange = true ;
230
+ }
223
231
} else if (SI) {
224
232
if (!SI->isAtomic ())
225
233
return false ;
@@ -228,35 +236,29 @@ bool AtomicExpandImpl::processAtomicInstr(Instruction *I) {
228
236
expandAtomicStoreToLibcall (SI);
229
237
return true ;
230
238
}
239
+
240
+ if (TLI->shouldCastAtomicStoreInIR (SI) ==
241
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
242
+ I = SI = convertAtomicStoreToIntegerType (SI);
243
+ MadeChange = true ;
244
+ }
231
245
} else if (RMWI) {
232
246
if (!atomicSizeSupported (TLI, RMWI)) {
233
247
expandAtomicRMWToLibcall (RMWI);
234
248
return true ;
235
249
}
250
+
251
+ if (TLI->shouldCastAtomicRMWIInIR (RMWI) ==
252
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
253
+ I = RMWI = convertAtomicXchgToIntegerType (RMWI);
254
+ MadeChange = true ;
255
+ }
236
256
} else if (CASI) {
237
257
if (!atomicSizeSupported (TLI, CASI)) {
238
258
expandAtomicCASToLibcall (CASI);
239
259
return true ;
240
260
}
241
- } else
242
- return false ;
243
-
244
- bool MadeChange = false ;
245
261
246
- if (LI && TLI->shouldCastAtomicLoadInIR (LI) ==
247
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
248
- I = LI = convertAtomicLoadToIntegerType (LI);
249
- MadeChange = true ;
250
- } else if (SI && TLI->shouldCastAtomicStoreInIR (SI) ==
251
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
252
- I = SI = convertAtomicStoreToIntegerType (SI);
253
- MadeChange = true ;
254
- } else if (RMWI &&
255
- TLI->shouldCastAtomicRMWIInIR (RMWI) ==
256
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
257
- I = RMWI = convertAtomicXchgToIntegerType (RMWI);
258
- MadeChange = true ;
259
- } else if (CASI) {
260
262
// TODO: when we're ready to make the change at the IR level, we can
261
263
// extend convertCmpXchgToInteger for floating point too.
262
264
if (CASI->getCompareOperand ()->getType ()->isPointerTy ()) {
@@ -265,7 +267,8 @@ bool AtomicExpandImpl::processAtomicInstr(Instruction *I) {
265
267
I = CASI = convertCmpXchgToIntegerType (CASI);
266
268
MadeChange = true ;
267
269
}
268
- }
270
+ } else
271
+ return false ;
269
272
270
273
if (TLI->shouldInsertFencesForAtomic (I)) {
271
274
auto FenceOrdering = AtomicOrdering::Monotonic;
0 commit comments