@@ -269,66 +269,63 @@ simplifyAMDGCNImageIntrinsic(const GCNSubtarget *ST,
269
269
ArgTys[0 ] = User->getType ();
270
270
});
271
271
}
272
- } else {
273
- // Only perform D16 folding if every user of the image sample is
274
- // an ExtractElementInst immediately followed by an FPTrunc to half.
275
- SmallVector<ExtractElementInst *, 4 > Extracts;
276
- SmallVector<FPTruncInst *, 4 > Truncs;
277
- bool AllHalfExtracts = true ;
278
-
279
- for (User *U : II.users ()) {
280
- auto *Ext = dyn_cast<ExtractElementInst>(U);
281
- if (!Ext || !Ext->hasOneUse ()) {
282
- AllHalfExtracts = false ;
283
- break ;
284
- }
285
- auto *Tr = dyn_cast<FPTruncInst>(*Ext->user_begin ());
286
- if (!Tr || !Tr->getType ()->isHalfTy ()) {
287
- AllHalfExtracts = false ;
288
- break ;
289
- }
290
- Extracts.push_back (Ext);
291
- Truncs.push_back (Tr);
292
- }
272
+ }
293
273
294
- if (AllHalfExtracts && !Extracts. empty ()) {
295
- auto *VecTy = cast<VectorType>(II. getType ());
296
- Type *HalfVecTy =
297
- VecTy-> getWithNewType ( Type::getHalfTy (II. getContext ())) ;
274
+ // Only perform D16 folding if every user of the image sample is
275
+ // an ExtractElementInst immediately followed by an FPTrunc to half.
276
+ SmallVector<ExtractElementInst *, 4 > Extracts;
277
+ SmallVector<FPTruncInst *, 4 > Truncs ;
298
278
299
- // Obtain the original image sample intrinsic's signature
300
- // and replace its return type with the half-vector for D16 folding
301
- SmallVector<Type *, 8 > SigTys;
302
- Intrinsic::getIntrinsicSignature (II.getCalledFunction (), SigTys);
303
- SigTys[0 ] = HalfVecTy;
279
+ for (User *U : II.users ()) {
280
+ auto *Ext = dyn_cast<ExtractElementInst>(U);
281
+ if (!Ext || !Ext->hasOneUse ())
282
+ return std::nullopt;
304
283
305
- Module *M = II. getModule ( );
306
- Function *HalfDecl =
307
- Intrinsic::getOrInsertDeclaration (M, ImageDimIntr-> Intr , SigTys) ;
284
+ auto *Tr = dyn_cast<FPTruncInst>(*Ext-> user_begin () );
285
+ if (!Tr || !Tr-> getType ()-> isHalfTy ())
286
+ return std::nullopt ;
308
287
309
- II.mutateType (HalfVecTy);
310
- II.setCalledFunction (HalfDecl);
288
+ Extracts.push_back (Ext);
289
+ Truncs.push_back (Tr);
290
+ }
311
291
312
- IRBuilder<> Builder (II.getContext ());
313
- for (auto [Ext, Tr] : zip (Extracts, Truncs)) {
314
- Value *Idx = Ext->getIndexOperand ();
292
+ if (Extracts.empty ())
293
+ return std::nullopt;
315
294
316
- Builder.SetInsertPoint (Tr);
295
+ auto *VecTy = cast<VectorType>(II.getType ());
296
+ Type *HalfVecTy = VecTy->getWithNewType (Type::getHalfTy (II.getContext ()));
317
297
318
- Value *HalfExtract = Builder.CreateExtractElement (&II, Idx);
319
- HalfExtract->takeName (Tr);
298
+ // Obtain the original image sample intrinsic's signature
299
+ // and replace its return type with the half-vector for D16 folding
300
+ SmallVector<Type *, 8 > SigTys;
301
+ Intrinsic::getIntrinsicSignature (II.getCalledFunction (), SigTys);
302
+ SigTys[0 ] = HalfVecTy;
320
303
321
- Tr->replaceAllUsesWith (HalfExtract);
322
- }
304
+ Module *M = II.getModule ();
305
+ Function *HalfDecl =
306
+ Intrinsic::getOrInsertDeclaration (M, ImageDimIntr->Intr , SigTys);
323
307
324
- for (FPTruncInst *T : Truncs)
325
- IC.eraseInstFromFunction (*T);
326
- for (ExtractElementInst *E : Extracts)
327
- IC.eraseInstFromFunction (*E);
308
+ II.mutateType (HalfVecTy);
309
+ II.setCalledFunction (HalfDecl);
328
310
329
- return &II;
330
- }
311
+ IRBuilder<> Builder (II.getContext ());
312
+ for (auto [Ext, Tr] : zip (Extracts, Truncs)) {
313
+ Value *Idx = Ext->getIndexOperand ();
314
+
315
+ Builder.SetInsertPoint (Tr);
316
+
317
+ Value *HalfExtract = Builder.CreateExtractElement (&II, Idx);
318
+ HalfExtract->takeName (Tr);
319
+
320
+ Tr->replaceAllUsesWith (HalfExtract);
331
321
}
322
+
323
+ for (FPTruncInst *T : Truncs)
324
+ IC.eraseInstFromFunction (*T);
325
+ for (ExtractElementInst *E : Extracts)
326
+ IC.eraseInstFromFunction (*E);
327
+
328
+ return &II;
332
329
}
333
330
}
334
331
0 commit comments