[llvm] [VectorCombine] Generalize foldBitOpOfBitcasts to support more cast operations (PR #148350)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 04:34:16 PDT 2025


================
@@ -862,8 +901,15 @@ bool VectorCombine::foldBitOpOfBitcasts(Instruction &I) {
 
   Worklist.pushValue(NewOp);
 
-  // Bitcast the result back
-  Value *Result = Builder.CreateBitCast(NewOp, I.getType());
+  // Create the cast operation
+  Value *Result = Builder.CreateCast(CastOpcode, NewOp, I.getType());
+
+  // Preserve cast instruction flags
+  if (auto *NewCast = dyn_cast<CastInst>(Result)) {
----------------
dtcxzyw wrote:

> do you recommend changing those as well? (In a separate patch to this one of course)

Yeah. We can propagate the flags in the insert callback.

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


More information about the llvm-commits mailing list