Skip to content

Commit

Permalink
[GVN][SROA] Fixes for O2 level
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Jul 29, 2021
1 parent 772c813 commit 84d89ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,12 @@ static bool canConvertValue(const DataLayout &DL, Type *OldTy, Type *NewTy) {
"We can't have the same bitwidth for different int types");
return false;
}
if (isa<ByteType>(OldTy) && isa<ByteType>(NewTy)) {
assert(cast<ByteType>(OldTy)->getBitWidth() !=
cast<ByteType>(NewTy)->getBitWidth() &&
"We can't have the same bitwidth for different byte types");
return false;
}

if (DL.getTypeSizeInBits(NewTy).getFixedSize() !=
DL.getTypeSizeInBits(OldTy).getFixedSize())
Expand Down Expand Up @@ -1770,6 +1776,8 @@ static Value *convertValue(const DataLayout &DL, IRBuilderTy &IRB, Value *V,

assert(!(isa<IntegerType>(OldTy) && isa<IntegerType>(NewTy)) &&
"Integer types must be the exact same to convert.");
assert(!(isa<ByteType>(OldTy) && isa<ByteType>(NewTy)) &&
"Byte types must be the exact same to convert.");

// See if we need inttoptr for this type pair. May require additional bitcast.
if (OldTy->isIntOrIntVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
Expand Down Expand Up @@ -1807,6 +1815,12 @@ static Value *convertValue(const DataLayout &DL, IRBuilderTy &IRB, Value *V,
}
}

if (OldTy->isByteOrByteVectorTy()) {
assert(OldTy->getScalarSizeInBits() == NewTy->getScalarSizeInBits() &&
"Byte and integer types must be the exact same to convert.");
return IRB.CreateByteCast(V);
}

return IRB.CreateBitCast(V, NewTy);
}

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Utils/VNCoercion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ static T *getStoreValueForLoadHelper(T *SrcVal, unsigned Offset, Type *LoadTy,
uint64_t LoadSize = (DL.getTypeSizeInBits(LoadTy).getFixedSize() + 7) / 8;
// Compute which bits of the stored value are being used by the load. Convert
// to an integer type to start with.
if (SrcVal->getType()->isByteTy()) {
Type *ITy = Type::getIntNTy(SrcVal->getContext(),
SrcVal->getType()->getByteBitWidth());
SrcVal = Helper.CreateCast(Instruction::ByteCast, SrcVal, ITy);
}
if (SrcVal->getType()->isPtrOrPtrVectorTy())
SrcVal = Helper.CreatePtrToInt(SrcVal, DL.getIntPtrType(SrcVal->getType()));
if (!SrcVal->getType()->isIntegerTy())
Expand Down

0 comments on commit 84d89ff

Please sign in to comment.