[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:21 PDT 2026


================
@@ -3083,6 +3083,57 @@ static Value *foldCopySignIdioms(BitCastInst &CI,
   return Builder.CreateCopySign(Builder.CreateBitCast(Y, FTy), X);
 }
 
+// bitcast (shuf X, Y, splat_mask) to iN --> (zext x) * C
+// where x is the splatted integer source element with bitwidth W and
+//       C = 1 + 2^W + 2^(2W) + ... = (2^N - 1)/(2^W - 1)
+// E.g.,
+//   x: i1, y = bitcast [x, x, x, x] --> y = x * 15
+//   x: i8, y = bitcast [x, x, x, x] --> y = x * 16843009
----------------
dtcxzyw wrote:

Use `///` for header comments.

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


More information about the llvm-commits mailing list