[llvm] [IRBuilder] Handle byte types in CreateBitPreservingCastChain (PR #209557)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 20:47:30 PDT 2026


================
@@ -139,8 +139,18 @@ Value *IRBuilderBase::CreateBitPreservingCastChain(const DataLayout &DL,
     return CreateBitCast(In, Ty);
   };
 
+  // Byte (and byte-vector) types are not integers, but like integers they can
+  // be reinterpreted as a pointer-sized integer before/after an inttoptr or
+  // ptrtoint step.  Treat them the same as integers here so we never attempt a
+  // direct (and invalid) bitcast between a byte/integer aggregate and a
+  // pointer.
+  bool OldIsIntLike =
+      OldTy->isIntOrIntVectorTy() || OldTy->isByteOrByteVectorTy();
----------------
gandhi56 wrote:

The intent for this function is to emit a legal `inttoptr`. So the source type is only allowed to be an integer or a byte. So I am okay with `Type::isIntegerOrByteType()` as well.

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


More information about the llvm-commits mailing list