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

Rahul Yadav via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 05:02:44 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)) {
----------------
rhyadav wrote:

thanks @dtcxzyw for catching this, i've made changes, tests all pass @RKSimon pls have a look, happy to take on the new patch for changes to rest of the VectorCombine, pls do create and assign. 

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


More information about the llvm-commits mailing list