@@ -2368,25 +2368,30 @@ bool AMDGPULegalizerInfo::legalizeAddrSpaceCast(
2368
2368
if (DestAS == AMDGPUAS::FLAT_ADDRESS &&
2369
2369
(SrcAS == AMDGPUAS::LOCAL_ADDRESS ||
2370
2370
SrcAS == AMDGPUAS::PRIVATE_ADDRESS)) {
2371
- Register ApertureReg = getSegmentAperture (SrcAS, MRI, B);
2372
- if (!ApertureReg.isValid ())
2373
- return false ;
2371
+ auto castLocalOrPrivateToFlat = [&](const DstOp &Dst) -> Register {
2372
+ Register ApertureReg = getSegmentAperture (SrcAS, MRI, B);
2373
+ if (!ApertureReg.isValid ())
2374
+ return false ;
2374
2375
2375
- // Coerce the type of the low half of the result so we can use merge_values.
2376
- Register SrcAsInt = B.buildPtrToInt (S32, Src).getReg (0 );
2376
+ // Coerce the type of the low half of the result so we can use
2377
+ // merge_values.
2378
+ Register SrcAsInt = B.buildPtrToInt (S32, Src).getReg (0 );
2377
2379
2378
- // TODO: Should we allow mismatched types but matching sizes in merges to
2379
- // avoid the ptrtoint?
2380
- auto BuildPtr = B.buildMergeLikeInstr (DstTy, {SrcAsInt, ApertureReg});
2380
+ // TODO: Should we allow mismatched types but matching sizes in merges to
2381
+ // avoid the ptrtoint?
2382
+ return B.buildMergeLikeInstr (Dst, {SrcAsInt, ApertureReg}).getReg (0 );
2383
+ };
2381
2384
2382
2385
// For llvm.amdgcn.addrspacecast.nonnull we can always assume non-null, for
2383
2386
// G_ADDRSPACE_CAST we need to guess.
2384
2387
if (isa<GIntrinsic>(MI) || isKnownNonNull (Src, MRI, TM, SrcAS)) {
2385
- B. buildCopy (Dst, BuildPtr );
2388
+ castLocalOrPrivateToFlat (Dst);
2386
2389
MI.eraseFromParent ();
2387
2390
return true ;
2388
2391
}
2389
2392
2393
+ Register BuildPtr = castLocalOrPrivateToFlat (DstTy);
2394
+
2390
2395
auto SegmentNull = B.buildConstant (SrcTy, TM.getNullPointerValue (SrcAS));
2391
2396
auto FlatNull = B.buildConstant (DstTy, TM.getNullPointerValue (DestAS));
2392
2397
0 commit comments