================
@@ -1488,6 +1488,61 @@ static bool SinkCast(CastInst *CI) {
return MadeChange;
}
+/// Hoists bitcasts to the source block to reduce register pressure
+static bool optimizeBitCast(BitCastInst *BCI, const TargetLowering &TLI,
+ const DataLayout &DL) {
+ auto *SrcInst = dyn_cast<Instruction>(BCI->getOperand(0));
+ if (!SrcInst || SrcInst->getParent() == BCI->getParent() ||
+ SrcInst->isTerminator())
+ return false;
+
+ EVT SrcVT = TLI.getValueType(DL, SrcInst->getType());
+ EVT DestVT = TLI.getValueType(DL, BCI->getType());
+
+ // Bail out on scalable vectors and illegal destination types
+ if (SrcVT.isScalableVector() || DestVT.isScalableVector() ||
+ !TLI.isTypeLegal(DestVT))
+ return false;
+
+ // Only hoist if it reduces physical register count
+ if (TLI.getNumRegisters(BCI->getContext(), SrcVT) <=
+ TLI.getNumRegisters(BCI->getContext(), DestVT))
+ return false;
+
+ // Prevent large cross-domain scalar hoists
+ Type *DestTy = BCI->getType();
+ Type *SrcTy = SrcInst->getType();
+ bool IsCrossDomain = DestTy->isFPOrFPVectorTy() != SrcTy->isFPOrFPVectorTy();
+ bool IsLargeScalar = !DestTy->isVectorTy() &&
+ DL.getTypeSizeInBits(DestTy).getFixedValue() > 64;
----------------
RKSimon wrote:
This needs to be more general (e.g. its a problem even just on 32-bit x86)
https://github.com/llvm/llvm-project/pull/207568
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits