[llvm] [AMDGPU] Support D16 folding for image.sample with multiple extractelement and fptrunc users (PR #141758)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 10:07:43 PDT 2025
================
@@ -269,6 +269,68 @@ simplifyAMDGCNImageIntrinsic(const GCNSubtarget *ST,
ArgTys[0] = User->getType();
});
}
+ } else {
+ // Only perform D16 folding if every user of the image sample is
+ // an ExtractElementInst immediately followed by an FPTrunc to half.
+ SmallVector<ExtractElementInst *, 4> Extracts;
+ SmallVector<FPTruncInst *, 4> Truncs;
+ bool AllHalfExtracts = true;
+
+ for (User *U : II.users()) {
+ auto *Ext = dyn_cast<ExtractElementInst>(U);
+ if (!Ext || !Ext->hasOneUse()) {
+ AllHalfExtracts = false;
+ break;
+ }
+ auto *Tr = dyn_cast<FPTruncInst>(*Ext->user_begin());
+ if (!Tr || !Tr->getType()->getScalarType()->isHalfTy()) {
+ AllHalfExtracts = false;
+ break;
+ }
+ Extracts.push_back(Ext);
+ Truncs.push_back(Tr);
+ }
+
+ if (AllHalfExtracts && !Extracts.empty()) {
+ auto *VecTy = cast<VectorType>(II.getType());
+ unsigned NElts = VecTy->getElementCount().getKnownMinValue();
+ Type *HalfVecTy =
+ VectorType::get(Type::getHalfTy(II.getContext()), NElts, false);
----------------
harrisonGPU wrote:
Thanks ! I have updated it.
https://github.com/llvm/llvm-project/pull/141758
More information about the llvm-commits
mailing list