Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6260,21 +6260,22 @@ bool llvm::canIgnoreSignBitOfNaN(const Use &U) {
}

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) {
Expand All @@ -6289,7 +6290,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.
Expand All @@ -6306,13 +6307,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));
}
}

Expand All @@ -6332,23 +6334,23 @@ 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 (uint64_t I = 0, E = CA->getNumElements(); I != E; ++I)
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL))))
return nullptr;
return Val;
}

if (isa<ConstantAggregate>(C)) {
Value *Val = UndefInt8;
Value *Val = UndefByte;
for (Value *Op : C->operands())
if (!(Val = Merge(Val, isBytewiseValue(Op, DL))))
return nullptr;
Expand Down
Loading