Skip to content

Commit 67765a6

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 65a421f commit 67765a6

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
@@ -6183,21 +6183,22 @@ KnownFPClass llvm::computeKnownFPClass(const Value *V,
61836183
}
61846184

61856185
Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
6186+
unsigned ByteWidth = DL.getByteWidth();
61866187

61876188
// All byte-wide stores are splatable, even of arbitrary variables.
6188-
if (V->getType()->isIntegerTy(8))
6189+
if (V->getType()->isIntegerTy(ByteWidth))
61896190
return V;
61906191

61916192
LLVMContext &Ctx = V->getContext();
61926193

61936194
// Undef don't care.
6194-
auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
6195+
auto *UndefByte = UndefValue::get(Type::getIntNTy(Ctx, ByteWidth));
61956196
if (isa<UndefValue>(V))
6196-
return UndefInt8;
6197+
return UndefByte;
61976198

61986199
// Return poison for zero-sized type.
61996200
if (DL.getTypeStoreSize(V->getType()).isZero())
6200-
return PoisonValue::get(Type::getInt8Ty(Ctx));
6201+
return PoisonValue::get(Type::getIntNTy(Ctx, ByteWidth));
62016202

62026203
Constant *C = dyn_cast<Constant>(V);
62036204
if (!C) {
@@ -6212,7 +6213,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
62126213

62136214
// Handle 'null' ConstantArrayZero etc.
62146215
if (C->isNullValue())
6215-
return Constant::getNullValue(Type::getInt8Ty(Ctx));
6216+
return Constant::getNullValue(Type::getIntNTy(Ctx, ByteWidth));
62166217

62176218
// Constant floating-point values can be handled as integer values if the
62186219
// corresponding integer value is "byteable". An important case is 0.0.
@@ -6229,13 +6230,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
62296230
: nullptr;
62306231
}
62316232

6232-
// We can handle constant integers that are multiple of 8 bits.
6233+
// We can handle constant integers that are multiple of the byte width.
62336234
if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
6234-
if (CI->getBitWidth() % 8 == 0) {
6235-
assert(CI->getBitWidth() > 8 && "8 bits should be handled above!");
6236-
if (!CI->getValue().isSplat(8))
6235+
if (CI->getBitWidth() % ByteWidth == 0) {
6236+
assert(CI->getBitWidth() > ByteWidth &&
6237+
"single byte should be handled above!");
6238+
if (!CI->getValue().isSplat(ByteWidth))
62376239
return nullptr;
6238-
return ConstantInt::get(Ctx, CI->getValue().trunc(8));
6240+
return ConstantInt::get(Ctx, CI->getValue().trunc(ByteWidth));
62396241
}
62406242
}
62416243

@@ -6255,23 +6257,23 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
62556257
return LHS;
62566258
if (!LHS || !RHS)
62576259
return nullptr;
6258-
if (LHS == UndefInt8)
6260+
if (LHS == UndefByte)
62596261
return RHS;
6260-
if (RHS == UndefInt8)
6262+
if (RHS == UndefByte)
62616263
return LHS;
62626264
return nullptr;
62636265
};
62646266

62656267
if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(C)) {
6266-
Value *Val = UndefInt8;
6268+
Value *Val = UndefByte;
62676269
for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
62686270
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL))))
62696271
return nullptr;
62706272
return Val;
62716273
}
62726274

62736275
if (isa<ConstantAggregate>(C)) {
6274-
Value *Val = UndefInt8;
6276+
Value *Val = UndefByte;
62756277
for (Value *Op : C->operands())
62766278
if (!(Val = Merge(Val, isBytewiseValue(Op, DL))))
62776279
return nullptr;

0 commit comments

Comments
 (0)