[llvm] [InstCombine] Fold `bitcast [x, ..., x] to iN` to `mul x, C` (PR #185907)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 10:59:20 PDT 2026


================
@@ -3161,8 +3212,16 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
   }
 
   if (auto *Shuf = dyn_cast<ShuffleVectorInst>(Src)) {
-    // Okay, we have (bitcast (shuffle ..)).  Check to see if this is
-    // a bitcast to a vector with the same # elts.
+    // Okay, we have (bitcast (shuffle ..)).
+
+    // Check to see if the bitcast to iN is only user of a splat-shuffle.
+    // If so, try to fold `bitcast [x, ..., x] to iN` into `(zext x) * C`
+    if (auto *DstIntTy = dyn_cast<IntegerType>(DestTy);
+        DstIntTy && Shuf->hasOneUser())
+      if (Value *V = foldSplatShuffleToMul(Shuf, DstIntTy, Builder))
----------------
dtcxzyw wrote:

Change the return type of `foldSplatShuffleToMul` to `Instruction *`.

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


More information about the llvm-commits mailing list