[llvm] [ValueTracking] ComputeNumSignBitsImpl - add basic handling of BITCAST nodes (PR #127218)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 05:13:24 PST 2025
================
@@ -3922,6 +3922,35 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
if (auto *U = dyn_cast<Operator>(V)) {
switch (Operator::getOpcode(V)) {
default: break;
+ case Instruction::BitCast: {
+ Value *Src = U->getOperand(0);
+ Type *SrcTy = Src->getType();
+ Type *SrcScalarTy = SrcTy->getScalarType();
+
+ if (!SrcScalarTy->isIntegerTy())
+ break;
+
+ unsigned SrcBits = SrcTy->getScalarSizeInBits();
+
+ if ((SrcBits % TyBits) != 0)
+ break;
+
+ if (auto *DstVTy = dyn_cast<FixedVectorType>(Ty)) {
+ unsigned Scale = SrcBits / TyBits;
+
+ APInt SrcDemandedElts =
+ APInt::getSplat(DstVTy->getNumElements() / Scale, APInt(1, 1));
+
+ Tmp = ComputeNumSignBits(Src, SrcDemandedElts, Depth + 1, Q);
+ if (Tmp == SrcBits)
+ return TyBits;
+ } else {
+ Tmp = ComputeNumSignBits(Src, APInt(1, 1), Depth + 1, Q);
----------------
RKSimon wrote:
This isn't guaranteed to be a scalar here, so could the 1 bit demanded elts mask fail?
https://github.com/llvm/llvm-project/pull/127218
More information about the llvm-commits
mailing list