[llvm] [LLVM][IR] Add support for vector ConstantInt/FP to ConstandFolding:FoldBitCast. (PR #117163)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 08:57:02 PST 2024


================
@@ -151,8 +151,14 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
     return FoldBitCast(ConstantVector::get(Ops), DestTy, DL);
   }
 
+  // Some of what follows may extend to cover scalable vectors but the current
+  // implementation is fixed length specific.
+  if (!isa<FixedVectorType>(C->getType()))
+    return ConstantExpr::getBitCast(C, DestTy);
+
   // If this is a bitcast from constant vector -> vector, fold it.
-  if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
+  if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C) &&
+      !isa<ConstantInt>(C) && !isa<ConstantFP>(C))
----------------
paulwalker-arm wrote:

I was going to say no because it should be safe to not perform anymore transformations.  However, if I'm reading it correctly I think that block of code is just broken upstream?

For the case where constant folding does not happen it is effectively returning `ConstantExpr::getBitCast(C, SrcAsIntTy)` and by this point we already know `SrcAsIntTy != DestVTy`?



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


More information about the llvm-commits mailing list