[llvm] [VectorCombine] Generalize foldBitOpOfBitcasts to support more cast operations (PR #148350)
    Yingwei Zheng via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sat Jul 19 07:31:08 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:
Since we use `IRBuilder<InstSimplifyFolder>` in VectorCombine, the result may point to an existing cast instruction instead of `CastOp (NewOp)`. Therefore, it may propagate flags into an incorrect instruction. I recommend using `CastInst::Create` instead of `Builder.CreateCast`.
https://github.com/llvm/llvm-project/pull/148350
    
    
More information about the llvm-commits
mailing list