https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/106538
>From 67765a6e3e4c8e0475cd6baccb801cad1498b36e Mon Sep 17 00:00:00 2001 From: Sergei Barannikov <baranniko...@gmail.com> Date: Fri, 2 Aug 2024 13:14:49 +0300 Subject: [PATCH] [ValueTracking] Make isBytewiseValue byte width agnostic This is a simple change to show how easy it can be to support unusual byte widths in the middle end. --- llvm/lib/Analysis/ValueTracking.cpp | 30 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 55feb15dfb1527..abe4a9d225fcb0 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6183,21 +6183,22 @@ KnownFPClass llvm::computeKnownFPClass(const Value *V, } Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) { + unsigned ByteWidth = DL.getByteWidth(); // All byte-wide stores are splatable, even of arbitrary variables. - if (V->getType()->isIntegerTy(8)) + if (V->getType()->isIntegerTy(ByteWidth)) return V; LLVMContext &Ctx = V->getContext(); // Undef don't care. - auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx)); + auto *UndefByte = UndefValue::get(Type::getIntNTy(Ctx, ByteWidth)); if (isa<UndefValue>(V)) - return UndefInt8; + return UndefByte; // Return poison for zero-sized type. if (DL.getTypeStoreSize(V->getType()).isZero()) - return PoisonValue::get(Type::getInt8Ty(Ctx)); + return PoisonValue::get(Type::getIntNTy(Ctx, ByteWidth)); Constant *C = dyn_cast<Constant>(V); if (!C) { @@ -6212,7 +6213,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) { // Handle 'null' ConstantArrayZero etc. if (C->isNullValue()) - return Constant::getNullValue(Type::getInt8Ty(Ctx)); + return Constant::getNullValue(Type::getIntNTy(Ctx, ByteWidth)); // Constant floating-point values can be handled as integer values if the // corresponding integer value is "byteable". An important case is 0.0. @@ -6229,13 +6230,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) { : nullptr; } - // We can handle constant integers that are multiple of 8 bits. + // We can handle constant integers that are multiple of the byte width. if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) { - if (CI->getBitWidth() % 8 == 0) { - assert(CI->getBitWidth() > 8 && "8 bits should be handled above!"); - if (!CI->getValue().isSplat(8)) + if (CI->getBitWidth() % ByteWidth == 0) { + assert(CI->getBitWidth() > ByteWidth && + "single byte should be handled above!"); + if (!CI->getValue().isSplat(ByteWidth)) return nullptr; - return ConstantInt::get(Ctx, CI->getValue().trunc(8)); + return ConstantInt::get(Ctx, CI->getValue().trunc(ByteWidth)); } } @@ -6255,15 +6257,15 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) { return LHS; if (!LHS || !RHS) return nullptr; - if (LHS == UndefInt8) + if (LHS == UndefByte) return RHS; - if (RHS == UndefInt8) + if (RHS == UndefByte) return LHS; return nullptr; }; if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(C)) { - Value *Val = UndefInt8; + Value *Val = UndefByte; for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I) if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL)))) return nullptr; @@ -6271,7 +6273,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) { } if (isa<ConstantAggregate>(C)) { - Value *Val = UndefInt8; + Value *Val = UndefByte; for (Value *Op : C->operands()) if (!(Val = Merge(Val, isBytewiseValue(Op, DL)))) return nullptr; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits