[llvm-commits] [dragonegg] r138956 - in /dragonegg/trunk/src: Constants.cpp Types.cpp
Duncan Sands
baldrick at free.fr
Thu Sep 1 11:44:51 PDT 2011
Author: baldrick
Date: Thu Sep 1 13:44:50 2011
New Revision: 138956
URL: http://llvm.org/viewvc/llvm-project?rev=138956&view=rev
Log:
Don't form types and constants like { i31 }. While the usage being
made of these types was correct, they do tend to tickle optimizer
bugs.
Modified:
dragonegg/trunk/src/Constants.cpp
dragonegg/trunk/src/Types.cpp
Modified: dragonegg/trunk/src/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Constants.cpp?rev=138956&r1=138955&r2=138956&view=diff
==============================================================================
--- dragonegg/trunk/src/Constants.cpp (original)
+++ dragonegg/trunk/src/Constants.cpp Thu Sep 1 13:44:50 2011
@@ -986,9 +986,13 @@
// it needs to be displaced before being passed to the user.
if (!R.empty() && R.getFirst() != Starts)
return false;
+ Type *Ty = C->getType();
+ // Check that the type isn't something like i17. Avoiding types like this
+ // is not needed for correctness, but makes life easier for the optimizers.
+ if ((Ty->getPrimitiveSizeInBits() % BITS_PER_UNIT) != 0)
+ return false;
// If the constant is wider than the range then it needs to be truncated
// before being passed to the user.
- Type *Ty = C->getType();
unsigned AllocBits = TD.getTypeAllocSizeInBits(Ty);
return AllocBits <= (unsigned)R.getWidth();
}
@@ -1023,6 +1027,7 @@
/// class, this one requires that the width of the range be a multiple of an
/// address unit, which usually means a multiple of 8.
Constant *extractContents(const TargetData &TD) {
+ assert(R.getWidth() % BITS_PER_UNIT == 0 && "Boundaries not aligned?");
/// If the current value for the constant can be used to represent the bits
/// in the range then just return it.
if (isSafeToReturnContentsDirectly(TD))
@@ -1035,12 +1040,23 @@
assert(isSafeToReturnContentsDirectly(TD) && "Unit over aligned?");
return C;
}
+ // If the type is something like i17 then round it up to a multiple of a
+ // byte. This is not needed for correctness, but helps the optimizers.
+ if ((C->getType()->getPrimitiveSizeInBits() % BITS_PER_UNIT) != 0) {
+ Type *Ty = C->getType();
+ assert(Ty->isIntegerTy() && "Non-integer type with non-byte size!");
+ unsigned BitWidth = RoundUpToAlignment(Ty->getPrimitiveSizeInBits(),
+ BITS_PER_UNIT);
+ Ty = IntegerType::get(Context, BitWidth);
+ C = TheFolder->CreateZExtOrBitCast(C, Ty);
+ if (isSafeToReturnContentsDirectly(TD))
+ return C;
+ }
// Turn the contents into a bunch of bytes. Remember the returned value as
// an optimization in case we are called again.
// TODO: If the contents only need to be truncated and have struct or array
// type then we could try to do the truncation by dropping or modifying the
// last elements of the constant, maybe yielding something less horrible.
- assert(R.getWidth() % BITS_PER_UNIT == 0 && "Boundaries not aligned?");
unsigned Units = R.getWidth() / BITS_PER_UNIT;
C = InterpretAsType(C, GetUnitType(Context, Units), R.getFirst() - Starts,
Folder);
Modified: dragonegg/trunk/src/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Types.cpp?rev=138956&r1=138955&r2=138956&view=diff
==============================================================================
--- dragonegg/trunk/src/Types.cpp (original)
+++ dragonegg/trunk/src/Types.cpp Thu Sep 1 13:44:50 2011
@@ -979,6 +979,10 @@
// needs to be displaced before being passed to the user.
if (!R.empty() && R.getFirst() != Starts)
return false;
+ // Check that the type isn't something like i17. Avoiding types like this
+ // is not needed for correctness, but makes life easier for the optimizers.
+ if ((Ty->getPrimitiveSizeInBits() % BITS_PER_UNIT) != 0)
+ return false;
// If the type is wider than the range then it needs to be truncated before
// being passed to the user.
uint64_t AllocBits = TD.getTypeAllocSizeInBits(Ty);
@@ -1014,6 +1018,7 @@
/// one requires that the width of the range be a multiple of an address unit,
/// which usually means a multiple of 8.
Type *extractContents(const TargetData &TD) {
+ assert(R.getWidth() % BITS_PER_UNIT == 0 && "Boundaries not aligned?");
/// If the current value for the type can be used to represent the bits in
/// the range then just return it.
if (isSafeToReturnContentsDirectly(TD))
@@ -1026,12 +1031,20 @@
assert(isSafeToReturnContentsDirectly(TD) && "Unit over aligned?");
return Ty;
}
+ // If the type is something like i17 then round it up to a multiple of a
+ // byte. This is not needed for correctness, but helps the optimizers.
+ if ((Ty->getPrimitiveSizeInBits() % BITS_PER_UNIT) != 0) {
+ unsigned BitWidth = RoundUpToAlignment(Ty->getPrimitiveSizeInBits(),
+ BITS_PER_UNIT);
+ Ty = IntegerType::get(Context, BitWidth);
+ if (isSafeToReturnContentsDirectly(TD))
+ return Ty;
+ }
// Represent the range using an array of bytes. Remember the returned type
// as an optimization in case we are called again.
// TODO: If the type only needs to be truncated and has struct or array type
// then we could try to do the truncation by dropping or modifying the last
// elements of the type, maybe yielding something less horrible.
- assert(R.getWidth() % BITS_PER_UNIT == 0 && "Boundaries not aligned?");
uint64_t Units = R.getWidth() / BITS_PER_UNIT;
Ty = GetUnitType(Context, Units);
Starts = R.getFirst();
More information about the llvm-commits
mailing list