[llvm] [InstCombine] SimplifyDemandedBits: add basic bitcast handling, Fixes #173780 (PR #173865)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 30 05:44:13 PST 2025


================
@@ -175,6 +175,22 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
     return false;
   }
 
+  if (auto *BC = dyn_cast<BitCastInst>(VInst)) {
+    Value *Src = BC->getOperand(0);
+    Type *SrcTy = Src->getType();
+    Type *DstTy = BC->getType();
+
+    // Only push demanded bits through lossless bitcasts
+    if (SrcTy->getScalarSizeInBits() ==
+        DstTy->getScalarSizeInBits()) {
+      return SimplifyDemandedBits(I, OpNo,
+                                  DemandedMask,
+                                  Known,
+                                  Q,
+                                  Depth + 1);
+    }
+  }
+
----------------
RKSimon wrote:

+1 - I think it also need clang-formatting

https://github.com/llvm/llvm-project/pull/173865


More information about the llvm-commits mailing list