[llvm] [ConstantFold] Support byte values in `bitcast` constant folding (PR #188030)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 11:17:22 PDT 2026
================
@@ -105,6 +106,68 @@ static Constant *foldConstVectorToAPInt(APInt &Result, Type *DestTy,
return nullptr;
}
+/// Check whether folding this bitcast into a byte vector would mix poison and
+/// non-poison bits in the same output lane. While integer types track poison on
+/// a per-value basis, byte types track it on a per-bit basis. However,
+/// `ConstantByte` cannot represent values with both poison and non-poison bits.
+///
+/// Source elements are grouped by the output lane they map to. Returns true if
+/// any group contains both poison and non-poison elements.
+static bool foldMixesPoisonBits(Constant *C, unsigned NumSrcElt,
+ unsigned NumDstElt) {
+ unsigned Ratio = NumSrcElt / NumDstElt;
----------------
dtcxzyw wrote:
As I pointed out in https://github.com/llvm/llvm-project/pull/185205, this is incorrect for some bitcasts like `<8 x b3> -> <3 x b8>`. But it should be fine for now.
https://github.com/llvm/llvm-project/pull/188030
More information about the llvm-commits
mailing list