@@ -435,13 +435,24 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
435
435
return ;
436
436
}
437
437
438
+ SmallPtrSet<const Constant *, 8 > VisitedConsts;
439
+
438
440
for (Instruction &I : instructions (F)) {
439
441
if (isa<AddrSpaceCastInst>(I) &&
440
- cast<AddrSpaceCastInst & >(I).getSrcAddressSpace () ==
442
+ cast<AddrSpaceCastInst>(I).getSrcAddressSpace () ==
441
443
AMDGPUAS::PRIVATE_ADDRESS) {
442
444
removeAssumedBits (FLAT_SCRATCH_INIT);
443
445
return ;
444
446
}
447
+ // check for addrSpaceCast in constant expressions
448
+ for (const Use &U : I.operands ()) {
449
+ if (const auto *C = dyn_cast<Constant>(U)) {
450
+ if (constHasASCast (C, VisitedConsts)) {
451
+ removeAssumedBits (FLAT_SCRATCH_INIT);
452
+ return ;
453
+ }
454
+ }
455
+ }
445
456
}
446
457
}
447
458
@@ -709,9 +720,9 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
709
720
// already removed in updateImpl() and execution won't reach here.
710
721
if (!Callee)
711
722
return true ;
712
- else
713
- return Callee->getIntrinsicID () !=
714
- Intrinsic::amdgcn_addrspacecast_nonnull;
723
+
724
+ return Callee->getIntrinsicID () !=
725
+ Intrinsic::amdgcn_addrspacecast_nonnull;
715
726
};
716
727
717
728
bool UsedAssumedInformation = false ;
@@ -721,6 +732,28 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
721
732
return !A.checkForAllCallLikeInstructions (CheckForNoFlatScratchInit, *this ,
722
733
UsedAssumedInformation);
723
734
}
735
+
736
+ bool constHasASCast (const Constant *C,
737
+ SmallPtrSetImpl<const Constant *> &Visited) {
738
+ if (!Visited.insert (C).second )
739
+ return false ;
740
+
741
+ if (const auto *CE = dyn_cast<ConstantExpr>(C))
742
+ if (CE->getOpcode () == Instruction::AddrSpaceCast &&
743
+ CE->getOperand (0 )->getType ()->getPointerAddressSpace () ==
744
+ AMDGPUAS::PRIVATE_ADDRESS)
745
+ return true ;
746
+
747
+ for (const Use &U : C->operands ()) {
748
+ const auto *OpC = dyn_cast<Constant>(U);
749
+ if (!OpC || !Visited.insert (OpC).second )
750
+ continue ;
751
+
752
+ if (constHasASCast (OpC, Visited))
753
+ return true ;
754
+ }
755
+ return false ;
756
+ }
724
757
};
725
758
726
759
AAAMDAttributes &AAAMDAttributes::createForPosition (const IRPosition &IRP,
0 commit comments