Skip to content

Commit a0d5c61

Browse files
committed
[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.
1 parent edcea1e commit a0d5c61

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6103,21 +6103,22 @@ KnownFPClass llvm::computeKnownFPClass(const Value *V,
61036103
}
61046104

61056105
Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
6106+
unsigned ByteWidth = DL.getByteWidth();
61066107

61076108
// All byte-wide stores are splatable, even of arbitrary variables.
6108-
if (V->getType()->isIntegerTy(8))
6109+
if (V->getType()->isIntegerTy(ByteWidth))
61096110
return V;
61106111

61116112
LLVMContext &Ctx = V->getContext();
61126113

61136114
// Undef don't care.
6114-
auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
6115+
auto *UndefByte = UndefValue::get(Type::getIntNTy(Ctx, ByteWidth));
61156116
if (isa<UndefValue>(V))
6116-
return UndefInt8;
6117+
return UndefByte;
61176118

61186119
// Return Undef for zero-sized type.
61196120
if (DL.getTypeStoreSize(V->getType()).isZero())
6120-
return UndefInt8;
6121+
return UndefByte;
61216122

61226123
Constant *C = dyn_cast<Constant>(V);
61236124
if (!C) {
@@ -6132,7 +6133,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
61326133

61336134
// Handle 'null' ConstantArrayZero etc.
61346135
if (C->isNullValue())
6135-
return Constant::getNullValue(Type::getInt8Ty(Ctx));
6136+
return Constant::getNullValue(Type::getIntNTy(Ctx, ByteWidth));
61366137

61376138
// Constant floating-point values can be handled as integer values if the
61386139
// corresponding integer value is "byteable". An important case is 0.0.
@@ -6149,13 +6150,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
61496150
: nullptr;
61506151
}
61516152

6152-
// We can handle constant integers that are multiple of 8 bits.
6153+
// We can handle constant integers that are multiple of the byte width.
61536154
if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
6154-
if (CI->getBitWidth() % 8 == 0) {
6155-
assert(CI->getBitWidth() > 8 && "8 bits should be handled above!");
6156-
if (!CI->getValue().isSplat(8))
6155+
if (CI->getBitWidth() % ByteWidth == 0) {
6156+
assert(CI->getBitWidth() > ByteWidth &&
6157+
"single byte should be handled above!");
6158+
if (!CI->getValue().isSplat(ByteWidth))
61576159
return nullptr;
6158-
return ConstantInt::get(Ctx, CI->getValue().trunc(8));
6160+
return ConstantInt::get(Ctx, CI->getValue().trunc(ByteWidth));
61596161
}
61606162
}
61616163

@@ -6175,23 +6177,23 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
61756177
return LHS;
61766178
if (!LHS || !RHS)
61776179
return nullptr;
6178-
if (LHS == UndefInt8)
6180+
if (LHS == UndefByte)
61796181
return RHS;
6180-
if (RHS == UndefInt8)
6182+
if (RHS == UndefByte)
61816183
return LHS;
61826184
return nullptr;
61836185
};
61846186

61856187
if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(C)) {
6186-
Value *Val = UndefInt8;
6188+
Value *Val = UndefByte;
61876189
for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
61886190
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL))))
61896191
return nullptr;
61906192
return Val;
61916193
}
61926194

61936195
if (isa<ConstantAggregate>(C)) {
6194-
Value *Val = UndefInt8;
6196+
Value *Val = UndefByte;
61956197
for (Value *Op : C->operands())
61966198
if (!(Val = Merge(Val, isBytewiseValue(Op, DL))))
61976199
return nullptr;

0 commit comments

Comments
 (0)